Make WordPress Core

Changeset 8961


Ignore:
Timestamp:
09/23/2008 09:11:27 PM (16 years ago)
Author:
ryan
Message:

First cut of comment paging. Add paging and threading settings. see #7769 #7635

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/options-discussion.php

    r8892 r8961  
    4040<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')); ?> />
    4141<?php _e('Close comments on articles older than') ?></label> <?php printf(__('%s days'), '<input name="close_comments_days_old" type="text" id="close_comments_days_old" value="' . attribute_escape(get_option('close_comments_days_old')) . '" size="3" />') ?>
     42<br />
     43<label for="thread_comments">
     44<input name="thread_comments" type="checkbox" id="thread_comments" value="1" <?php checked('1', get_option('thread_comments')); ?> />
     45<?php _e('Group replies into threads') ?></label> <?php printf(__('%s levels deep'), '<input name="thread_comments_depth" type="text" id="thread_comments_depth" value="' . attribute_escape(get_option('thread_comments_depth')) . '" size="3" />') ?>
     46<br />
     47<label for="page_comments">
     48<input name="page_comments" type="checkbox" id="page_comments" value="1" <?php checked('1', get_option('page_comments')); ?> />
     49<?php _e('Break comments into pages with') ?></label> <?php printf(__('%s comments per page'), '<input name="comments_per_page" type="text" id="comments_per_page" value="' . attribute_escape(get_option('comments_per_page')) . '" size="3" />') ?>
    4250<br />
    4351<small><em><?php echo '(' . __('These settings may be overridden for individual articles.') . ')'; ?></em></small>
  • trunk/wp-admin/options.php

    r8906 r8961  
    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', 'close_comments_for_old_posts', 'close_comments_days_old' ),
     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', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page' ),
    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-content/themes/default/comments.php

    r8938 r8961  
    1616
    1717    <ol class="commentlist">
    18     <?php wp_list_comments($comments); ?>
     18    <?php wp_list_comments(); ?>
    1919    </ol>
    20 
     20    <div class="navigation">
     21        <div class="alignleft"><?php previous_comments_link() ?></div>
     22        <div class="alignright"><?php next_comments_link() ?></div>
     23    </div>
    2124 <?php else : // this is displayed if there are no comments so far ?>
    2225
  • trunk/wp-includes/classes.php

    r8939 r8961  
    2727     * @var array
    2828     */
    29     var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term');
     29    var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'debug', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage');
    3030
    3131    /**
     
    3737     * @var array
    3838     */
    39     var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm');
     39    var $private_query_vars = array('offset', 'posts_per_page', 'posts_per_archive_page', 'what_to_show', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page');
    4040
    4141    /**
     
    732732
    733733    /**
     734     * Max number of pages walked by the paged walker
     735     *
     736     * @since 2.7.0
     737     * @var int
     738     * @access protected
     739     */
     740    var $max_pages = 1;
     741
     742    /**
    734743     * Starts the list before the elements are added.
    735744     *
     
    948957
    949958        /* sanity check */
    950         if ( empty($elements) || $max_depth < 0 )
     959        if ( empty($elements) || $max_depth < -1 )
    951960            return '';
    952961
     
    956965        $id_field = $this->db_fields['id'];
    957966        $parent_field = $this->db_fields['parent'];
     967
     968        $count = -1;
     969        if ( -1 == $max_depth )
     970            $total_top = count( $elements );
     971        if ( $page_num < 1 || $per_page < 0  ) {
     972            // No paging
     973            $paging = false;
     974            $start = 0;
     975            if ( -1 == $max_depth )
     976                $end = $total_top;
     977            $this->max_pages = 1;
     978        } else {
     979            $paging = true;
     980            $start = ( (int)$page_num - 1 ) * (int)$per_page;
     981            $end   = $start + $per_page;
     982            if ( -1 == $max_depth )
     983                $this->max_pages = ceil($total_top / $per_page);
     984        }
     985
     986        // flat display
     987        if ( -1 == $max_depth ) {
     988            $empty_array = array();
     989            foreach ( $elements as $e ) {
     990                $count++;
     991                if ( $count < $start )
     992                    continue;
     993                if ( $count >= $end )
     994                    break;
     995                $this->display_element( $e, $empty_array, 1, 0, $args, $output );
     996            }
     997            return $output;
     998        }
    958999
    9591000        /*
     
    9711012        }
    9721013
    973         $count = -1;
    9741014        $total_top = count( $top_level_elements );
    975         if ( $page_num < 1 || $per_page < 0  ) {
    976             $start = 0;
    977             $end = $total_top;
    978         } else {
    979             $start = ( (int)$page_num - 1 ) * (int)$per_page;
    980             $end   = $start + $per_page;
    981         }
     1015
     1016        if ( $paging )
     1017            $this->max_pages = ceil($total_top / $per_page);
    9821018
    9831019        foreach( $top_level_elements as $e ){
     
    9971033        }
    9981034
    999         if ( $end >= $total_top && count( $children_elements ) > 0 ){
     1035        if ( $end >= $total_top && count( $children_elements ) > 0 ) {
    10001036            $empty_array = array();
    10011037            foreach ( $children_elements as $orphans )
     
    10311067            $this->unset_children( $child, $children_elements );
    10321068
    1033         unset( $children_elements[$id] );
     1069        if ( isset($children_elements[$id]) )
     1070            unset( $children_elements[$id] );
    10341071
    10351072    }
  • trunk/wp-includes/comment-template.php

    r8941 r8961  
    851851    $args = wp_parse_args($args, $defaults);
    852852
    853     if ( 0 == $args['depth'] || $args['max_depth'] < $args['depth'] )
     853    if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
    854854        return;
    855855
     
    974974 *
    975975 * @param $args string|array Formatting options
    976     * @param $comments array Optional array of comment objects.  Defaults to $wp_query->comments
     976 * @param $comments array Optional array of comment objects.  Defaults to $wp_query->comments
    977977 */
    978978function wp_list_comments($args = array(), $comments = null ) {
    979979    global $wp_query;
    980980
    981     $defaults = array('walker' => null, 'depth' => 3, 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all');
     981    $defaults = array('walker' => null, 'depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
     982        'page' => get_query_var('cpage'), 'per_page' => '');
    982983
    983984    $r = wp_parse_args( $args, $defaults );
     985
     986    if ( '' === $r['per_page'] && get_option('page_comments') )
     987        $r['per_page'] = get_query_var('comments_per_page');
     988
     989    if ( empty($r['per_page']) ) {
     990        $r['page'] = 0;
     991    } else {
     992        $r['page'] = intval($r['page']);
     993        if ( empty($r['page']) )
     994            $r['page'] = 1;
     995    }
     996
     997    if ( '' === $r['depth'] ) {
     998        if ( get_option('thread_comments') )
     999            $r['depth'] = get_option('thread_comments_depth');
     1000        else
     1001            $r['depth'] = -1;
     1002    }
    9841003
    9851004    extract( $r, EXTR_SKIP );
     
    9961015            if ( empty($wp_query->comments_by_type[$type]) )
    9971016                return;
    998             return $walker->walk($wp_query->comments_by_type[$type], $depth, $r);
     1017            $walker->paged_walk($wp_query->comments_by_type[$type], $depth, $page, $per_page, $r);
     1018            $wp_query->max_num_comment_pages = $walker->max_pages;
     1019            return;
    9991020        }
    1000         $walker->walk($wp_query->comments, $depth, $r);
     1021        $walker->paged_walk($wp_query->comments, $depth, $page, $per_page, $r);
     1022        $wp_query->max_num_comment_pages = $walker->max_pages;
    10011023    } else {
    10021024        if ( empty($comments) )
    10031025            return;
    10041026        if ( 'all' != $type ) {
    1005             $comments_by_type = separate_comments($comments);
     1027            $comments_by_type = &separate_comments($comments);
    10061028            if ( empty($comments_by_type[$type]) )
    10071029                return;
    1008             return $walker->walk($comments_by_type[$type], $depth, $r);
     1030            $walker->paged_walk($comments_by_type[$type], $depth, $page, $per_page, $r);
     1031            $wp_query->max_num_comment_pages = $walker->max_pages;
     1032            return;
    10091033        }
    1010         $walker->walk($comments, $depth, $r);
     1034        $walker->paged_walk($comments, $depth, $page, $per_page, $r);
     1035        $wp_query->max_num_comment_pages = $walker->max_pages;
    10111036    }
    10121037}
  • trunk/wp-includes/formatting.php

    r8958 r8961  
    18211821        case 'default_email_category':
    18221822        case 'default_link_category':
     1823        case 'close_comments_days_old':
     1824        case 'comments_per_page':
     1825        case 'thread_comments_depth':
    18231826            $value = abs((int) $value);
    18241827            break;
  • trunk/wp-includes/link-template.php

    r8896 r8961  
    794794}
    795795
     796function get_comments_pagenum_link($pagenum = 1) {
     797    global $wp_rewrite;
     798
     799    $pagenum = (int) $pagenum;
     800
     801    $request = remove_query_arg( 'cpage' );
     802
     803    $home_root = parse_url(get_option('home'));
     804    $home_root = ( isset($home_root['path']) ) ? $home_root['path'] : '';
     805    $home_root = preg_quote( trailingslashit( $home_root ), '|' );
     806
     807    $request = preg_replace('|^'. $home_root . '|', '', $request);
     808    $request = preg_replace('|^/+|', '', $request);
     809
     810    $base = trailingslashit( get_bloginfo( 'home' ) );
     811
     812    if ( $pagenum > 1 ) {
     813        $result = add_query_arg( 'cpage', $pagenum, $base . $request );
     814    } else {
     815        $result = $base . $request;
     816    }
     817
     818    $result = apply_filters('get_comments_pagenum_link', $result);
     819
     820    return $result;
     821}
     822
     823function next_comments_link($label='', $max_page = 0) {
     824    global $wp_query;
     825
     826    if ( !is_singular() )
     827        return;
     828
     829    $page = get_query_var('cpage');
     830   
     831    if ( !$page )
     832        $page = 1;
     833
     834    if ( !$page )
     835        $page = 1;
     836
     837    $nextpage = intval($page) + 1;
     838
     839    if ( empty($max_page) )
     840        $max_page = $wp_query->max_num_comment_pages;
     841
     842    if ( $nextpage > $max_page )
     843        return;
     844
     845    if ( empty($label) )
     846        $label = __('&raquo; Newer Comments');
     847
     848    echo '<a href="' . clean_url(get_comments_pagenum_link($nextpage));
     849    $attr = apply_filters( 'next_comments_link_attributes', '' );
     850    echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
     851}
     852
     853function previous_comments_link($label='') {
     854    global $wp_query;
     855
     856    if ( !is_singular() )
     857        return;
     858
     859    $page = get_query_var('cpage');
     860
     861    if ( $page <= 1 )
     862        return;
     863
     864    $nextpage = intval($page) - 1;
     865
     866    if ( empty($label) )
     867        $label = __('&laquo; Older Comments');
     868
     869    echo '<a href="' . clean_url(get_comments_pagenum_link($nextpage));
     870    $attr = apply_filters( 'previous_comments_link_attributes', '' );
     871    echo "\" $attr>". preg_replace('/&([^#])(?![a-z]{1,8};)/', '&#038;$1', $label) .'</a>';
     872}
     873
    796874function get_shortcut_link() {
    797875    $link = "javascript:
  • trunk/wp-includes/query.php

    r8922 r8961  
    843843     */
    844844    var $max_num_pages = 0;
     845
     846    /**
     847     * The amount of comment pages.
     848     *
     849     * @since 2.7.0
     850     * @access public
     851     * @var int
     852     */
     853    var $max_num_comment_pages = 0;
    845854
    846855    /**
     
    16131622            $q['posts_per_page'] = 1;
    16141623
     1624        if ( !isset($q['comments_per_page']) || $q['comments_per_page'] == 0 )
     1625            $q['comments_per_page'] = get_option('comments_per_page');
     1626
    16151627        if ( $this->is_home && (empty($this->query) || $q['preview'] == 'true') && ( 'page' == get_option('show_on_front') ) && get_option('page_on_front') ) {
    16161628            $this->is_page = true;
Note: See TracChangeset for help on using the changeset viewer.