Making WordPress.org


Ignore:
Timestamp:
11/25/2015 10:56:07 AM (8 years ago)
Author:
ocean90
Message:

Translate: Disable the /languages/$locale API endpoint temporarily.

The memory usage needs to be improved.

File:
1 edited

Legend:

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

    r2109 r2132  
    1818
    1919    public function register_routes() {
    20         // Bail for API requests.
    2120        $request_uri = GP::$router->request_uri();
    22         if ( gp_startswith( $request_uri, '/' . GP::$router->api_prefix . '/' ) ) {
    23             return;
    24         }
    25 
    2621        $path = '(.+?)';
    2722        $locale = '(' . implode( '|', array_map( function( $locale ) { return $locale->slug; }, GP_Locales::locales() ) ) . ')';
    2823
    29         // Delete default routes.
    30         GP::$router->remove("/languages/$locale");
    31         GP::$router->remove("/languages/$locale/$path");
     24        if ( gp_startswith( $request_uri, '/' . GP::$router->api_prefix . '/' ) ) { // API requests.
     25            // Delete default routes.
     26            GP::$router->remove("/languages/$locale");
     27        } else {
     28            // Delete default routes.
     29            GP::$router->remove("/languages/$locale");
     30            GP::$router->remove("/languages/$locale/$path");
    3231
    33         // Redirect routes.
    34         GP::$router->prepend( '/languages', array( 'WPorg_GP_Route_Redirector', 'redirect_languages' ) );
    35         GP::$router->prepend( "/languages/$path", array( 'WPorg_GP_Route_Redirector', 'redirect_languages' ) );
     32            // Redirect routes.
     33            GP::$router->prepend( '/languages', array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
     34            GP::$router->prepend( "/languages/$path", array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
    3635
    37         // Register custom routes.
    38         GP::$router->prepend( '/', array( 'WPorg_GP_Route_Index', 'get_locales' ) );
    39         GP::$router->prepend( "/locale/$locale", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );
    40         GP::$router->prepend( "/locale/$locale/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );
    41         GP::$router->prepend( "/locale/$locale/$path/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_projects' ) );
    42         GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( 'WPorg_GP_Route_Locale', 'get_locale_project' ) );
    43         GP::$router->prepend( '/stats/?', array( 'WPorg_GP_Route_Stats', 'get_stats_overview' ) );
    44         $project = '([^/]*)/?';
    45         GP::$router->prepend( "/projects/wp-plugins/$project", array( 'WPorg_GP_Route_WP_Plugins', 'get_plugin_projects' ) );
     36            // Register custom routes.
     37            GP::$router->prepend( '/', array( 'GP_WPorg_Route_Index', 'get_locales' ) );
     38            GP::$router->prepend( "/locale/$locale", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
     39            GP::$router->prepend( "/locale/$locale/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
     40            GP::$router->prepend( "/locale/$locale/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
     41            GP::$router->prepend( "/locale/$locale/$path/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_project' ) );
     42            GP::$router->prepend( '/stats/?', array( 'GP_WPorg_Route_Stats', 'get_stats_overview' ) );
     43            $project = '([^/]*)/?';
     44            GP::$router->prepend( "/projects/wp-plugins/$project", array( 'GP_WPorg_Route_WP_Plugins', 'get_plugin_projects' ) );
     45        }
    4646    }
    4747}
Note: See TracChangeset for help on using the changeset viewer.