<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[34957] trunk/src/wp-includes/class-wp-rewrite.php: Docs: Add saner formatting and make readability improvements to a variety of inline comments in `WP_Rewrite` and `WP_Rewrite::generate_rewrite_rules()`.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/34957">34957</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/34957","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>DrewAPicture</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-10-08 21:17:14 +0000 (Thu, 08 Oct 2015)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Docs: Add saner formatting and make readability improvements to a variety of inline comments in `WP_Rewrite` and `WP_Rewrite::generate_rewrite_rules()`.

See <a href="https://core.trac.wordpress.org/ticket/34218">#34218</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswprewritephp">trunk/src/wp-includes/class-wp-rewrite.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswprewritephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-rewrite.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-rewrite.php        2015-10-08 21:05:50 UTC (rev 34956)
+++ trunk/src/wp-includes/class-wp-rewrite.php  2015-10-08 21:17:14 UTC (rev 34957)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -456,15 +456,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">        public function page_uri_index() {
</span><span class="cx" style="display: block; padding: 0 10px">                global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //get pages in order of hierarchy, i.e. children after parents
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Get pages in order of hierarchy, i.e. children after parents.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $pages = $wpdb->get_results("SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'page' AND post_status != 'auto-draft'");
</span><span class="cx" style="display: block; padding: 0 10px">                $posts = get_page_hierarchy( $pages );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // If we have no pages get out quick
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // If we have no pages get out quick.
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( !$posts )
</span><span class="cx" style="display: block; padding: 0 10px">                        return array( array(), array() );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //now reverse it, because we need parents after children for rewrite rules to work properly
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Now reverse it, because we need parents after children for rewrite rules to work properly.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $posts = array_reverse($posts, true);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $page_uris = array();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -496,7 +496,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array Page rewrite rules.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function page_rewrite_rules() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // the extra .? at the beginning prevents clashes with other regular expressions in the rules array
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // The extra .? at the beginning prevents clashes with other regular expressions in the rules array.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->add_rewrite_tag( '%pagename%', '(.?.+?)', 'pagename=' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return $this->generate_rewrite_rules( $this->get_page_permastruct(), EP_PAGES, true, true, false, false );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -547,8 +547,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( empty($date_endian) )
</span><span class="cx" style="display: block; padding: 0 10px">                        $date_endian = '%year%/%monthnum%/%day%';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                // Do not allow the date tags and %post_id% to overlap in the permalink
-               // structure. If they do, move the date tags to $front/date/.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /*
+                * Do not allow the date tags and %post_id% to overlap in the permalink
+                * structure. If they do, move the date tags to $front/date/.
+                */
</ins><span class="cx" style="display: block; padding: 0 10px">                 $front = $this->front;
</span><span class="cx" style="display: block; padding: 0 10px">                preg_match_all('/%.+?%/', $this->permalink_structure, $tokens);
</span><span class="cx" style="display: block; padding: 0 10px">                $tok_index = 1;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -859,37 +861,41 @@
</span><span class="cx" style="display: block; padding: 0 10px">         * @return array Rewrite rule list.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        public function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE, $paged = true, $feed = true, $forcomments = false, $walk_dirs = true, $endpoints = true) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Build a regex to match the feed section of URLs, something like (feed|atom|rss|rss2)/?
</ins><span class="cx" style="display: block; padding: 0 10px">                 $feedregex2 = '';
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( (array) $this->feeds as $feed_name)
</span><span class="cx" style="display: block; padding: 0 10px">                        $feedregex2 .= $feed_name . '|';
</span><span class="cx" style="display: block; padding: 0 10px">                $feedregex2 = '(' . trim($feedregex2, '|') . ')/?$';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //$feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom
-               //and <permalink>/atom are both possible
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /*
+                * $feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom
+                * and <permalink>/atom are both possible
+                */
</ins><span class="cx" style="display: block; padding: 0 10px">                 $feedregex = $this->feed_base . '/' . $feedregex2;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //build a regex to match the trackback and page/xx parts of URLs
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Build a regex to match the trackback and page/xx parts of URLs.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $trackbackregex = 'trackback/?$';
</span><span class="cx" style="display: block; padding: 0 10px">                $pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';
</span><span class="cx" style="display: block; padding: 0 10px">                $commentregex = $this->comments_pagination_base . '-([0-9]{1,})/?$';
</span><span class="cx" style="display: block; padding: 0 10px">                $embedregex = 'embed/?$';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //build up an array of endpoint regexes to append => queries to append
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Build up an array of endpoint regexes to append => queries to append.
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( $endpoints ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $ep_query_append = array ();
</span><span class="cx" style="display: block; padding: 0 10px">                        foreach ( (array) $this->endpoints as $endpoint) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                //match everything after the endpoint name, but allow for nothing to appear there
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         // Match everything after the endpoint name, but allow for nothing to appear there.
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $epmatch = $endpoint[1] . '(/(.*))?/?$';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                //this will be appended on to the rest of the query for each dir
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               // This will be appended on to the rest of the query for each dir.
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $epquery = '&' . $endpoint[2] . '=';
</span><span class="cx" style="display: block; padding: 0 10px">                                $ep_query_append[$epmatch] = array ( $endpoint[0], $epquery );
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //get everything up to the first rewrite tag
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Get everything up to the first rewrite tag.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //build an array of the tags (note that said array ends up being in $tokens[0])
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+               // Build an array of the tags (note that said array ends up being in $tokens[0]).
</ins><span class="cx" style="display: block; padding: 0 10px">                 preg_match_all('/%.+?%/', $permalink_structure, $tokens);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $num_tokens = count($tokens[0]);
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -899,8 +905,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $trackbackindex = $index;
</span><span class="cx" style="display: block; padding: 0 10px">                $embedindex = $index;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //build a list from the rewritecode and queryreplace arrays, that will look something like
-               //tagname=$matches[i] where i is the current $i
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /*
+                * Build a list from the rewritecode and queryreplace arrays, that will look something
+                * like tagname=$matches[i] where i is the current $i.
+                */
</ins><span class="cx" style="display: block; padding: 0 10px">                 $queries = array();
</span><span class="cx" style="display: block; padding: 0 10px">                for ( $i = 0; $i < $num_tokens; ++$i ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( 0 < $i )
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -912,39 +920,41 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $queries[$i] .= $query_token;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //get the structure, minus any cruft (stuff that isn't tags) at the front
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Get the structure, minus any cruft (stuff that isn't tags) at the front.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $structure = $permalink_structure;
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $front != '/' )
</span><span class="cx" style="display: block; padding: 0 10px">                        $structure = str_replace($front, '', $structure);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //create a list of dirs to walk over, making rewrite rules for each level
-               //so for example, a $structure of /%year%/%monthnum%/%postname% would create
-               //rewrite rules for /%year%/, /%year%/%monthnum%/ and /%year%/%monthnum%/%postname%
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /*
+                * Create a list of dirs to walk over, making rewrite rules for each level
+                * so for example, a $structure of /%year%/%monthnum%/%postname% would create
+                * rewrite rules for /%year%/, /%year%/%monthnum%/ and /%year%/%monthnum%/%postname%
+                */
</ins><span class="cx" style="display: block; padding: 0 10px">                 $structure = trim($structure, '/');
</span><span class="cx" style="display: block; padding: 0 10px">                $dirs = $walk_dirs ? explode('/', $structure) : array( $structure );
</span><span class="cx" style="display: block; padding: 0 10px">                $num_dirs = count($dirs);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //strip slashes from the front of $front
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Strip slashes from the front of $front.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $front = preg_replace('|^/+|', '', $front);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                //the main workhorse loop
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // The main workhorse loop.
</ins><span class="cx" style="display: block; padding: 0 10px">                 $post_rewrite = array();
</span><span class="cx" style="display: block; padding: 0 10px">                $struct = $front;
</span><span class="cx" style="display: block; padding: 0 10px">                for ( $j = 0; $j < $num_dirs; ++$j ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //get the struct for this dir, and trim slashes off the front
-                       $struct .= $dirs[$j] . '/'; //accumulate. see comment near explode('/', $structure) above
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Get the struct for this dir, and trim slashes off the front.
+                       $struct .= $dirs[$j] . '/'; // Accumulate. see comment near explode('/', $structure) above.
</ins><span class="cx" style="display: block; padding: 0 10px">                         $struct = ltrim($struct, '/');
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //replace tags with regexes
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Replace tags with regexes.
</ins><span class="cx" style="display: block; padding: 0 10px">                         $match = str_replace($this->rewritecode, $this->rewritereplace, $struct);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //make a list of tags, and store how many there are in $num_toks
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Make a list of tags, and store how many there are in $num_toks.
</ins><span class="cx" style="display: block; padding: 0 10px">                         $num_toks = preg_match_all('/%.+?%/', $struct, $toks);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //get the 'tagname=$matches[i]'
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Get the 'tagname=$matches[i]'.
</ins><span class="cx" style="display: block; padding: 0 10px">                         $query = ( ! empty( $num_toks ) && isset( $queries[$num_toks - 1] ) ) ? $queries[$num_toks - 1] : '';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //set up $ep_mask_specific which is used to match more specific URL types
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Set up $ep_mask_specific which is used to match more specific URL types.
</ins><span class="cx" style="display: block; padding: 0 10px">                         switch ( $dirs[$j] ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                case '%year%':
</span><span class="cx" style="display: block; padding: 0 10px">                                        $ep_mask_specific = EP_YEAR;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -959,65 +969,74 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        $ep_mask_specific = EP_NONE;
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //create query for /page/xx
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Create query for /page/xx.
</ins><span class="cx" style="display: block; padding: 0 10px">                         $pagematch = $match . $pageregex;
</span><span class="cx" style="display: block; padding: 0 10px">                        $pagequery = $index . '?' . $query . '&paged=' . $this->preg_index($num_toks + 1);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //create query for /comment-page-xx
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Create query for /comment-page-xx.
</ins><span class="cx" style="display: block; padding: 0 10px">                         $commentmatch = $match . $commentregex;
</span><span class="cx" style="display: block; padding: 0 10px">                        $commentquery = $index . '?' . $query . '&cpage=' . $this->preg_index($num_toks + 1);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( get_option('page_on_front') ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                //create query for Root /comment-page-xx
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         // Create query for Root /comment-page-xx.
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $rootcommentmatch = $match . $commentregex;
</span><span class="cx" style="display: block; padding: 0 10px">                                $rootcommentquery = $index . '?' . $query . '&page_id=' . get_option('page_on_front') . '&cpage=' . $this->preg_index($num_toks + 1);
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //create query for /feed/(feed|atom|rss|rss2|rdf)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Create query for /feed/(feed|atom|rss|rss2|rdf).
</ins><span class="cx" style="display: block; padding: 0 10px">                         $feedmatch = $match . $feedregex;
</span><span class="cx" style="display: block; padding: 0 10px">                        $feedquery = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Create query for /(feed|atom|rss|rss2|rdf) (see comment near creation of $feedregex).
</ins><span class="cx" style="display: block; padding: 0 10px">                         $feedmatch2 = $match . $feedregex2;
</span><span class="cx" style="display: block; padding: 0 10px">                        $feedquery2 = $feedindex . '?' . $query . '&feed=' . $this->preg_index($num_toks + 1);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //if asked to, turn the feed queries into comment feed ones
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // If asked to, turn the feed queries into comment feed ones.
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( $forcomments ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $feedquery .= '&withcomments=1';
</span><span class="cx" style="display: block; padding: 0 10px">                                $feedquery2 .= '&withcomments=1';
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //start creating the array of rewrites for this dir
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Start creating the array of rewrites for this dir.
</ins><span class="cx" style="display: block; padding: 0 10px">                         $rewrite = array();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( $feed ) //...adding on /feed/ regexes => queries
-                               $rewrite = array($feedmatch => $feedquery, $feedmatch2 => $feedquery2);
-                       if ( $paged ) //...and /page/xx ones
-                               $rewrite = array_merge($rewrite, array($pagematch => $pagequery));
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //only on pages with comments add ../comment-page-xx/
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // ...adding on /feed/ regexes => queries
+                       if ( $feed ) {
+                               $rewrite = array( $feedmatch => $feedquery, $feedmatch2 => $feedquery2 );
+                       }
+
+                       //...and /page/xx ones
+                       if ( $paged ) {
+                               $rewrite = array_merge( $rewrite, array( $pagematch => $pagequery ) );
+                       }
+
+                       // Only on pages with comments add ../comment-page-xx/.
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( EP_PAGES & $ep_mask || EP_PERMALINK & $ep_mask ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $rewrite = array_merge($rewrite, array($commentmatch => $commentquery));
</span><span class="cx" style="display: block; padding: 0 10px">                        } elseif ( EP_ROOT & $ep_mask && get_option('page_on_front') ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $rewrite = array_merge($rewrite, array($rootcommentmatch => $rootcommentquery));
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //do endpoints
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       // Do endpoints.
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( $endpoints ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                foreach ( (array) $ep_query_append as $regex => $ep) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //add the endpoints on if the mask fits
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Add the endpoints on if the mask fits.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         if ( $ep[0] & $ep_mask || $ep[0] & $ep_mask_specific )
</span><span class="cx" style="display: block; padding: 0 10px">                                                $rewrite[$match . $regex] = $index . '?' . $query . $ep[1] . $this->preg_index($num_toks + 2);
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px">                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        //if we've got some tags in this dir
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // If we've got some tags in this dir.
</ins><span class="cx" style="display: block; padding: 0 10px">                         if ( $num_toks ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $post = false;
</span><span class="cx" style="display: block; padding: 0 10px">                                $page = false;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                //check to see if this dir is permalink-level: i.e. the structure specifies an
-                               //individual post. Do this by checking it contains at least one of 1) post name,
-                               //2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
-                               //minute all present). Set these flags now as we need them for the endpoints.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         /*
+                                * Check to see if this dir is permalink-level: i.e. the structure specifies an
+                                * individual post. Do this by checking it contains at least one of 1) post name,
+                                * 2) post ID, 3) page name, 4) timestamp (year, month, day, hour, second and
+                                * minute all present). Set these flags now as we need them for the endpoints.
+                                */
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( strpos($struct, '%postname%') !== false
</span><span class="cx" style="display: block; padding: 0 10px">                                                || strpos($struct, '%post_id%') !== false
</span><span class="cx" style="display: block; padding: 0 10px">                                                || strpos($struct, '%pagename%') !== false
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1033,15 +1052,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        foreach ( get_post_types( array('_builtin' => false ) ) as $ptype ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                if ( strpos($struct, "%$ptype%") !== false ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $post = true;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                        $page = is_post_type_hierarchical( $ptype ); // This is for page style attachment url's
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                                                       // This is for page style attachment URLs.
+                                                       $page = is_post_type_hierarchical( $ptype );
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         break;
</span><span class="cx" style="display: block; padding: 0 10px">                                                }
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                //if we're creating rules for a permalink, do all the endpoints like attachments etc
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         // If creating rules for a permalink, do all the endpoints like attachments etc.
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( $post ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //create query and regex for trackback
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Create query and regex for trackback.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $trackbackmatch = $match . $trackbackregex;
</span><span class="cx" style="display: block; padding: 0 10px">                                        $trackbackquery = $trackbackindex . '?' . $query . '&tb=1';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1049,37 +1070,59 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        $embedmatch = $match . $embedregex;
</span><span class="cx" style="display: block; padding: 0 10px">                                        $embedquery = $embedindex . '?' . $query . '&embed=true';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //trim slashes from the end of the regex for this dir
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Trim slashes from the end of the regex for this dir.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $match = rtrim($match, '/');
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //get rid of brackets
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Get rid of brackets.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $submatchbase = str_replace( array('(', ')'), '', $match);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //add a rule for at attachments, which take the form of <permalink>/some-text
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Add a rule for at attachments, which take the form of <permalink>/some-text.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $sub1 = $submatchbase . '/([^/]+)/';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        $sub1tb = $sub1 . $trackbackregex; //add trackback regex <permalink>/trackback/...
-                                       $sub1feed = $sub1 . $feedregex; //and <permalink>/feed/(atom|...)
-                                       $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...)
-                                       $sub1comment = $sub1 . $commentregex; //and <permalink>/comment-page-xx
-                                       $sub1embed = $sub1 . $embedregex; //and <permalink>/embed/...
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //add another rule to match attachments in the explicit form:
-                                       //<permalink>/attachment/some-text
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Add trackback regex <permalink>/trackback/...
+                                       $sub1tb = $sub1 . $trackbackregex;
+
+                                       // And <permalink>/feed/(atom|...)
+                                       $sub1feed = $sub1 . $feedregex;
+
+                                       // And <permalink>/(feed|atom...)
+                                       $sub1feed2 = $sub1 . $feedregex2;
+
+                                       // And <permalink>/comment-page-xx
+                                       $sub1comment = $sub1 . $commentregex;
+
+                                       // And <permalink>/embed/...
+                                       $sub1embed = $sub1 . $embedregex;
+
+                                       /*
+                                        * Add another rule to match attachments in the explicit form:
+                                        * <permalink>/attachment/some-text
+                                        */
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $sub2 = $submatchbase . '/attachment/([^/]+)/';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        $sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback
-                                       $sub2feed = $sub2 . $feedregex;    //feeds, <permalink>/attachment/feed/(atom|...)
-                                       $sub2feed2 = $sub2 . $feedregex2;  //and feeds again on to this <permalink>/attachment/(feed|atom...)
-                                       $sub2comment = $sub2 . $commentregex; //and <permalink>/comment-page-xx
-                                       $sub2embed = $sub2 . $embedregex; //and <permalink>/embed/...
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //create queries for these extra tag-ons we've just dealt with
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // And add trackbacks <permalink>/attachment/trackback.
+                                       $sub2tb = $sub2 . $trackbackregex;
+
+                                       // Feeds, <permalink>/attachment/feed/(atom|...)
+                                       $sub2feed = $sub2 . $feedregex;
+
+                                       // And feeds again on to this <permalink>/attachment/(feed|atom...)
+                                       $sub2feed2 = $sub2 . $feedregex2;
+
+                                       // And <permalink>/comment-page-xx
+                                       $sub2comment = $sub2 . $commentregex;
+
+                                       // And <permalink>/embed/...
+                                       $sub2embed = $sub2 . $embedregex;
+
+                                       // Create queries for these extra tag-ons we've just dealt with.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $subquery = $index . '?attachment=' . $this->preg_index(1);
</span><span class="cx" style="display: block; padding: 0 10px">                                        $subtbquery = $subquery . '&tb=1';
</span><span class="cx" style="display: block; padding: 0 10px">                                        $subfeedquery = $subquery . '&feed=' . $this->preg_index(2);
</span><span class="cx" style="display: block; padding: 0 10px">                                        $subcommentquery = $subquery . '&cpage=' . $this->preg_index(2);
</span><span class="cx" style="display: block; padding: 0 10px">                                        $subembedquery = $subquery . '&embed=true';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //do endpoints for attachments
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Do endpoints for attachments.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         if ( !empty($endpoints) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                foreach ( (array) $ep_query_append as $regex => $ep ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                        if ( $ep[0] & EP_ATTACHMENT ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1089,39 +1132,47 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                }
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //now we've finished with endpoints, finish off the $sub1 and $sub2 matches
-                                       //add a ? as we don't have to match that last slash, and finally a $ so we
-                                       //match to the end of the URL
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 /*
+                                        * Now we've finished with endpoints, finish off the $sub1 and $sub2 matches
+                                        * add a ? as we don't have to match that last slash, and finally a $ so we
+                                        * match to the end of the URL
+                                        */
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $sub1 .= '?$';
</span><span class="cx" style="display: block; padding: 0 10px">                                        $sub2 .= '?$';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        // Post pagination, e.g. <permalink>/2/
-                                       // Previously: '(/[0-9]+)?/?$', which produced '/2' for page.
-                                       // When cast to int, returned 0.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 /*
+                                        * Post pagination, e.g. <permalink>/2/
+                                        * Previously: '(/[0-9]+)?/?$', which produced '/2' for page.
+                                        * When cast to int, returned 0.
+                                        */
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $match = $match . '(?:/([0-9]+))?/?$';
</span><span class="cx" style="display: block; padding: 0 10px">                                        $query = $index . '?' . $query . '&page=' . $this->preg_index($num_toks + 1);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                } else { //not matching a permalink so this is a lot simpler
-                                       //close the match and finalise the query
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               // Not matching a permalink so this is a lot simpler.
+                               } else {
+                                       // Close the match and finalise the query.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $match .= '?$';
</span><span class="cx" style="display: block; padding: 0 10px">                                        $query = $index . '?' . $query;
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                //create the final array for this dir by joining the $rewrite array (which currently
-                               //only contains rules/queries for trackback, pages etc) to the main regex/query for
-                               //this dir
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         /*
+                                * Create the final array for this dir by joining the $rewrite array (which currently
+                                * only contains rules/queries for trackback, pages etc) to the main regex/query for
+                                * this dir
+                                */
</ins><span class="cx" style="display: block; padding: 0 10px">                                 $rewrite = array_merge($rewrite, array($match => $query));
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                //if we're matching a permalink, add those extras (attachments etc) on
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         // If we're matching a permalink, add those extras (attachments etc) on.
</ins><span class="cx" style="display: block; padding: 0 10px">                                 if ( $post ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //add trackback
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Add trackback.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $rewrite = array_merge(array($trackbackmatch => $trackbackquery), $rewrite);
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        // add embed
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Add embed.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         $rewrite = array_merge( array( $embedmatch => $embedquery ), $rewrite );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        //add regexes/queries for attachments, attachment trackbacks and so on
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // Add regexes/queries for attachments, attachment trackbacks and so on.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         if ( ! $page ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                //require <permalink>/attachment/stuff form for pages because of confusion with subpages
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         // Require <permalink>/attachment/stuff form for pages because of confusion with subpages.
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 $rewrite = array_merge( $rewrite, array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $sub1        => $subquery,
</span><span class="cx" style="display: block; padding: 0 10px">                                                        $sub1tb      => $subtbquery,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1134,11 +1185,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                        $rewrite = array_merge( array( $sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery, $sub2embed => $subembedquery ), $rewrite );
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        } //if($num_toks)
-                       //add the rules for this dir to the accumulating $post_rewrite
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 }
+                       // Add the rules for this dir to the accumulating $post_rewrite.
</ins><span class="cx" style="display: block; padding: 0 10px">                         $post_rewrite = array_merge($rewrite, $post_rewrite);
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                } //foreach ($dir)
-               return $post_rewrite; //the finished rules. phew!
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         }
+
+               // The finished rules. phew!
+               return $post_rewrite;
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span></span></pre>
</div>
</div>

</body>
</html>