WordPress.org

Make WordPress Core

Ticket #2004: pages page should page proof.patch

File pages page should page proof.patch, 13.1 KB (added by Jairus, 10 years ago)

dirty proof-of-concept for paging on wp 2.3

  • edit-pages.php

     
    1 <?php
    2 require_once('admin.php');
    3 $title = __('Pages');
    4 $parent_file = 'edit.php';
    5 wp_enqueue_script( 'listman' );
    6 require_once('admin-header.php');
    7 
    8 $post_stati  = array(   //      array( adj, noun )
    9                         'publish' => array(__('Published'), __('Published pages')),
    10                         'draft'   => array(__('Draft'), __('Draft pages')),
    11                         'private' => array(__('Private'), __('Private pages'))
    12                 );
    13 
    14 
    15 $post_status_label = __('Pages');
    16 $post_status_q = '';
    17 if ( isset($_GET['post_status']) && in_array( $_GET['post_status'], array_keys($post_stati) ) ) {
    18         $post_status_label = $post_stati[$_GET['post_status']][1];
    19         $post_status_q = '&post_status=' . $_GET['post_status'];
    20 }
    21 
    22 ?>
    23 
    24 <div class="wrap">
    25 
    26 <h2><?php
    27 // Use $_GET instead of is_ since they can override each other
    28 $h2_search = isset($_GET['s']) && $_GET['s'] ? ' ' . sprintf(__('matching &#8220;%s&#8221;'), wp_specialchars( stripslashes( $_GET['s'] ) ) ) : '';
    29 $h2_author = '';
    30 if ( isset($_GET['author']) && $_GET['author'] ) {
    31         $author_user = get_userdata( (int) $_GET['author'] );
    32         $h2_author = ' ' . sprintf(__('by %s'), wp_specialchars( $author_user->display_name ));
    33 }
    34 printf( _c( '%1$s%2$s%3$s|You can reorder these: 1: Pages, 2: by {s}, 3: matching {s}' ), $post_status_label, $h2_author, $h2_search );
    35 ?></h2>
    36 
    37 <p><?php _e('Pages are like posts except they live outside of the normal blog chronology and can be hierarchical. You can use pages to organize and manage any amount of content.'); ?> <a href="page-new.php"><?php _e('Create a new page &raquo;'); ?></a></p>
    38 
    39 <form name="searchform" id="searchform" action="" method="get">
    40         <fieldset><legend><?php _e('Search Terms&hellip;') ?></legend>
    41                 <input type="text" name="s" id="s" value="<?php echo attribute_escape( stripslashes( $_GET['s'] ) ); ?>" size="17" />
    42         </fieldset>
    43 
    44 
    45         <fieldset><legend><?php _e('Page Type&hellip;'); ?></legend>
    46                 <select name='post_status'>
    47                         <option<?php selected( @$_GET['post_status'], 0 ); ?> value='0'><?php _e('Any'); ?></option>
    48 <?php   foreach ( $post_stati as $status => $label ) : ?>
    49                         <option<?php selected( @$_GET['post_status'], $status ); ?> value='<?php echo $status; ?>'><?php echo $label[0]; ?></option>
    50 <?php   endforeach; ?>
    51                 </select>
    52         </fieldset>
    53 
    54 <?php $editable_ids = get_editable_user_ids( $user_ID ); if ( $editable_ids && count( $editable_ids ) > 1 ) : ?>
    55 
    56         <fieldset><legend><?php _e('Author&hellip;'); ?></legend>
    57                 <?php wp_dropdown_users( array('include' => $editable_ids, 'show_option_all' => __('Any'), 'name' => 'author', 'selected' => isset($_GET['author']) ? $_GET['author'] : 0) ); ?>
    58         </fieldset>
    59 
    60 <?php endif; ?>
    61 
    62         <input type="submit" id="post-query-submit" value="<?php _e('Filter &#187;'); ?>" class="button" />
    63 </form>
    64 
    65 <br style="clear:both;" />
    66 
    67 <?php
    68 wp("post_type=page&orderby=menu_order&what_to_show=posts$post_status_q&posts_per_page=-1&posts_per_archive_page=-1&order=asc");
    69 
    70 $all = !( $h2_search || $post_status_q );
    71 
    72 if ($posts) {
    73 ?>
    74 <table class="widefat">
    75   <thead>
    76   <tr>
    77     <th scope="col" style="text-align: center"><?php _e('ID') ?></th>
    78     <th scope="col"><?php _e('Title') ?></th>
    79     <th scope="col"><?php _e('Owner') ?></th>
    80         <th scope="col"><?php _e('Updated') ?></th>
    81         <th scope="col" colspan="3" style="text-align: center"><?php _e('Action'); ?></th>
    82   </tr>
    83   </thead>
    84   <tbody id="the-list">
    85 <?php page_rows(0, 0, $posts, $all); ?>
    86   </tbody>
    87 </table>
    88 
    89 <div id="ajax-response"></div>
    90 
    91 <?php
    92 } else {
    93 ?>
    94 <p><?php _e('No pages found.') ?></p>
    95 <?php
    96 } // end if ($posts)
    97 ?>
    98 
    99 <h3><a href="page-new.php"><?php _e('Create New Page &raquo;'); ?></a></h3>
    100 
    101 </div>
    102 
    103 <?php include('admin-footer.php'); ?>
     1<?php
     2require_once('admin.php');
     3$title = __('Pages');
     4$parent_file = 'edit.php';
     5wp_enqueue_script( 'listman' );
     6require_once('admin-header.php');
     7
     8$post_stati  = array(   //      array( adj, noun )
     9                        'publish' => array(__('Published'), __('Published pages')),
     10                        'draft'   => array(__('Draft'), __('Draft pages')),
     11                        'private' => array(__('Private'), __('Private pages'))
     12                );
     13
     14
     15$post_status_label = __('Pages');
     16$post_status_q = '';
     17if ( isset($_GET['post_status']) && in_array( $_GET['post_status'], array_keys($post_stati) ) ) {
     18        $post_status_label = $post_stati[$_GET['post_status']][1];
     19        $post_status_q = '&post_status=' . $_GET['post_status'];
     20}
     21
     22?>
     23
     24<div class="wrap">
     25
     26<h2><?php
     27// Use $_GET instead of is_ since they can override each other
     28$h2_search = isset($_GET['s']) && $_GET['s'] ? ' ' . sprintf(__('matching &#8220;%s&#8221;'), wp_specialchars( stripslashes( $_GET['s'] ) ) ) : '';
     29$h2_author = '';
     30if ( isset($_GET['author']) && $_GET['author'] ) {
     31        $author_user = get_userdata( (int) $_GET['author'] );
     32        $h2_author = ' ' . sprintf(__('by %s'), wp_specialchars( $author_user->display_name ));
     33}
     34printf( _c( '%1$s%2$s%3$s|You can reorder these: 1: Pages, 2: by {s}, 3: matching {s}' ), $post_status_label, $h2_author, $h2_search );
     35?></h2>
     36
     37<p><?php _e('Pages are like posts except they live outside of the normal blog chronology and can be hierarchical. You can use pages to organize and manage any amount of content.'); ?> <a href="page-new.php"><?php _e('Create a new page &raquo;'); ?></a></p>
     38
     39<form name="searchform" id="searchform" action="" method="get">
     40        <fieldset><legend><?php _e('Search Terms&hellip;') ?></legend>
     41                <input type="text" name="s" id="s" value="<?php echo attribute_escape( stripslashes( $_GET['s'] ) ); ?>" size="17" />
     42        </fieldset>
     43
     44
     45        <fieldset><legend><?php _e('Page Type&hellip;'); ?></legend>
     46                <select name='post_status'>
     47                        <option<?php selected( @$_GET['post_status'], 0 ); ?> value='0'><?php _e('Any'); ?></option>
     48<?php   foreach ( $post_stati as $status => $label ) : ?>
     49                        <option<?php selected( @$_GET['post_status'], $status ); ?> value='<?php echo $status; ?>'><?php echo $label[0]; ?></option>
     50<?php   endforeach; ?>
     51                </select>
     52        </fieldset>
     53
     54<?php $editable_ids = get_editable_user_ids( $user_ID ); if ( $editable_ids && count( $editable_ids ) > 1 ) : ?>
     55
     56        <fieldset><legend><?php _e('Author&hellip;'); ?></legend>
     57                <?php wp_dropdown_users( array('include' => $editable_ids, 'show_option_all' => __('Any'), 'name' => 'author', 'selected' => isset($_GET['author']) ? $_GET['author'] : 0) ); ?>
     58        </fieldset>
     59
     60<?php endif; ?>
     61
     62        <input type="submit" id="post-query-submit" value="<?php _e('Filter &#187;'); ?>" class="button" />
     63</form>
     64
     65<br style="clear:both;" />
     66
     67<?php
     68wp("post_type=page&orderby=menu_order&what_to_show=posts$post_status_q&posts_per_page=-1&posts_per_archive_page=-1&order=asc");
     69
     70$all = !( $h2_search || $post_status_q );
     71
     72if ($posts) {
     73?>
     74<table class="widefat">
     75  <thead>
     76  <tr>
     77    <th scope="col" style="text-align: center"><?php _e('ID') ?></th>
     78    <th scope="col"><?php _e('Title') ?></th>
     79    <th scope="col"><?php _e('Owner') ?></th>
     80        <th scope="col"><?php _e('Updated') ?></th>
     81        <th scope="col" colspan="3" style="text-align: center"><?php _e('Action'); ?></th>
     82  </tr>
     83  </thead>
     84  <tbody id="the-list">
     85<?php
     86
     87            if ( $all == false )
     88            {
     89                page_rows(0, 0, $posts, $all);
     90            }
     91            else
     92            {
     93             
     94$numPagesPerPage = 50; //number of pages to be displayed per page
     95$pages =  $wpdb->get_results("SELECT `post_title`, `ID`, `guid`, `post_author`, `post_modified`  FROM `wp_posts` WHERE `post_type` = 'page' ORDER BY `wp_posts`.`ID` DESC", ARRAY_A);
     96$size = sizeof($pages);//total number of pages in the database
     97
     98$numAdminPagesfull =$size/$numPagesPerPage;//get the total number of full admin pages
     99$numAdminPages =  (int)$numAdminPagesfull;//get rid of the fraction if there is one
     100$fraction = false;//initally set this to false
     101
     102//if they are not equal, then the number of pages is not divisble by the $numPagesPerPage
     103if($numAdminPages != $numAdminPagesfull){
     104$numPagesLastPage = ($numAdminPagesfull-$numAdminPages)*$numPagesPerPage;//this gets the number of posts on the last page
     105$numAdminPages++;//increase it so we know how many pages there are
     106$fraction = true;//so we know that there arent the full number of pages on the last page
     107}
     108
     109if (isset($_POST['pageNum'])){
     110        $adminPage = $_POST['pageNum'];
     111        unset($_POST['pageNum']);
     112        if (isset($_POST['back'])){
     113        unset($_POST['back']); 
     114        $adminPage--;
     115        }else if (isset($_POST['next'])){
     116        unset($_POST['next']); 
     117        $adminPage++;
     118        }
     119        }else{
     120        $adminPage = 1;
     121}       
     122//if thre is a fraction, and on the last page, then do it differently
     123if ($fraction && $adminPage == $numAdminPages){
     124$lowernum = ($adminPage-1)*$numPagesPerPage;
     125$uppernum = $lowernum + $numPagesLastPage;
     126}else{
     127//else, get the adminpage and multiply it by the number of pages per page
     128$lowernum = ($adminPage-1)*$numPagesPerPage;
     129$uppernum = $adminPage*$numPagesPerPage;       
     130}
     131
     132$displayPages ="";//empty this
     133for ($i = $lowernum; $i < $uppernum; $i++){
     134$displayPages[] = $pages[$i];//add the pages to the displayPage
     135}
     136//give it to the function to display the pages info on the page
     137page_rows_modified($displayPages);
     138}
     139?>
     140  </tbody>
     141</table>
     142
     143<div id="ajax-response"></div>
     144
     145<?php
     146} else {
     147?>
     148<p><?php _e('No pages found.') ?></p>
     149<?php
     150} // end if ($posts)
     151if ( $all != false ){
     152//if not searched, then display the below
     153echo '<p>Displaying pages '.$lowernum.' to '.$uppernum.' of total '. $size.' pages.</p>';       
     154        ?>
     155
     156<div>
     157<table>
     158<tr>
     159<?php
     160//the above div may not be styled properly
     161$z = 0;
     162//add a button for each page
     163while ($z <  $numAdminPages){
     164?>
     165
     166<form action="" method="post">
     167<input type="hidden" name="pageNum" id="pageNum" value="<?php echo $z+1; ?>">
     168<input type="submit" name="submit" value="<?php echo $z+1; ?>"
     169<?php if($adminPage != $z+1){
     170//if  on the page that is being viewed, then style the button   
     171}else {echo 'style="background:#fff;"';
     172}?>
     173/>
     174</form>
     175
     176<?php
     177$z++;
     178}
     179?>
     180</tr>
     181</table>
     182
     183</div>
     184
     185<div class="navigation">
     186<div class="alignleft"><?php
     187if( $adminPage > 1){
     188        //if not on the first page, add a button to scroll back a page
     189        ?>
     190        <form action="" method="post">
     191        <input type="hidden" name="back" id="back" value="true">
     192        <input type="hidden" name="pageNum" id=pageNum" value="<?php echo $adminPage ?>">
     193        <p class="submit">
     194        <input type="submit" name="submit" value="&laquo Previous Page" />
     195        </p>
     196        </form>
     197<?php
     198}
     199?>
     200</div>
     201
     202<div class="alignright"><?php
     203//if not on the last page, add a button to go to the next page
     204if($adminPage < $numAdminPages){
     205        ?>
     206<form action="" method="post">
     207        <input type="hidden" name="next" id="next" value="true">
     208        <input type="hidden" name="pageNum" id="pageNum" value="<?php echo $adminPage ?>">
     209        <p class="submit">
     210        <input type="submit" name="submit" value="Next Page &raquo" />
     211        </p>
     212        </form>
     213<?php
     214}
     215?>
     216</div>
     217
     218</div>
     219<br><br><br>
     220<?php
     221//may need to do some styling, like the above <br> probably shouldnt be used
     222}?>
     223
     224<h3><a href="page-new.php"><?php _e('Create New Page &raquo;'); ?></a></h3>
     225
     226</div>
     227
     228<?php include('admin-footer.php'); ?>
  • includes/template.php

     
    199199                if ( $hierarchy ) page_rows( $id, $level + 1, $pages );
    200200        }
    201201}
     202//added by Jason Manion
     203function page_rows_modified($pages = 0) {
     204        global $wpdb, $class;
     205
     206        if ( empty($pages) || $pages == 0 )
     207                return false;
     208               
     209        foreach ( $pages as $post) {
     210               
     211                $title = wp_specialchars($post['post_title']);
     212                $id =  $post['ID'];
     213                $class = ('alternate' == $class ) ? '' : 'alternate';
     214                $link = $post['guid'];
     215                $authorid = $post['post_author'];
     216?>
     217        <tr id='page-<?php echo $id; ?>' class='<?php echo $class; ?>'>
     218    <td scope="row" style="text-align: center"><?php echo $id; ?></td>
     219    <td><?php echo $title; ?></td>
     220    <td><?php  $first = get_usermeta($authorid,'first_name'); $last = get_usermeta($authorid,'last_name'); echo $first." ".$last; ?></td>
     221    <td><?php if ( '0000-00-00 00:00:00' ==$post['post_modified'] ) _e('Unpublished'); else echo mysql2date( __('Y-m-d g:i a'), $post['post_modified'] ); ?></td>
     222        <td><a href="<?php echo $link ?>" rel="permalink" class="view"><?php _e( 'View' ); ?></a></td>
     223    <td><?php if ( current_user_can( 'edit_page', $id ) ) { echo "<a href='page.php?action=edit&amp;post=$id' class='edit'>" . __( 'Edit' ) . "</a>"; } ?></td>
     224    <td><?php if ( current_user_can( 'delete_page', $id ) ) { echo "<a href='" . wp_nonce_url( "page.php?action=delete&amp;post=$id", 'delete-page_' . $id ) .  "' class='delete' onclick=\"return deleteSomething( 'page', " . $id . ", '" . js_escape(sprintf( __("You are about to delete the '%s' page.\n'OK' to delete, 'Cancel' to stop." ), get_the_title() ) ) . "' );\">" . __( 'Delete' ) . "</a>"; } ?></td>
     225  </tr>
     226
     227<?php
     228}
     229}
    202230
    203231function user_row( $user_object, $style = '' ) {
    204232        if ( !(is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )