Make WordPress Core

Ticket #15761: garyc40-15761.patch

File garyc40-15761.patch, 14.5 KB (added by garyc40, 14 years ago)

UI for bulk edit (JS disabled), javascript fix for checkbox behavior during bulk edit

  • wp-admin/edit.php

    diff --git wp-admin/edit.php wp-admin/edit.php
    index 883cb5d..3b72564 100644
     
    88
    99/** WordPress Administration Bootstrap */
    1010require_once( './admin.php' );                 
     11
    1112$wp_list_table = get_list_table('WP_Posts_List_Table');
    1213$wp_list_table->check_permissions();
    1314$pagenum = $wp_list_table->get_pagenum();
    unset( $_redirect ); 
    2324
    2425$doaction = $wp_list_table->current_action();
    2526
    26 if ( $doaction ) {
     27if ( $doaction && ! $wp_list_table->is_bulk_edit_form() ) {
    2728        check_admin_referer('bulk-posts');
    2829
    2930        $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
    if ( $doaction ) { 
    4243                $post_ids = explode( ',', $_REQUEST['ids'] );
    4344        } elseif ( !empty( $_REQUEST['post'] ) ) {
    4445                $post_ids = array_map('intval', $_REQUEST['post']);
     46        } elseif ( ! empty( $_REQUEST['bulk_post'] ) ) {
     47                $post_ids = array_map( 'intval', $_REQUEST['bulk_post'] );
    4548        }
    46 
     49       
    4750        if ( !isset( $post_ids ) ) {
    4851                wp_redirect( admin_url("edit.php?post_type=$post_type") );
    4952                exit;
    if ( $doaction ) { 
    6265                                $trashed++;
    6366                        }
    6467                        $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids) ), $sendback );
     68                        $sendback = remove_query_arg( array( 'updated' ), $sendback );
    6569                        break;
    6670                case 'untrash':
    6771                        $untrashed = 0;
    if ( $doaction ) { 
    103107                                $done['skipped'] = count( $done['skipped'] );
    104108                                $done['locked'] = count( $done['locked'] );
    105109                                $sendback = add_query_arg( $done, $sendback );
     110                                $sendback = remove_query_arg( array( 'bulk_post' ), $sendback );
    106111                        }
     112
    107113                        break;
    108114        }
    109115
    110116        $sendback = remove_query_arg( array('action', 'action2', 'tags_input', 'post_author', 'comment_status', 'ping_status', '_status',  'post', 'bulk_edit', 'post_view'), $sendback );
    111 
    112117        wp_redirect($sendback);
    113118        exit();
    114119} elseif ( ! empty($_REQUEST['_wp_http_referer']) ) {
    $_SERVER['REQUEST_URI'] = remove_query_arg( array('locked', 'skipped', 'updated' 
    247252
    248253<?php
    249254if ( $wp_list_table->has_items() )
    250         $wp_list_table->inline_edit();
     255        if ( $wp_list_table->is_bulk_edit_form() ) {
     256                $wp_list_table->inline_edit( 'inline' );
     257        } else {
     258                $wp_list_table->inline_edit();
     259        }
    251260?>
    252261
    253262<div id="ajax-response"></div>
  • wp-admin/includes/class-wp-list-table.php

    diff --git wp-admin/includes/class-wp-list-table.php wp-admin/includes/class-wp-list-table.php
    index 5a3fd00..920f16c 100644
    class WP_List_Table { 
    700700        </tr>
    701701        </tfoot>
    702702
     703        <?php do_action( 'wp_list_table_tbody' ); ?>
     704
    703705        <tbody id="the-list"<?php if ( $singular ) echo " class='list:$singular'"; ?>>
    704706                <?php $this->display_rows(); ?>
    705707        </tbody>
  • wp-admin/includes/class-wp-posts-list-table.php

    diff --git wp-admin/includes/class-wp-posts-list-table.php wp-admin/includes/class-wp-posts-list-table.php
    index 696b911..8dbc4e3 100644
    class WP_Posts_List_Table extends WP_List_Table { 
    1616         * @access protected
    1717         */
    1818        var $hierarchical_display;
     19       
     20        /**
     21         * Whether the bulk edit form should be displayed (when JavaScript is disabled)
     22         *
     23         * @since 3.1.0
     24         * @var bool
     25         * @access protected
     26         */
     27        var $bulk_edit_display = false;
    1928
    2029        /**
    2130         * Holds the number of pending comments for each post
    class WP_Posts_List_Table extends WP_List_Table { 
    8493                if ( !current_user_can( $post_type_object->cap->edit_posts ) )
    8594                        wp_die( __( 'Cheatin&#8217; uh?' ) );
    8695        }
     96       
     97        function is_bulk_edit_form() {
     98                return $this->bulk_edit_display;
     99        }
     100       
     101        function display_bulk_edit_form() {
     102                $this->inline_edit( 'bulk' );
     103        }
    87104
    88105        function prepare_items() {
    89106                global $post_type_object, $post_type, $avail_post_stati, $wp_query, $per_page, $mode;
    class WP_Posts_List_Table extends WP_List_Table { 
    237254                if ( isset( $_REQUEST['delete_all'] ) || isset( $_REQUEST['delete_all2'] ) )
    238255                        return 'delete_all';
    239256
    240                 return parent::current_action();
     257                if ( isset( $_REQUEST['bulk_post'] ) ) {
     258                        return 'edit';
     259                }
     260
     261                $action = parent::current_action();
     262
     263                if ( $action == 'edit' && ! isset( $_REQUEST['bulk_edit']) ) {                 
     264                        $this->bulk_edit_display = true;
     265                        add_action( 'wp_list_table_tbody', array( &$this, 'display_bulk_edit_form' ) );
     266                }
     267               
     268                return $action;
    241269        }
    242270
    243271        function pagination( $which ) {
    class WP_Posts_List_Table extends WP_List_Table { 
    496524                        switch ( $column_name ) {
    497525
    498526                        case 'cb':
     527                                $checked = ( isset( $_REQUEST['post'] ) && in_array( $post->ID, $_REQUEST['post'] ) ) ? ' checked="checked"' : '';
    499528                        ?>
    500                         <th scope="row" class="check-column"><?php if ( $can_edit_post ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>" /><?php } ?></th>
     529                        <th scope="row" class="check-column"><?php if ( $can_edit_post ) { ?><input type="checkbox" name="post[]" value="<?php the_ID(); ?>"<?php echo $checked; ?> /><?php } ?></th>
    501530                        <?php
    502531                        break;
    503532
    class WP_Posts_List_Table extends WP_List_Table { 
    684713        }
    685714
    686715        /**
    687          * Outputs the hidden row displayed when inline editing
     716         * Outputs inline editing forms
    688717         *
    689718         * @since 3.1.0
     719         *
     720         * @param string $which Specify which form to be output. Can be one of the following: 'inline', 'bulk', or 'both'
    690721         */
    691         function inline_edit() {
     722        function inline_edit( $which = 'both' ) {
    692723                global $mode;
    693724
    694725                $screen = get_current_screen();
    class WP_Posts_List_Table extends WP_List_Table { 
    714745                $m = ( isset( $mode ) && 'excerpt' == $mode ) ? 'excerpt' : 'list';
    715746                $can_publish = current_user_can( $post_type_object->cap->publish_posts );
    716747                $core_columns = array( 'cb' => true, 'date' => true, 'title' => true, 'categories' => true, 'tags' => true, 'comments' => true, 'author' => true );
    717 
     748                $as_tbody = ( $which == 'bulk' && $this->bulk_edit_display );
     749               
     750                if ( $as_tbody && empty( $_REQUEST['post'] ) ) {
     751                        return;
     752                }
     753               
     754                $style = ( $as_tbody ) ? '' : ' style="display:none;"';
    718755        ?>
    719756
    720         <form method="get" action=""><table style="display: none"><tbody id="inlineedit">
     757        <?php if ( ! $as_tbody ): ?>
     758        <form method="get" action=""><table<?php echo $style; ?>><?php endif; ?>
     759                <tbody id="inlineedit">
    721760                <?php
    722761                $hclass = count( $hierarchical_taxonomies ) ? 'post' : 'page';
    723762                $bulk = 0;
    724                 while ( $bulk < 2 ) { ?>
     763                $max = 2;
     764               
     765                if ( $which == 'bulk' ) {
     766                        $bulk = 1;
     767                }
     768               
     769                if ( $which == 'inline' ) {
     770                        $max = 1;
     771                }
     772               
     773                while ( $bulk < $max ) { ?>
    725774
    726                 <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-$screen->post_type ";
     775                <tr id="<?php echo $bulk ? 'bulk-edit' : 'inline-edit'; ?>" class="inline-editor inline-edit-row inline-edit-row-<?php echo "$hclass inline-edit-$screen->post_type ";
    727776                        echo $bulk ? "bulk-edit-row bulk-edit-row-$hclass bulk-edit-$screen->post_type" : "quick-edit-row quick-edit-row-$hclass inline-edit-$screen->post_type";
    728                 ?>" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
     777                ?>"<?php echo $style; ?>><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
    729778
    730779                <fieldset class="inline-edit-col-left"><div class="inline-edit-col">
    731780                        <h4><?php echo $bulk ? __( 'Bulk Edit' ) : __( 'Quick Edit' ); ?></h4>
    class WP_Posts_List_Table extends WP_List_Table { 
    734783        if ( post_type_supports( $screen->post_type, 'title' ) ) :
    735784                if ( $bulk ) : ?>
    736785                        <div id="bulk-title-div">
    737                                 <div id="bulk-titles"></div>
     786                                <div id="bulk-titles">
     787                                        <?php
     788                                        if ( $as_tbody ) {
     789                                                $post_ids = $_REQUEST['post'];
     790                                               
     791                                                foreach ( $post_ids as $post_id ) {
     792                                                        $post = get_post( $post_id );
     793                                                        $title = esc_html( apply_filters( 'the_title', $post->post_title ) );
     794                                                        $temp_ids = array_diff( $post_ids, array( $post_id ) );
     795                                                        $delete_link = remove_query_arg( array( 'post' ), $_SERVER['REQUEST_URI'] );
     796                                                        $delete_link = add_query_arg( array( 'post' => $temp_ids ), $_SERVER['REQUEST_URI'] );
     797                                                        ?>
     798                                                                <div id="ttle<?php echo $post_id; ?>">
     799                                                                        <a id="_<?php echo $post_id; ?>" class="ntdelbutton" title="Remove From Bulk Edit" href="<?php echo $delete_link; ?>">X</a>
     800                                                                        <?php echo $title; ?>
     801                                                                        <input type="hidden" name="bulk_post[]" value="<?php echo $post_id; ?>" />
     802                                                                </div>
     803                                                        <?php
     804                                                }
     805                                        }
     806                                        ?>
     807                                </div>
    738808                        </div>
    739809
    740810        <?php else : // $bulk ?>
    class WP_Posts_List_Table extends WP_List_Table { 
    808878
    809879                </div></fieldset>
    810880
    811         <?php if ( count( $hierarchical_taxonomies ) && !$bulk ) : ?>
     881        <?php if ( count( $hierarchical_taxonomies ) && ( !$bulk || $as_tbody ) ) : ?>
    812882
    813883                <fieldset class="inline-edit-col-center inline-edit-categories"><div class="inline-edit-col">
    814884
    class WP_Posts_List_Table extends WP_List_Table { 
    827897
    828898                </div></fieldset>
    829899
    830         <?php endif; // count( $hierarchical_taxonomies ) && !$bulk ?>
     900        <?php endif; // count( $hierarchical_taxonomies ) && ( !$bulk || $as_tbody ) ?>
    831901
    832902                <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
    833903
    834         <?php
    835                 if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
    836                         echo $authors_dropdown;
    837         ?>
    838 
    839904        <?php if ( $post_type_object->hierarchical ) : ?>
    840905
    841906                        <label>
    class WP_Posts_List_Table extends WP_List_Table { 
    874939                endif; // post_type_supports page-attributes
    875940        endif; // $post_type_object->hierarchical ?>
    876941
    877         <?php if ( count( $flat_taxonomies ) && !$bulk ) : ?>
     942        <?php if ( count( $flat_taxonomies ) && ( !$bulk || $as_tbody ) ) : ?>
    878943
    879944        <?php foreach ( $flat_taxonomies as $taxonomy ) : ?>
    880945
    class WP_Posts_List_Table extends WP_List_Table { 
    885950
    886951        <?php endforeach; //$flat_taxonomies as $taxonomy ?>
    887952
    888         <?php endif; // count( $flat_taxonomies ) && !$bulk  ?>
     953        <?php endif; // count( $flat_taxonomies ) && ( !$bulk || $as_tbody )  ?>
     954       
     955        <?php
     956                if ( post_type_supports( $screen->post_type, 'author' ) && $bulk )
     957                        echo $authors_dropdown;
     958        ?>
    889959
    890960        <?php if ( post_type_supports( $screen->post_type, 'comments' ) || post_type_supports( $screen->post_type, 'trackbacks' ) ) :
    891961                if ( $bulk ) : ?>
    class WP_Posts_List_Table extends WP_List_Table { 
    9981068                        <?php } else {
    9991069                                submit_button( __( 'Update' ), 'button-primary alignright', 'bulk_edit', false, array( 'accesskey' => 's' ) );
    10001070                        } ?>
     1071                       
    10011072                        <input type="hidden" name="post_view" value="<?php echo esc_attr( $m ); ?>" />
    10021073                        <input type="hidden" name="screen" value="<?php echo esc_attr( $screen->id ); ?>" />
    10031074                        <br class="clear" />
    class WP_Posts_List_Table extends WP_List_Table { 
    10071078                $bulk++;
    10081079                }
    10091080?>
    1010                 </tbody></table></form>
     1081                </tbody>
     1082                <?php if ( ! $as_tbody ): ?> </table></form> <?php endif; ?>
    10111083<?php
    10121084        }
    10131085}
  • wp-admin/includes/post.php

    diff --git wp-admin/includes/post.php wp-admin/includes/post.php
    index e445c1e..0de142f 100644
    function bulk_edit_posts( $post_data = null ) { 
    245245        if ( empty($post_data) )
    246246                $post_data = &$_POST;
    247247
     248        if ( isset( $post_data['bulk_post'] ) ) {
     249                $post_data['post'] = array_unique( array_merge( $post_data['post'], $post_data['bulk_post'] ) );
     250        }
     251
    248252        if ( isset($post_data['post_type']) )
    249253                $ptype = get_post_type_object($post_data['post_type']);
    250254        else
  • wp-admin/js/inline-edit-post.dev.js

    diff --git wp-admin/js/inline-edit-post.dev.js wp-admin/js/inline-edit-post.dev.js
    index 1a257c6..9ffb88c 100644
     
    11(function($) {
    22inlineEditPost = {
     3        bulkEditing : false,
    34
    45        init : function(){
    56                var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit');
    inlineEditPost = { 
    4647                        inlineEditPost.edit(this);
    4748                        return false;
    4849                });
     50               
     51                $('.check-column input').live('click', function(){
     52                        var id;
     53                        if (inlineEditPost.bulkEditing) {
     54                                id = $(this).val();
     55                                if ($(this).attr('checked')) {
     56                                        inlineEditPost.addToBulk(id);
     57                                } else {
     58                                        inlineEditPost.removeFromBulk(id);
     59                                }
     60                        }
     61                });
     62               
     63                $('#bulk-titles a').live('click', function(){
     64                        var id = $(this).attr('id').substr(1);
     65                        inlineEditPost.removeFromBulk(id);
     66                });
    4967
    5068                $('#bulk-title-div').parents('fieldset').after(
    5169                        $('#inline-edit fieldset.inline-edit-categories').clone()
    inlineEditPost = { 
    84102                var t = this;
    85103                $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
    86104        },
     105       
     106        addToBulk : function(id) {
     107                var theTitle, item;
     108                theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle;
     109                item = '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
     110                $('#bulk-titles').append(item);
     111        },
     112       
     113        removeFromBulk : function(id) {
     114                $('table.widefat input[value="'+id+'"]').attr('checked', '');
     115                $('#ttle'+id).remove();
     116        },
    87117
    88118        setBulk : function(){
    89                 var te = '', type = this.type, tax, c = true;
     119                var type = this.type, tax, c = true;
    90120                this.revert();
     121                this.bulkEditing = true;
    91122
    92123                $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
    93124                $('table.widefat tbody').prepend( $('#bulk-edit') );
    inlineEditPost = { 
    96127                $('tbody th.check-column input[type="checkbox"]').each(function(i){
    97128                        if ( $(this).attr('checked') ) {
    98129                                c = false;
    99                                 var id = $(this).val(), theTitle;
    100                                 theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle;
    101                                 te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
     130                                var id = $(this).val();
     131                                inlineEditPost.addToBulk(id);
    102132                        }
    103133                });
    104134
    105135                if ( c )
    106136                        return this.revert();
    107137
    108                 $('#bulk-titles').html(te);
    109                 $('#bulk-titles a').click(function(){
    110                         var id = $(this).attr('id').substr(1);
    111 
    112                         $('table.widefat input[value="'+id+'"]').attr('checked', '');
    113                         $('#ttle'+id).remove();
    114                 });
     138//              $('#bulk-titles').html(te);
    115139
    116140                // enable autocomplete for tags
    117141                if ( 'post' == type ) {
    inlineEditPost = { 
    265289                                $('table.widefat #bulk-edit').removeClass('inline-editor').hide();
    266290                                $('#bulk-titles').html('');
    267291                                $('#inlineedit').append( $('#bulk-edit') );
     292                                this.bulkEditing = false;
    268293                        } else {
    269294                                $('#'+id).remove();
    270295                                id = id.substr( id.lastIndexOf('-') + 1 );
  • wp-admin/post.php

    diff --git wp-admin/post.php wp-admin/post.php
    index 883ec3f..21cfeeb 100644
    case 'trash': 
    218218
    219219        if ( ! wp_trash_post($post_id) )
    220220                wp_die( __('Error in moving to Trash.') );
     221        $sendback = remove_query_arg( 'updated', $sendback );
    221222
    222223        wp_redirect( add_query_arg( array('trashed' => 1, 'ids' => $post_id), $sendback ) );
    223224        exit();