Making WordPress.org

Changeset 13513


Ignore:
Timestamp:
04/12/2024 06:18:06 AM (10 months ago)
Author:
dd32
Message:

Plugin Driectory: Readme Validator: Improve the user experience of using the readme validator.

This introduces two main changes:

  • Allows for putting a plugin url (htps://wordpress.org/plugins/hello-dolly/) into the readme URL field to validate that plugins stable readme file.
  • Imports the URL validated into the text area, such that you can both see what was validated, and alter it before validating again.
Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php

    r13465 r13513  
    1111 */
    1212class Validator {
     13
     14    /**
     15     * Last content validated.
     16     *
     17     * @var string
     18     */
     19    public $last_content = '';
    1320
    1421    /**
     
    8693    public function validate( $readme ) {
    8794        $errors = $warnings = $notes = array();
     95
     96        // Store the last validated content for later use.
     97        $this->last_content = $readme;
    8898
    8999        // Security note: Keep the data: protocol here, Parser accepts a string HOWEVER
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-readme-validator.php

    r13275 r13513  
    22namespace WordPressdotorg\Plugin_Directory\Shortcodes;
    33
     4use WordPressdotorg\Plugin_Directory\Plugin_Directory;
    45use WordPressdotorg\Plugin_Directory\Readme\Validator;
    56
     
    1011     */
    1112    public static function display() {
     13        $readme_url      = '';
     14        $readme_contents = '';
     15        if ( ! empty( $_REQUEST['readme'] ) && is_string( $_REQUEST['readme'] ) ) {
     16            $readme_url = wp_unslash( $_REQUEST['readme'] );
     17        }
     18
     19        if ( ! empty( $_POST['readme_contents'] ) && is_string( $_POST['readme_contents'] ) ) {
     20            $readme_contents = base64_decode( wp_unslash( $_POST['readme_contents'] ), true );
     21        }
     22
     23        // If the user has specified a plugin URL, validate the stable tags readme (Well, try to, we don't know it's exact filename).
     24        if ( $readme_url && preg_match( '!^https?://([^./]+\.)?wordpress.org/plugins/(?P<slug>[^/]+)!i', $readme_url, $m ) ) {
     25            $plugin = Plugin_Directory::get_plugin_post( $m['slug'] );
     26
     27            if ( $plugin ) {
     28                $readme_url         = 'https://plugins.svn.wordpress.org/' . $plugin->post_name . '/' . ( ( $plugin->stable_tag && 'trunk' != $plugin->stable_tag ) ? 'tags/' . $plugin->stable_tag : 'trunk' ) . '/readme.txt';
     29                $_REQUEST['readme'] = $readme_url;
     30            }
     31        }
     32
    1233        ob_start();
    1334        ?>
    1435        <div class="wrap">
    1536            <?php
    16             if ( $_REQUEST ) {
    17                 self::validate_readme();
    18             }
     37            if ( $readme_contents || $readme_url ) {
     38                self::validate_readme( $readme_contents ?: $readme_url );
    1939
    20             $readme_url      = '';
    21             $readme_contents = '';
    22             if ( ! empty( $_REQUEST['readme'] ) && is_string( $_REQUEST['readme'] ) ) {
    23                 $readme_url = wp_unslash( $_REQUEST['readme'] );
    24             }
    25             if ( ! empty( $_POST['readme_contents'] ) && is_string( $_POST['readme_contents'] ) ) {
    26                 $readme_contents = base64_decode( wp_unslash( $_POST['readme_contents'] ), true );
     40                $readme_contents = Validator::instance()->last_content ?: $readme_contents;
    2741            }
    2842            ?>
     
    6276    /**
    6377     * Validates readme.txt contents and adds feedback.
     78     *
     79     * @param string $readme_url_or_contents URL or contents of the readme.txt file.
     80     * @return void
    6481     */
    65     protected static function validate_readme() {
    66         if ( ! empty( $_REQUEST['readme'] ) && is_string( $_REQUEST['readme'] ) ) {
    67             $errors = Validator::instance()->validate_url( wp_unslash( $_REQUEST['readme'] ) );
     82    protected static function validate_readme( $readme_url_or_contents = '' ) {
    6883
    69         } elseif ( ! empty( $_POST['readme_contents'] ) && is_string( $_POST['readme_contents'] ) ) {
    70             $contents = base64_decode( wp_unslash( $_REQUEST['readme_contents'] ), true );
    71             if ( ! $contents ) {
    72                 return;
    73             }
     84        if ( str_starts_with( $readme_url_or_contents, 'http://' ) || str_starts_with( $readme_url_or_contents, 'https://' ) ) {
     85            $errors = Validator::instance()->validate_url( $readme_url_or_contents );
    7486
    75             $errors = Validator::instance()->validate_content( $contents );
     87        } elseif ( $readme_url_or_contents ) {
     88            $errors = Validator::instance()->validate_content( $readme_url_or_contents );
    7689
    7790        } else {
Note: See TracChangeset for help on using the changeset viewer.