WordPress.org

Making WordPress.org

Changeset 8249


Ignore:
Timestamp:
02/14/2019 06:43:05 AM (9 months ago)
Author:
dd32
Message:

Translate: Add a per-locale stats page which lists plugin/theme translation status.

Notes:

  • This is currently not linked from anywhere.
  • The number displayed (250) may be lowered, currently only ~245 theme projects and ~200 plugin projects are displayed due to filtering.
  • Plugins displays based on Code (Dev+Stable) + Readme (Dev+Stable).

Examples:

See #2290.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/class-plugin.php

    r6851 r8249  
    8888     *  - (/locale)/$locale/$dir/glossary/-export
    8989     *  - (/locale)/$locale/$dir/glossary/-import
     90     *  - /locale/$locale/$dir/stats(?:/(plugins|themes))?s
    9091     *  - /stats/?
    9192     *  - /projects/wp-plugins/$project
     
    143144            GP::$router->prepend( "(/locale)/$locale/$dir/glossary/-import", array( 'GP_Route_Glossary_Entry', 'import_glossary_entries_get' ) );
    144145            GP::$router->prepend( "(/locale)/$locale/$dir/glossary/-import", array( 'GP_Route_Glossary_Entry', 'import_glossary_entries_post' ), 'post' );
     146            GP::$router->prepend( "/locale/$locale/$dir/stats(?:/(plugins|themes))?", array( __NAMESPACE__ . '\Routes\Stats', 'get_stats_plugin_theme_overview' ) );
    145147            GP::$router->prepend( '/stats', array( __NAMESPACE__ . '\Routes\Stats', 'get_stats_overview' ) );
    146148            GP::$router->prepend( '/consistency', array( __NAMESPACE__ . '\Routes\Consistency', 'get_search_form' ) );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/routes/class-stats.php

    r6689 r8249  
    55use GP;
    66use GP_Route;
     7use GP_Locales;
    78
    89/**
     
    138139    }
    139140
     141    public function get_stats_plugin_theme_overview( $locale, $locale_slug, $view = false ) {
     142        global $wpdb;
     143        if ( ! $locale || ! $locale_slug || ! $view ) {
     144            wp_redirect( '/stats', 301 );
     145            die();
     146        }
     147
     148        $gp_locale = GP_Locales::by_slug( $locale );
     149
     150        $items = array();
     151        if ( 'plugins' == $view ) {
     152            // Fetch top 100 plugins..
     153            $items = get_transient( __METHOD__ . '_plugin_items' );
     154            if ( ! $items ) {
     155                $api = wp_safe_remote_get( 'https://api.wordpress.org/plugins/info/1.2/?action=query_plugins&request[per_page]=250' );
     156                foreach ( json_decode( wp_remote_retrieve_body( $api ) )->plugins as $plugin ) {
     157                    $items[ $plugin->slug ] = (object) [
     158                        'installs' => $plugin->active_installs,
     159                    ];
     160                }
     161                set_transient( __METHOD__ . '_plugin_items', $items, DAY_IN_SECONDS );
     162            }
     163        } elseif ( 'themes' == $view && defined( 'WPORG_THEME_DIRECTORY_BLOGID' ) ) {
     164            $items = get_transient( __METHOD__ . '_theme_items' );
     165            if ( ! $items ) {
     166                // The Themes API API isn't playing nice.. Easiest way..
     167                switch_to_blog( WPORG_THEME_DIRECTORY_BLOGID );
     168                $items = $wpdb->get_results(
     169                    "SELECT p.post_name as slug, pm.meta_value as installs
     170                    FROM {$wpdb->posts} p
     171                    LEFT JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id AND pm.meta_key = '_active_installs'
     172                    WHERE p.post_type = 'repopackage' AND p.post_status = 'publish'
     173                    ORDER BY pm.meta_value+0 DESC, p.post_date
     174                    LIMIT 250",
     175                    OBJECT_K
     176                );
     177                restore_current_blog();
     178                foreach ( $items as $slug => $details ) {
     179                    unset( $items[$slug]->slug );
     180                }
     181                set_transient( __METHOD__ . '_theme_items', $items, DAY_IN_SECONDS );
     182            }
     183        } else {
     184            wp_safe_redirect( '/stats' );
     185            die();
     186        }
     187
     188        $project_ids = [];
     189        foreach ( $items as $slug => $details ) {
     190            $items[$slug]->project = GP::$project->by_path( 'wp-' . $view . '/' . $slug );
     191            if ( ! $items[$slug]->project || ! $items[$slug]->project->active ) {
     192                // Not all top-all-time plugins/themes have translation projects.
     193                unset( $items[ $slug ] );
     194                continue;
     195            }
     196
     197            if (
     198                'plugins' == $view &&
     199                (
     200                    ! GP::$project->by_path( $items[$slug]->project->path . '/dev' )
     201                    &&
     202                    ! GP::$project->by_path( $items[$slug]->project->path . '/stable' )
     203                )
     204            ) {
     205                // Not all top plugins are translation-aware, lets just skip those..
     206                unset( $items[ $slug ] );
     207                continue;
     208            }
     209
     210            $project_ids[ $items[$slug]->project->id ] = $slug;
     211        }
     212
     213        $sql_project_ids = implode( ', ', array_map( 'intval', array_keys( $project_ids ) ) );
     214        $stats = $wpdb->get_results( $wpdb->prepare(
     215            "SELECT `project_id`, `all`, `current`, `waiting`, `untranslated`
     216                FROM {$wpdb->project_translation_status}
     217                WHERE project_id IN ($sql_project_ids)
     218                AND locale = %s AND locale_slug = %s",
     219            $locale, $locale_slug
     220        ) );
     221        foreach ( $stats as $row ) {
     222            $items[ $project_ids[ $row->project_id ] ]->stats = $row;
     223        }
     224
     225        $this->tmpl( 'stats-plugin-themes-overview', compact( 'locale', 'locale_slug', 'view', 'gp_locale', 'items' ) );
     226    }
    140227}
Note: See TracChangeset for help on using the changeset viewer.