WordPress.org

Make WordPress Core

Ticket #7927: 7927.4.patch

File 7927.4.patch, 13.1 KB (added by Viper007Bond, 10 years ago)

Fix bugs and sorting (see below)

  • wp-admin/includes/schema.php

     
    288288        add_option('image_default_align', '');
    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
    293299        $unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file', 'use_preview', 'use_htmltrans', 'smilies_directory', 'fileupload_allowedusers', 'use_phoneemail', 'default_post_status', 'default_post_category', 'archive_mode', 'time_difference', 'links_minadminlevel', 'links_use_adminlevels', 'links_rating_type', 'links_rating_char', 'links_rating_ignore_zero', 'links_rating_single_image', 'links_rating_image0', 'links_rating_image1', 'links_rating_image2', 'links_rating_image3', 'links_rating_image4', 'links_rating_image5', 'links_rating_image6', 'links_rating_image7', 'links_rating_image8', 'links_rating_image9', 'weblogs_cacheminutes', 'comment_allowed_tags', 'search_engine_friendly_urls', 'default_geourl_lat', 'default_geourl_lon', 'use_default_geourl', 'weblogs_xml_url', 'new_users_can_blog', '_wpnonce', '_wp_http_referer', 'Update', 'action', 'rich_editing', 'autosave_interval', 'deactivated_plugins');
  • wp-admin/options-discussion.php

     
    4343<input name="default_comment_status" type="checkbox" id="default_comment_status" value="open" <?php checked('open', get_option('default_comment_status')); ?> />
    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">
    5359<input name="thread_comments" type="checkbox" id="thread_comments" value="1" <?php checked('1', get_option('thread_comments')); ?> />
     
    6874?><br />
    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" />') ?>
     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?>
    7288<br />
    73 <small><em><?php echo '(' . __('These settings may be overridden for individual articles.') . ')'; ?></em></small>
     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 .= '>' . __('oldest') . '</option><option value="desc"';
     94if ( 'desc' == get_option('comment_order') ) $comment_order .= ' selected="selected"';
     95$comment_order .= '>' . __('newest') . '</option></select>';
     96
     97printf( __('Comments should be displayed with the %s comments on top'), $comment_order );
     98
     99?></label>
    74100</fieldset></td>
    75101</tr>
    76102<tr valign="top">
  • wp-admin/options.php

     
    2323
    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' ),
    2929        'privacy' => array( 'blog_public' ),
  • wp-includes/classes.php

     
    985985
    986986                // flat display
    987987                if ( -1 == $max_depth ) {
     988                        if ( !empty($args[0]['reverse_top_level']) )
     989                                $elements = array_reverse( $elements );
     990
    988991                        $empty_array = array();
    989992                        foreach ( $elements as $e ) {
    990993                                $count++;
     
    10171020                else
    10181021                        $end = $total_top;
    10191022
    1020                 foreach( $top_level_elements as $e ){
     1023                if ( !empty($args[0]['reverse_top_level']) ) {
     1024                        $top_level_elements = array_reverse( $top_level_elements );
     1025                        $oldstart = $start;
     1026                        $start = $total_top - $end;
     1027                        $end = $total_top - $oldstart;
     1028                }
     1029                if ( !empty($args[0]['reverse_children']) ) {
     1030                        foreach ( $children_elements as $parent => $children )
     1031                                $children_elements[$parent] = array_reverse( $children );
     1032                }
     1033
     1034                foreach ( $top_level_elements as $e ) {
    10211035                        $count++;
    10221036
    10231037                        //for the last page, need to unset earlier children in order to keep track of orphans
  • wp-includes/comment-template.php

     
    762762                $comments_by_type = &$wp_query->comments_by_type;
    763763        }
    764764
     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() );
     767
    765768        define('COMMENTS_TEMPLATE', true);
    766769
    767770        $include = apply_filters('comments_template', STYLESHEETPATH . $file );
     
    11221125 * @since 2.7.0
    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 ) {
    11291132        global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt;
     
    11321135        $comment_depth = 1;
    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 );
    11381141
     
    11421145        if ( empty($r['per_page']) ) {
    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
    11511150        if ( '' === $r['depth'] ) {
     
    11551154                        $r['depth'] = -1;
    11561155        }
    11571156
     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;
     1173
    11581174        extract( $r, EXTR_SKIP );
    11591175
    11601176        if ( empty($walker) )
  • wp-includes/comment.php

     
    481481}
    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 )
     497                $comments = $wp_query->comments;
     498
     499        if ( !$comments )
     500                return 0;
     501
     502        if ( !$per_page )
     503                $per_page = get_query_var('comments_per_page');
     504
     505        if ( !$threaded )
     506                $threaded = get_option('thread_comments');
     507
     508        if ( $threaded ) {
     509                $walker = new Walker_Comment;
     510                $count = ceil( $walker->get_number_of_root_elements( $comments ) / $per_page );
     511        } else {
     512                $count = ceil( count( $comments ) / $per_page );
     513        }
     514
     515        return $count;
     516}
     517
     518/**
    484519 * Does comment contain blacklisted characters or words.
    485520 *
    486521 * @since 1.5.0
  • wp-includes/link-template.php

     
    11351135 * @param int $pagenum Optional. Page number.
    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
    11411141        $pagenum = (int) $pagenum;
     
    11511151
    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';
    11611163
     
    11941196        if ( empty($label) )
    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>';
    12001202}