Make WordPress Core

Changeset 9296


Ignore:
Timestamp:
10/23/2008 04:08:47 PM (16 years ago)
Author:
ryan
Message:

Comment paging and sorting from Viper007Bond. see #7927

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/schema.php

    r9290 r9296  
    289289    add_option('close_comments_for_old_posts', 0);
    290290    add_option('close_comments_days_old', 14);
     291    add_option('thread_comments', 0);
     292    add_option('thread_comments_depth', 5);
     293    add_option('page_comments', 1);
     294    add_option('comments_per_page', 10);
     295    add_option('default_comments_page', 'newest');
     296    add_option('comment_order', 'asc');
    291297
    292298    // Delete unused options
  • trunk/wp-admin/options-discussion.php

    r9233 r9296  
    4444<?php _e('Allow people to post comments on the article') ?></label>
    4545<br />
     46<small><em><?php echo '(' . __('These settings may be overridden for individual articles.') . ')'; ?></em></small>
     47</fieldset></td>
     48</tr>
     49<tr valign="top">
     50<th scope="row"><?php _e('Other comment settings') ?></th>
     51<td><fieldset><legend class="hidden"><?php _e('Other comment settings') ?></legend>
    4652<label for="require_name_email"><input type="checkbox" name="require_name_email" id="require_name_email" value="1" <?php checked('1', get_option('require_name_email')); ?> /> <?php _e('Comment author must fill out name and e-mail') ?></label>
    4753<br />
    4854<label for="close_comments_for_old_posts">
    4955<input name="close_comments_for_old_posts" type="checkbox" id="close_comments_for_old_posts" value="1" <?php checked('1', get_option('close_comments_for_old_posts')); ?> />
    50 <?php printf( __('Close comments on articles older than %s days'), '</label><input name="close_comments_days_old" type="text" id="close_comments_days_old" value="' . attribute_escape(get_option('close_comments_days_old')) . '" size="3" />') ?>
     56<?php printf( __('Automatically close comments on articles older than %s days'), '</label><input name="close_comments_days_old" type="text" id="close_comments_days_old" value="' . attribute_escape(get_option('close_comments_days_old')) . '" size="3" />') ?>
    5157<br />
    5258<label for="thread_comments">
     
    6975<label for="page_comments">
    7076<input name="page_comments" type="checkbox" id="page_comments" value="1" <?php checked('1', get_option('page_comments')); ?> />
    71 <?php printf( __('Break comments into pages with %s comments per page'), '</label><input name="comments_per_page" type="text" id="comments_per_page" value="' . attribute_escape(get_option('comments_per_page')) . '" size="3" />') ?>
    72 <br />
    73 <small><em><?php echo '(' . __('These settings may be overridden for individual articles.') . ')'; ?></em></small>
     77<?php
     78
     79$default_comments_page = '</label><select name="default_comments_page" id="default_comments_page"><option value="newest"';
     80if ( 'newest' == get_option('default_comments_page') ) $default_comments_page .= ' selected="selected"';
     81$default_comments_page .= '>' . __('last') . '</option><option value="oldest"';
     82if ( 'oldest' == get_option('default_comments_page') ) $default_comments_page .= ' selected="selected"';
     83$default_comments_page .= '>' . __('first') . '</option></select>';
     84
     85printf( __('Break comments into pages with %1$s comments per page and the %2$s page displayed by default'), '</label><input name="comments_per_page" type="text" id="comments_per_page" value="' . attribute_escape(get_option('comments_per_page')) . '" size="3" />', $default_comments_page );
     86
     87?>
     88<br />
     89<label for="comment_order"><?php
     90
     91$comment_order = '<select name="comment_order" id="comment_order"><option value="asc"';
     92if ( 'asc' == get_option('comment_order') ) $comment_order .= ' selected="selected"';
     93$comment_order .= '>' . __('older') . '</option><option value="desc"';
     94if ( 'desc' == get_option('comment_order') ) $comment_order .= ' selected="selected"';
     95$comment_order .= '>' . __('newer') . '</option></select>';
     96
     97printf( __('Comments should be displayed with the %s comments at the top of each page'), $comment_order );
     98
     99?></label>
    74100</fieldset></td>
    75101</tr>
  • trunk/wp-admin/options.php

    r9250 r9296  
    2424$whitelist_options = array(
    2525    'general' => array('blogname', 'blogdescription', 'admin_email', 'users_can_register', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'comment_registration', 'default_role' ),
    26     'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page' ),
     26    'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order' ),
    2727    'misc' => array( 'hack_file', 'use_linksupdate', 'uploads_use_yearmonth_folders', 'upload_path' ),
    2828    'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type' ),
  • trunk/wp-comments-post.php

    r8720 r9296  
    8080}
    8181
    82 $location = ( empty($_POST['redirect_to']) ? get_permalink($comment_post_ID) : $_POST['redirect_to'] ) . '#comment-' . $comment_id;
     82if ( empty($_POST['redirect_to']) )
     83    $postlink = ( 'newest' == get_option('default_comments_page') ) ? get_permalink($comment_post_ID) : add_query_arg( 'cpage', get_comment_pages_count( get_comments( array( 'post_id' => $comment_post_ID ) ) ), get_permalink($comment_post_ID) );
     84
     85$location = ( empty($_POST['redirect_to']) ? $postlink : $_POST['redirect_to'] ) . '#comment-' . $comment_id;
    8386$location = apply_filters('comment_post_redirect', $location, $comment);
    8487
  • trunk/wp-includes/classes.php

    r9083 r9296  
    986986        // flat display
    987987        if ( -1 == $max_depth ) {
     988            if ( !empty($args[0]['reverse_top_level']) ) {
     989                $elements = array_reverse( $elements );
     990                $oldstart = $start;
     991                $start = $total_top - $end;
     992                $end = $total_top - $oldstart;
     993            }
     994
    988995            $empty_array = array();
    989996            foreach ( $elements as $e ) {
     
    10181025            $end = $total_top;
    10191026
    1020         foreach( $top_level_elements as $e ){
     1027        if ( !empty($args[0]['reverse_top_level']) ) {
     1028            $top_level_elements = array_reverse( $top_level_elements );
     1029            $oldstart = $start;
     1030            $start = $total_top - $end;
     1031            $end = $total_top - $oldstart;
     1032        }
     1033        if ( !empty($args[0]['reverse_children']) ) {
     1034            foreach ( $children_elements as $parent => $children )
     1035                $children_elements[$parent] = array_reverse( $children );
     1036        }
     1037
     1038        foreach ( $top_level_elements as $e ) {
    10211039            $count++;
    10221040
  • trunk/wp-includes/comment-template.php

    r9209 r9296  
    762762        $comments_by_type = &$wp_query->comments_by_type;
    763763    }
     764
     765    if ( '' == get_query_var('cpage') && get_option('page_comments') && 'newest' == get_option('default_comments_page') )
     766        set_query_var( 'cpage', get_comment_pages_count() );
    764767
    765768    define('COMMENTS_TEMPLATE', true);
     
    11231126 * @uses Walker_Comment
    11241127 *
    1125  * @param $args string|array Formatting options
    1126  * @param $comments array Optional array of comment objects.  Defaults to $wp_query->comments
     1128 * @param string|array $args Formatting options
     1129 * @param array $comments Optional array of comment objects.  Defaults to $wp_query->comments
    11271130 */
    11281131function wp_list_comments($args = array(), $comments = null ) {
     
    11331136
    11341137    $defaults = array('walker' => null, 'depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
    1135         'page' => get_query_var('cpage'), 'per_page' => '', 'avatar_size' => 32);
     1138        'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => '', 'reverse_children' => '');
    11361139
    11371140    $r = wp_parse_args( $args, $defaults );
     
    11431146        $r['per_page'] = 0;
    11441147        $r['page'] = 0;
    1145     } else {
    1146         $r['page'] = intval($r['page']);
    1147         if ( empty($r['page']) )
    1148             $r['page'] = 1;
    11491148    }
    11501149
     
    11551154            $r['depth'] = -1;
    11561155    }
     1156
     1157    if ( '' === $r['page'] ) {
     1158        if ( empty($comments) ) {
     1159            $r['page'] = get_query_var('cpage');
     1160        } else {
     1161            $threaded = ( -1 == $r['depth'] ) ? false : true;
     1162            $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($comments, $r['per_page'], $threaded) : 1;
     1163            set_query_var( 'cpage', $r['page'] );
     1164        }
     1165    }
     1166    // Validation check
     1167    $r['page'] = intval($r['page']);
     1168    if ( 0 == $r['page'] && 0 != $r['per_page'] )
     1169        $r['page'] = 1;
     1170
     1171    if ( '' == $r['reverse_top_level'] )
     1172        $r['reverse_top_level'] = ( 'asc' == get_option('comment_order') ) ? FALSE : TRUE;
    11571173
    11581174    extract( $r, EXTR_SKIP );
  • trunk/wp-includes/comment.php

    r9292 r9296  
    482482
    483483/**
     484 * Calculate the total number of comment pages.
     485 *
     486 * @since 2.7.0
     487 *
     488 * @param array $comments Optional array of comment objects.  Defaults to $wp_query->comments
     489 * @param int $per_page Optional comments per page.
     490 * @param boolean $threaded Optional control over flat or threaded comments.
     491 * @return int Number of comment pages.
     492 */
     493function get_comment_pages_count( $comments = null, $per_page = null, $threaded = null ) {
     494    global $wp_query;
     495
     496    if ( !$comments || !is_array($comments) )
     497        $comments = $wp_query->comments;
     498
     499    if ( empty($comments) )
     500        return 0;
     501
     502    if ( !isset($per_page) )
     503        $per_page = (int) get_query_var('comments_per_page');
     504    if ( 0 === $per_page )
     505        $per_page = (int) get_option('comments_per_page');
     506    if ( 0 === $per_page )
     507        return 1;
     508
     509    if ( !isset($threaded) )
     510        $threaded = get_option('thread_comments');
     511
     512    if ( $threaded ) {
     513        $walker = new Walker_Comment;
     514        $count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );
     515    } else {
     516        $count = ceil( count( $comments ) / $per_page );
     517    }
     518
     519    return $count;
     520}
     521
     522/**
    484523 * Does comment contain blacklisted characters or words.
    485524 *
  • trunk/wp-includes/link-template.php

    r9274 r9296  
    11361136 * @return string
    11371137 */
    1138 function get_comments_pagenum_link($pagenum = 1) {
     1138function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
    11391139    global $wp_rewrite;
    11401140
     
    11521152    $base = trailingslashit( get_bloginfo( 'home' ) );
    11531153
    1154     if ( $pagenum > 1 ) {
     1154    $result = $base . $request;
     1155   
     1156    if ( 'newest' == get_option('default_comments_page') ) {
     1157        if ( $pagenum != $max_page )
     1158            $result = add_query_arg( 'cpage', $pagenum, $base . $request );
     1159    } elseif ( $pagenum > 1 )
    11551160        $result = add_query_arg( 'cpage', $pagenum, $base . $request );
    1156     } else {
    1157         $result = $base . $request;
    1158     }
    11591161
    11601162    $result .= '#comments';
     
    11951197        $label = __('&raquo; Newer Comments');
    11961198
    1197     echo '<a href="' . clean_url(get_comments_pagenum_link($nextpage));
     1199    echo '<a href="' . clean_url( get_comments_pagenum_link( $nextpage, $max_page ) );
    11981200    $attr = apply_filters( 'next_comments_link_attributes', '' );
    11991201    echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
  • trunk/wp-includes/version.php

    r9290 r9296  
    99 * @global string $wp_version
    1010 */
    11 $wp_version = '2.7-almost-beta';
     11$wp_version = '2.7-almost-beta-9296';
    1212
    1313/**
     
    1616 * @global int $wp_db_version
    1717 */
    18 $wp_db_version = 9290;
     18$wp_db_version = 9296;
    1919
    2020?>
Note: See TracChangeset for help on using the changeset viewer.