Making WordPress.org

Changeset 2752


Ignore:
Timestamp:
03/15/2016 08:02:51 PM (11 years ago)
Author:
obenland
Message:

Plugin Directory: Allow plugin committers to be added and removed.

Still needs cap checks.
Uses wpList to seemlessly add/remove committers. Works similar to the
category meta box.

See #1571.

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

Legend:

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

    r2737 r2752  
    3030
    3131                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
     32
    3233                add_action( 'wp_ajax_replyto-comment', array( $this, 'save_custom_comment' ), 0 );
    33 
    34                 add_filter( 'postbox_classes_plugin_internal-notes', array( $this, 'postbox_classes' ) );
    3534                add_filter( 'comment_row_actions', array( $this, 'custom_comment_row_actions' ), 10, 2 );
     35
     36                add_filter( 'postbox_classes_plugin_internal-notes',    array( __NAMESPACE__ . '\Metabox\Internal_Notes', 'postbox_classes' ) );
     37                add_filter( 'postbox_classes_plugin_plugin-committers', array( __NAMESPACE__ . '\Metabox\Committers',     'postbox_classes' ) );
     38                add_filter( 'wp_ajax_add-committer',    array( __NAMESPACE__ . '\Metabox\Committers', 'add_committer'    ) );
     39                add_filter( 'wp_ajax_delete-committer', array( __NAMESPACE__ . '\Metabox\Committers', 'remove_committer' ) );
    3640        }
    3741
     
    6165                global $post_type;
    6266
    63                 if ( 'post.php' == $hook_suffix && 'plugin' == $post_type ) {
     67                if ( 'post.php' === $hook_suffix && 'plugin' === $post_type ) {
    6468                        wp_enqueue_style( 'plugin-admin-edit-css', plugins_url( 'css/edit-form.css', Plugin_Directory\PLUGIN_FILE ), array( 'edit' ), 1 );
    65                         wp_enqueue_script( 'plugin-admin-edit-js', plugins_url( 'js/edit-form.js', Plugin_Directory\PLUGIN_FILE ), array( 'wp-util' ), 1 );
     69                        wp_enqueue_script( 'plugin-admin-edit-js', plugins_url( 'js/edit-form.js', Plugin_Directory\PLUGIN_FILE ), array( 'wp-util', 'wp-lists' ), 1 );
     70                        wp_localize_script( 'plugin-admin-edit-js', 'pluginDirectory', array(
     71                                'removeCommitterAYS' => __( 'Are you sure you want to remove this committer?', 'wporg-plugins' ),
     72                        ) );
    6673                }
    6774        }
     
    133140                        update_post_meta( $post_id, 'tested', wp_slash( wp_unslash( $_POST['tested_with'] ) ) );
    134141                }
    135         }
    136 
    137         /**
    138          * Filters the postbox classes for custom comment meta boxes.
    139          *
    140          * @param array $classes An array of postbox classes.
    141          * @return array
    142          */
    143         public function postbox_classes( $classes ) {
    144                 $classes[] = 'comments-meta-box';
    145 
    146                 return array_filter( $classes );
    147142        }
    148143
     
    160155         */
    161156        public function custom_comment_row_actions( $actions, $comment ) {
    162                 if ( 'internal-note' === $comment->comment_type ) {
     157                if ( 'internal-note' === $comment->comment_type && isset( $_REQUEST['mode'] ) && 'single' === $_REQUEST['mode'] ) {
    163158                        $allowed_actions = array( 'reply' => true );
    164159
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-committers.php

    r2655 r2752  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Admin\Metabox;
    3 use WordPressdotorg\Plugin_Directory\Tools;
     3use WordPressdotorg\Plugin_Directory\Admin\Committers_List_Table;
    44
    55/**
     
    99 */
    1010class Committers {
    11         static function display() {
    12                 $plugin_slug         = get_post()->post_name;
    13                 $existing_committers = Tools::get_plugin_committers( $plugin_slug );
    14                 $existing_committers = array_map( function ( $user ) {
    15                         return new \WP_User( $user );
    16                 }, $existing_committers );
    1711
    18                 $output = '';
    19                 foreach ( $existing_committers as $committer ) {
    20                         $output .= sprintf(
    21                                 '<li title="%s"><span class="avatar">%s</span> %s</li>',
    22                                 esc_attr( $committer->user_login ),
    23                                 get_avatar( $committer, '24' ),
    24                                 esc_html( $committer->display_name )
    25                         );
     12        /**
     13         * Filters the postbox classes for custom comment meta boxes.
     14         *
     15         * @param array $classes An array of postbox classes.
     16         * @return array
     17         */
     18        public static function postbox_classes( $classes ) {
     19                $classes[] = 'committers-meta-box';
     20
     21                return array_filter( $classes );
     22        }
     23
     24        public static function display() {
     25                $list = new Committers_List_Table();
     26                $list->prepare_items();
     27                $list->display();
     28        }
     29
     30        public static function add_committer() {
     31                check_ajax_referer( 'add-committer' );
     32
     33                $login   = isset( $_POST['add_committer'] ) ? sanitize_user( $_POST['add_committer'] ) : '';
     34                $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
     35
     36                if ( ! $committer = get_user_by( 'login', $login ) ) {
     37                        wp_die( time() );
    2638                }
    27                 echo '<ul class="committers">' . $output . '</ul>';
     39
     40                if ( ! current_user_can( 'manage_committers', $post_id ) ) {
     41                //      wp_die( -1 );
     42                }
     43                global $post, $wpdb;
     44
     45                $response = new \WP_Ajax_Response();
     46                $post     = get_post( $post_id );
     47
     48                $result = $wpdb->insert( PLUGINS_TABLE_PREFIX . 'svn_access', array(
     49                        'path'   => "/{$post->post_name}",
     50                        'user'   => $login,
     51                        'access' => 'rw',
     52                ) );
     53
     54                if ( ! $result ) {
     55                        $message = __( 'An error has occurred. Please reload the page and try again.' );
     56                        if ( is_wp_error( $result ) && $result->get_error_message() ) {
     57                                $message = $result->get_error_message();
     58                        }
     59
     60                        $response->add( array(
     61                                'what' => 'committer',
     62                                'data' => new \WP_Error( 'error', $message ),
     63                        ) );
     64                        $response->send();
     65                }
     66
     67                $wp_list_table = new Committers_List_Table();
     68
     69                $response->add( array(
     70                        'what'     => 'committer',
     71                        'id'       => $committer->ID,
     72                        'data'     => $wp_list_table->single_row( $committer ),
     73                        'position' => -1,
     74                ) );
     75                $response->send();
     76        }
     77
     78        public static function remove_committer() {
     79                $id      = isset( $_POST['id'] )      ? (int) $_POST['id']      : 0;
     80                $post_id = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
     81
     82                check_ajax_referer( "remove-committer-$id" );
     83
     84                if ( ! $committer = get_user_by( 'id', $id ) ) {
     85                        wp_die( time() );
     86                }
     87
     88                if ( ! current_user_can( 'manage_committers', $post_id ) ) {
     89                //      wp_die( -1 );
     90                }
     91
     92                $plugin_slug = get_post( $post_id )->post_name;
     93
     94                $result = $GLOBALS['wpdb']->delete( PLUGINS_TABLE_PREFIX . 'svn_access', array(
     95                        'path'   => "/{$plugin_slug}",
     96                        'user'   => $committer->user_login,
     97                ) );
     98
     99                wp_die( $result );
    28100        }
    29101}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/admin/metabox/class-internal-notes.php

    r2735 r2752  
    1111
    1212        /**
     13         * Filters the postbox classes for custom comment meta boxes.
     14         *
     15         * @param array $classes An array of postbox classes.
     16         * @return array
     17         */
     18        public static function postbox_classes( $classes ) {
     19                $classes[] = 'comments-meta-box';
     20
     21                return array_filter( $classes );
     22        }
     23
     24        /**
    1325         * Displays comment box for internal notes.
    1426         */
    15         static function display() {
     27        public static function display() {
    1628                $wp_list_table = new Plugin_Comments_List_Table( array(
    1729                        'comment_type' => 'internal-note',
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/css/edit-form.css

    r2735 r2752  
    2020        content: "\f173";
    2121}
     22
    2223.misc-pub-section label[for="tested_with"]::before {
    2324        content: "\f177";
     
    3334}
    3435
    35 .misc-pub-section .button-link {
     36.button-link:not(.handlediv) {
    3637        color: #0073aa;
    3738        -webkit-transition-property: border, background, color;
     
    4142        -webkit-transition-timing-function: ease-in-out;
    4243        transition-timing-function: ease-in-out;
    43     text-decoration: underline;
     44        text-decoration: underline;
    4445}
    4546
    46 .misc-pub-section .button-link:hover,
    47 .misc-pub-section .button-link:active {
     47.button-link:not(.handlediv):hover,
     48.button-link:not(.handlediv):active {
    4849        color: #00a0d2;
    4950}
     
    6768}
    6869
    69 .comments-meta-box.postbox .inside,
     70#poststuff .comments-meta-box.postbox .inside,
     71#poststuff .committers-meta-box.postbox .inside,
    7072.comments-meta-box .column-comment p {
    7173        margin: 0;
    7274        padding: 0;
     75        border: 0;
    7376}
    7477
    7578.comments-meta-box .inside .row-actions {
    7679        line-height:18px;
     80}
     81
     82.comments-meta-box .inside .column-author {
     83        width: 20%;
    7784}
    7885
     
    9097}
    9198
    92 .comments-meta-box .comments-box {
     99.comments-meta-box .comments-box,
     100.committers-meta-box .wp-list-table {
    93101        border: 0 none;
    94102}
     
    124132        }
    125133}
     134
     135/* Committers meta box */
     136.add-committer {
     137        padding: 0 12px 12px;
     138}
     139
     140.add-committer .button-link {
     141        font-weight: 600;
     142        margin: 10px 0;
     143}
     144
     145.add-committer input[type="text"] {
     146        margin: 0 0 1em;
     147        max-width: 260px;
     148        vertical-align: baseline;
     149        width: 100%;
     150}
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/edit-form.js

    r2735 r2752  
    33 */
    44
    5 ( function( $, wp ) {
     5( function( $, wp, pluginDirectory ) {
    66        var PluginEdit = {
    77                $testedWith: {},
     
    2222                        _.each( $( '#post-body' ).find( '.comments-box' ), PluginEdit.loadComments );
    2323
    24                         $( '#add-new-comment' ).on( 'click', 'a.button', function( event ) {
    25                                 event.preventDefault();
     24                        $( '#add-new-comment' ).on( 'click', 'a.button', PluginEdit.prepareCommentForm );
    2625
    27                                 window.commentReply && commentReply.addcomment( $( '#post_ID' ).val() );
     26                        $( '#add-committer-toggle' ).on( 'click', PluginEdit.toggleCommitterForm );
    2827
    29                                 $( '#replyrow' ).find( '.comment-reply' ).append( $( '<input/>' ).attr({
    30                                         type: 'hidden',
    31                                         name: 'comment_type',
    32                                         value: $( '.comments-box' ).data( 'comment-type' )
    33                                 }) );
     28                        $( '#the-committer-list' ).wpList({
     29                                alt: false,
     30                                confirm: function( element, settings, action ) {
     31                                        if ( 'committer' === settings.what && 'delete' === action ) {
     32                                                return confirm( pluginDirectory.removeCommitterAYS );
     33                                        }
     34                                        return true;
     35                                }
     36                        }).on( 'wpListAddEnd', function() {
     37                                $( 'input[name="add_committer"]', '#add-committer' ).val( '' ).focus();
    3438                        } );
    3539                },
     
    9397                                }
    9498                        } );
     99                },
     100
     101                prepareCommentForm: function( event ) {
     102                        event.preventDefault();
     103
     104                        window.commentReply && commentReply.addcomment( $( '#post_ID' ).val() );
     105
     106                        // Add a field with the custom comment type.
     107                        $( '#replyrow' ).find( '.comment-reply' ).append( $( '<input/>' ).attr({
     108                                type: 'hidden',
     109                                name: 'comment_type',
     110                                value: $( '.comments-box' ).data( 'comment-type' )
     111                        }) );
     112                },
     113
     114                toggleCommitterForm: function( event ) {
     115                        var $form = $( '#add-committer' );
     116
     117                        // Show/hide form.
     118                        $form.toggleClass( 'wp-hidden-children' );
     119
     120                        // Focus on the input field, and on enter add the committer, don't save post.
     121                        $( 'input[name="add_committer"]', $form ).focus().on( 'keydown', function( event ) {
     122                                if ( 13 === event.which ) {
     123                                        event.preventDefault();
     124                                        $( '#add-committer-submit', $form ).click();
     125                                }
     126                        } );
    95127                }
    96128        };
    97129
    98130        $( PluginEdit.ready );
    99 } )( window.jQuery, window.wp );
     131} )( window.jQuery, window.wp, window.pluginDirectory );
Note: See TracChangeset for help on using the changeset viewer.