Making WordPress.org

Changeset 11228


Ignore:
Timestamp:
09/14/2021 05:45:59 AM (4 years ago)
Author:
dd32
Message:

Theme Directory: Add an API endpoint to generate a dynamic SVN auth file.

Note: This won't take effect until we're ready to welcome commits.

See #5899.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/rest-api.php

    r10826 r11228  
    4747// Include the REST API Endpoints at the appropriate time.
    4848add_action( 'rest_api_init', function() {
    49     include __DIR__ . '/rest-api/class-internal-stats.php';
     49    include __DIR__ . '/rest-api/class-internal.php';
    5050    include __DIR__ . '/rest-api/class-info-endpoint.php';
    5151    include __DIR__ . '/rest-api/class-query-endpoint.php';
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/rest-api/class-internal.php

    r11227 r11228  
    55use WP_Http;
    66
    7 class Internal_Stats {
     7class Internal {
    88
    99    function __construct() {
     
    1111            'methods'             => \WP_REST_Server::CREATABLE,
    1212            'callback'            => array( $this, 'bulk_update_stats' ),
     13            'permission_callback' => array( $this, 'permission_check_internal_api_bearer' ),
     14        ) );
     15
     16        register_rest_route( 'themes/v1', 'svn-auth', array(
     17            'methods'             => \WP_REST_Server::READABLE,
     18            'callback'            => array( $this, 'svn_auth' ),
    1319            'permission_callback' => array( $this, 'permission_check_internal_api_bearer' ),
    1420        ) );
     
    3844
    3945        return true;
     46    }
     47
     48    /**
     49     * Generates a SVN auth file.
     50     *
     51     * The SVN auth file is printed directly to the output, designed to be consumed by a cron task.
     52     */
     53    function svn_auth() {
     54        global $wpdb;
     55
     56        header( 'Content-Type: text/plain' );
     57
     58        // Raw SQL to avoid loading every WP_Post / WP_User object causing OOM errors.
     59        $themes = $wpdb->get_results(
     60            "SELECT p.post_name as slug, u.user_login as user
     61            FROM {$wpdb->posts} p
     62            JOIN {$wpdb->users} u ON p.post_author = u.ID
     63            WHERE p.post_type = 'repopackage' AND p.post_status IN( 'publish', 'delist' )
     64            ORDER BY p.post_name ASC"
     65        );
     66
     67        // Some users need write access to all themes, such as the dropbox user.
     68        $all_access_users   = get_option( 'svn_all_access', array() );
     69        $all_access_users[] = 'themedropbox';
     70        echo "[/]\n";
     71        echo "* = r\n";
     72        foreach ( array_unique( $all_access_users ) as $u ) {
     73            echo "{$u} = rw\n";
     74        }
     75        echo "\n";
     76
     77        // Theme Authors.
     78        foreach ( $themes as $r ) {
     79            if ( ! $r->slug ) {
     80                // This should never occur, but just to ensure this never produces [/].
     81                continue;
     82            }
     83
     84            printf(
     85                "[%s]\n%s = rw\n\n",
     86                '/' . $r->slug,
     87                $r->user
     88            );
     89
     90        }
     91
     92        exit();     
    4093    }
    4194
     
    118171
    119172}
    120 new Internal_Stats();
     173new Internal();
Note: See TracChangeset for help on using the changeset viewer.