]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/includes/class-wp-list-table.php
WordPress 3.9.1-scripts
[autoinstalls/wordpress.git] / wp-admin / includes / class-wp-list-table.php
index 1d80a7ba43f5cdcbec31e088005ace20c92e4f54..3aa066d8afb8163eda145ee607bbdc27c8b9e36f 100644 (file)
@@ -1,12 +1,4 @@
 <?php
-/**
- * Base class for displaying a list of items in an ajaxified HTML table.
- *
- * @package WordPress
- * @subpackage List_Table
- * @since 3.1.0
- */
-
 /**
  * Base class for displaying a list of items in an ajaxified HTML table.
  *
@@ -72,30 +64,34 @@ class WP_List_Table {
        var $_pagination;
 
        /**
-        * Constructor. The child class should call this constructor from it's own constructor
+        * Constructor. The child class should call this constructor from its own constructor
         *
         * @param array $args An associative array with information about the current table
         * @access protected
         */
-       function WP_List_Table( $args = array() ) {
+       function __construct( $args = array() ) {
                $args = wp_parse_args( $args, array(
                        'plural' => '',
                        'singular' => '',
-                       'ajax' => false
+                       'ajax' => false,
+                       'screen' => null,
                ) );
 
-               $screen = get_current_screen();
+               $this->screen = convert_to_screen( $args['screen'] );
 
-               add_filter( "manage_{$screen->id}_columns", array( &$this, 'get_columns' ), 0 );
+               add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
 
                if ( !$args['plural'] )
-                       $args['plural'] = $screen->base;
+                       $args['plural'] = $this->screen->base;
+
+               $args['plural'] = sanitize_key( $args['plural'] );
+               $args['singular'] = sanitize_key( $args['singular'] );
 
                $this->_args = $args;
 
                if ( $args['ajax'] ) {
                        // wp_enqueue_script( 'list-table' );
-                       add_action( 'admin_footer', array( &$this, '_js_vars' ) );
+                       add_action( 'admin_footer', array( $this, '_js_vars' ) );
                }
        }
 
@@ -139,6 +135,12 @@ class WP_List_Table {
                if ( !$args['total_pages'] && $args['per_page'] > 0 )
                        $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
 
+               // redirect if page number is invalid and headers are not already sent
+               if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
+                       wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
+                       exit;
+               }
+
                $this->_pagination_args = $args;
        }
 
@@ -200,10 +202,14 @@ class WP_List_Table {
                        echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
                if ( ! empty( $_REQUEST['order'] ) )
                        echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
+               if ( ! empty( $_REQUEST['post_mime_type'] ) )
+                       echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
+               if ( ! empty( $_REQUEST['detached'] ) )
+                       echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
 ?>
 <p class="search-box">
        <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
-       <input type="text" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
+       <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
        <?php submit_button( $text, 'button', false, false, array('id' => 'search-submit') ); ?>
 </p>
 <?php
@@ -223,16 +229,24 @@ class WP_List_Table {
        }
 
        /**
-        * Display the bulk actions dropdown.
+        * Display the list of views available on this table.
         *
         * @since 3.1.0
         * @access public
         */
        function views() {
-               $screen = get_current_screen();
-
                $views = $this->get_views();
-               $views = apply_filters( 'views_' . $screen->id, $views );
+               /**
+                * Filter the list of available list table views.
+                *
+                * The dynamic portion of the hook name, $this->screen->id, refers
+                * to the ID of the current screen, usually a string.
+                *
+                * @since 3.5.0
+                *
+                * @param array $views An array of available list table views.
+                */
+               $views = apply_filters( "views_{$this->screen->id}", $views );
 
                if ( empty( $views ) )
                        return;
@@ -265,12 +279,21 @@ class WP_List_Table {
         * @access public
         */
        function bulk_actions() {
-               $screen = get_current_screen();
-
                if ( is_null( $this->_actions ) ) {
                        $no_new_actions = $this->_actions = $this->get_bulk_actions();
-                       // This filter can currently only be used to remove actions.
-                       $this->_actions = apply_filters( 'bulk_actions-' . $screen->id, $this->_actions );
+                       /**
+                        * Filter the list table Bulk Actions drop-down.
+                        *
+                        * The dynamic portion of the hook name, $this->screen->id, refers
+                        * to the ID of the current screen, usually a string.
+                        *
+                        * This filter can currently only be used to remove bulk actions.
+                        *
+                        * @since 3.5.0
+                        *
+                        * @param array $actions An array of the available bulk actions.
+                        */
+                       $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
                        $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
                        $two = '';
                } else {
@@ -282,11 +305,16 @@ class WP_List_Table {
 
                echo "<select name='action$two'>\n";
                echo "<option value='-1' selected='selected'>" . __( 'Bulk Actions' ) . "</option>\n";
-               foreach ( $this->_actions as $name => $title )
-                       echo "\t<option value='$name'>$title</option>\n";
+
+               foreach ( $this->_actions as $name => $title ) {
+                       $class = 'edit' == $name ? ' class="hide-if-no-js"' : '';
+
+                       echo "\t<option value='$name'$class>$title</option>\n";
+               }
+
                echo "</select>\n";
 
-               submit_button( __( 'Apply' ), 'button-secondary action', false, false, array( 'id' => "doaction$two" ) );
+               submit_button( __( 'Apply' ), 'action', false, false, array( 'id' => "doaction$two" ) );
                echo "\n";
        }
 
@@ -315,7 +343,7 @@ class WP_List_Table {
         * @access protected
         *
         * @param array $actions The list of actions
-        * @param bool $always_visible Wether the actions should be always visible
+        * @param bool $always_visible Whether the actions should be always visible
         * @return string
         */
        function row_actions( $actions, $always_visible = false ) {
@@ -325,7 +353,7 @@ class WP_List_Table {
                if ( !$action_count )
                        return '';
 
-               $out = '<div class="' . ( $always_visible ? 'row-actions-visible' : 'row-actions' ) . '">';
+               $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
                foreach ( $actions as $action => $link ) {
                        ++$i;
                        ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
@@ -352,6 +380,16 @@ class WP_List_Table {
                        ORDER BY post_date DESC
                ", $post_type ) );
 
+               /**
+                * Filter the 'Months' drop-down results.
+                *
+                * @since 3.7.0
+                *
+                * @param object $months    The months drop-down query results.
+                * @param string $post_type The post type.
+                */
+               $months = apply_filters( 'months_dropdown_results', $months, $post_type );
+
                $month_count = count( $months );
 
                if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
@@ -360,7 +398,7 @@ class WP_List_Table {
                $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
 ?>
                <select name='m'>
-                       <option<?php selected( $m, 0 ); ?> value='0'><?php _e( 'Show all dates' ); ?></option>
+                       <option<?php selected( $m, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option>
 <?php
                foreach ( $months as $arc_row ) {
                        if ( 0 == $arc_row->year )
@@ -372,7 +410,8 @@ class WP_List_Table {
                        printf( "<option %s value='%s'>%s</option>\n",
                                selected( $m, $year . $month, false ),
                                esc_attr( $arc_row->year . $month ),
-                               $wp_locale->get_month( $month ) . " $year"
+                               /* translators: 1: month name, 2: 4-digit year */
+                               sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
                        );
                }
 ?>
@@ -456,6 +495,18 @@ class WP_List_Table {
                if ( empty( $per_page ) || $per_page < 1 )
                        $per_page = $default;
 
+               /**
+                * Filter the number of items to be displayed on each page of the list table.
+                *
+                * The dynamic hook name, $option, refers to the per page option depending
+                * on the type of list table in use. Possible values may include:
+                * 'edit_comments_per_page', 'sites_network_per_page', 'site_themes_network_per_page',
+                * 'themes_netework_per_page', 'users_network_per_page', 'edit_{$post_type}', etc.
+                *
+                * @since 2.9.0
+                *
+                * @param int $per_page Number of items to be displayed. Default 20.
+                */
                return (int) apply_filters( $option, $per_page );
        }
 
@@ -469,13 +520,13 @@ class WP_List_Table {
                if ( empty( $this->_pagination_args ) )
                        return;
 
-               extract( $this->_pagination_args );
+               extract( $this->_pagination_args, EXTR_SKIP );
 
                $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
 
                $current = $this->get_pagenum();
 
-               $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+               $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
 
                $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
 
@@ -504,9 +555,8 @@ class WP_List_Table {
                if ( 'bottom' == $which )
                        $html_current_page = $current;
                else
-                       $html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name='%s' value='%s' size='%d' />",
+                       $html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name='paged' value='%s' size='%d' />",
                                esc_attr__( 'Current page' ),
-                               esc_attr( 'paged' ),
                                $current,
                                strlen( $total_pages )
                        );
@@ -528,9 +578,15 @@ class WP_List_Table {
                        '&raquo;'
                );
 
-               $output .= "\n" . join( "\n", $page_links );
+               $pagination_links_class = 'pagination-links';
+               if ( ! empty( $infinite_scroll ) )
+                       $pagination_links_class = ' hide-if-js';
+               $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
 
-               $page_class = $total_pages < 2 ? ' one-page' : '';
+               if ( $total_pages )
+                       $page_class = $total_pages < 2 ? ' one-page' : '';
+               else
+                       $page_class = ' no-pages';
 
                $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
 
@@ -580,12 +636,21 @@ class WP_List_Table {
                if ( isset( $this->_column_headers ) )
                        return $this->_column_headers;
 
-               $screen = get_current_screen();
-
-               $columns = get_column_headers( $screen );
-               $hidden = get_hidden_columns( $screen );
-
-               $_sortable = apply_filters( "manage_{$screen->id}_sortable_columns", $this->get_sortable_columns() );
+               $columns = get_column_headers( $this->screen );
+               $hidden = get_hidden_columns( $this->screen );
+
+               $sortable_columns = $this->get_sortable_columns();
+               /**
+                * Filter the list table sortable columns for a specific screen.
+                *
+                * The dynamic portion of the hook name, $this->screen->id, refers
+                * to the ID of the current screen, usually a string.
+                *
+                * @since 3.5.0
+                *
+                * @param array $sortable_columns An array of sortable columns.
+                */
+               $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
 
                $sortable = array();
                foreach ( $_sortable as $id => $data ) {
@@ -627,11 +692,9 @@ class WP_List_Table {
         * @param bool $with_id Whether to set the id attribute or not
         */
        function print_column_headers( $with_id = true ) {
-               $screen = get_current_screen();
-
                list( $columns, $hidden, $sortable ) = $this->get_column_info();
 
-               $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+               $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
                $current_url = remove_query_arg( 'paged', $current_url );
 
                if ( isset( $_GET['orderby'] ) )
@@ -644,6 +707,13 @@ class WP_List_Table {
                else
                        $current_order = 'asc';
 
+               if ( ! empty( $columns['cb'] ) ) {
+                       static $cb_counter = 1;
+                       $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
+                               . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
+                       $cb_counter++;
+               }
+
                foreach ( $columns as $column_key => $column_display_name ) {
                        $class = array( 'manage-column', "column-$column_key" );
 
@@ -695,7 +765,7 @@ class WP_List_Table {
                $this->display_tablenav( 'top' );
 
 ?>
-<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0">
+<table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
        <thead>
        <tr>
                <?php $this->print_column_headers(); ?>
@@ -708,7 +778,7 @@ class WP_List_Table {
        </tr>
        </tfoot>
 
-       <tbody id="the-list"<?php if ( $singular ) echo " class='list:$singular'"; ?>>
+       <tbody id="the-list"<?php if ( $singular ) echo " data-wp-lists='list:$singular'"; ?>>
                <?php $this->display_rows_or_placeholder(); ?>
        </tbody>
 </table>
@@ -740,8 +810,8 @@ class WP_List_Table {
 ?>
        <div class="tablenav <?php echo esc_attr( $which ); ?>">
 
-               <div class="alignleft actions">
-                       <?php $this->bulk_actions( $which ); ?>
+               <div class="alignleft actions bulkactions">
+                       <?php $this->bulk_actions(); ?>
                </div>
 <?php
                $this->extra_tablenav( $which );
@@ -802,7 +872,7 @@ class WP_List_Table {
                $row_class = ( $row_class == '' ? ' class="alternate"' : '' );
 
                echo '<tr' . $row_class . '>';
-               echo $this->single_row_columns( $item );
+               $this->single_row_columns( $item );
                echo '</tr>';
        }
 
@@ -833,7 +903,7 @@ class WP_List_Table {
                        }
                        elseif ( method_exists( $this, 'column_' . $column_name ) ) {
                                echo "<td $attributes>";
-                               echo call_user_func( array( &$this, 'column_' . $column_name ), $item );
+                               echo call_user_func( array( $this, 'column_' . $column_name ), $item );
                                echo "</td>";
                        }
                        else {
@@ -854,7 +924,7 @@ class WP_List_Table {
                $this->prepare_items();
 
                extract( $this->_args );
-               extract( $this->_pagination_args );
+               extract( $this->_pagination_args, EXTR_SKIP );
 
                ob_start();
                if ( ! empty( $_REQUEST['no_placeholder'] ) )
@@ -884,11 +954,13 @@ class WP_List_Table {
         */
        function _js_vars() {
                $args = array(
-                       'class' => get_class( $this ),
-                       'screen' => get_current_screen()
+                       'class'  => get_class( $this ),
+                       'screen' => array(
+                               'id'   => $this->screen->id,
+                               'base' => $this->screen->base,
+                       )
                );
 
                printf( "<script type='text/javascript'>list_args = %s;</script>\n", json_encode( $args ) );
        }
 }
-?>