From f275541cf6362ecf2731bb201e13ce170ce8bf30 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 23 Oct 2008 18:55:22 +0000 Subject: [PATCH] pretty permalinks for comment paging. Props Viper007Bind. fixes #7942 git-svn-id: http://svn.automattic.com/wordpress/trunk@9300 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 11 ++++++++--- wp-includes/link-template.php | 5 ++++- wp-includes/rewrite.php | 16 ++++++++++++++-- wp-includes/version.php | 4 ++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index aa788f9c5f..58acf379a3 100644 --- a/wp-includes/canonical.php +++ b/wp-includes/canonical.php @@ -123,14 +123,15 @@ function redirect_canonical($requested_url=null, $do_redirect=true) { } // paging and feeds - if ( get_query_var('paged') || is_feed() ) { + if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) { if ( !$redirect_url ) $redirect_url = $requested_url; $paged_redirect = @parse_url($redirect_url); - while ( preg_match( '#page/[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/feed(/[a-z0-9-]*?(/+)?)?$#', $paged_redirect['path'] ) ) { + while ( preg_match( '#page/[0-9]+?(/+)?$#', $paged_redirect['path'] ) || preg_match( '#/feed(/[a-z0-9-]*?(/+)?)?$#', $paged_redirect['path'] ) || preg_match( '#comment-page-[0-9]+/?$#', $paged_redirect['path'] ) ) { // Strip off paging and feed $paged_redirect['path'] = preg_replace('#/page/[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing paging $paged_redirect['path'] = preg_replace('#/feed(/[a-z0-9-]*?(/+)?)?$#', '/', $paged_redirect['path']); // strip off any existing feed + $paged_redirect['path'] = preg_replace('#comment-page-[0-9]+?(/+)?$#', '/', $paged_redirect['path']); // strip off any existing comment paging } $paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']); // strip off trailing /index.php/ @@ -148,10 +149,14 @@ function redirect_canonical($requested_url=null, $do_redirect=true) { if ( is_feed() ) { $paged_redirect['path'] = user_trailingslashit( trailingslashit( $paged_redirect['path'] ) . 'feed/' . ( ( 'rss2' == get_query_var('feed') || 'feed' == get_query_var('feed') ) ? '' : get_query_var('feed') ), 'feed' ); } + if ( get_query_var('cpage') > 1 ) { + $paged_redirect['path'] = user_trailingslashit( trailingslashit( $paged_redirect['path'] ) . 'comment-page-' . get_query_var('cpage'), 'commentpaged' ); + } $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; $redirect['path'] = $paged_redirect['path']; $redirect['query'] = remove_query_arg( 'paged', $redirect['query'] ); - $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); + $redirect['query'] = remove_query_arg( 'feed', $redirect['query'] ); + $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); } } diff --git a/wp-includes/link-template.php b/wp-includes/link-template.php index 9894db123d..1348145cdb 100644 --- a/wp-includes/link-template.php +++ b/wp-includes/link-template.php @@ -1242,7 +1242,7 @@ function previous_comments_link($label='') { * @return string Markup for pagination links. */ function paginate_comments_links($args = array()) { - global $wp_query; + global $wp_query, $wp_rewrite; if ( !is_singular() ) return; @@ -1259,6 +1259,9 @@ function paginate_comments_links($args = array()) { 'echo' => true, 'add_fragment' => '#comments' ); + if ( $wp_rewrite->using_permalinks() ) + $defaults['base'] = user_trailingslashit(get_permalink() . 'comment-page-%#%', 'commentpaged'); + $args = wp_parse_args( $args, $defaults ); $page_links = paginate_links( $args ); diff --git a/wp-includes/rewrite.php b/wp-includes/rewrite.php index 5f2f0c7919..c5c5c50d23 100644 --- a/wp-includes/rewrite.php +++ b/wp-includes/rewrite.php @@ -1259,6 +1259,7 @@ class WP_Rewrite { //build a regex to match the trackback and page/xx parts of URLs $trackbackregex = 'trackback/?$'; $pageregex = 'page/?([0-9]{1,})/?$'; + $commentregex = 'comment-page-([0-9]{1,})/?$'; //build up an array of endpoint regexes to append => queries to append if ($endpoints) { @@ -1339,6 +1340,10 @@ class WP_Rewrite { $pagematch = $match . $pageregex; $pagequery = $index . '?' . $query . '&paged=' . $this->preg_index($num_toks + 1); + //create query for /comment-page-xx + $commentmatch = $match . $commentregex; + $commentquery = $index . '?' . $query . '&cpage=' . $this->preg_index($num_toks + 1); + //create query for /feed/(feed|atom|rss|rss2|rdf) $feedmatch = $match . $feedregex; $feedquery = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1); @@ -1360,6 +1365,10 @@ class WP_Rewrite { if ($paged) //...and /page/xx ones $rewrite = array_merge($rewrite, array($pagematch => $pagequery)); + //only on pages with comments add ../comment-page-xx/ + if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask || EP_NONE & $ep_mask ) + $rewrite = array_merge($rewrite, array($commentmatch => $commentquery)); + //do endpoints if ($endpoints) { foreach ( (array) $ep_query_append as $regex => $ep) { @@ -1403,6 +1412,7 @@ class WP_Rewrite { $sub1tb = $sub1 . $trackbackregex; //add trackback regex /trackback/... $sub1feed = $sub1 . $feedregex; //and /feed/(atom|...) $sub1feed2 = $sub1 . $feedregex2; //and /(feed|atom...) + $sub1comment = $sub1 . $commentregex; //and /comment-page-xx //add an ? as we don't have to match that last slash, and finally a $ so we //match to the end of the URL @@ -1412,11 +1422,13 @@ class WP_Rewrite { $sub2tb = $sub2 . $trackbackregex; //and add trackbacks /attachment/trackback $sub2feed = $sub2 . $feedregex; //feeds, /attachment/feed/(atom|...) $sub2feed2 = $sub2 . $feedregex2; //and feeds again on to this /attachment/(feed|atom...) + $sub2comment = $sub2 . $commentregex; //and /comment-page-xx //create queries for these extra tag-ons we've just dealt with $subquery = $index . '?attachment=' . $this->preg_index(1); $subtbquery = $subquery . '&tb=1'; $subfeedquery = $subquery . '&feed=' . $this->preg_index(2); + $subcommentquery = $subquery . '&cpage=' . $this->preg_index(2); //do endpoints for attachments if ( !empty($endpoint) ) { foreach ( (array) $ep_query_append as $regex => $ep ) { @@ -1451,8 +1463,8 @@ class WP_Rewrite { //add regexes/queries for attachments, attachment trackbacks and so on if ( ! $page ) //require /attachment/stuff form for pages because of confusion with subpages - $rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery)); - $rewrite = array_merge(array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery), $rewrite); + $rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery, $sub1comment => $subcommentquery)); + $rewrite = array_merge(array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery), $rewrite); } } //if($num_toks) //add the rules for this dir to the accumulating $post_rewrite diff --git a/wp-includes/version.php b/wp-includes/version.php index f732bf96c9..187b7f4ed6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -8,13 +8,13 @@ * * @global string $wp_version */ -$wp_version = '2.7-almost-beta-9296'; +$wp_version = '2.7-almost-beta-9300'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * * @global int $wp_db_version */ -$wp_db_version = 9296; +$wp_db_version = 9300; ?>