* (bug 12553) Fixed invalid XHTML in edit conflict screen
[lhc/web/wiklou.git] / includes / Parser.php
index a14cace..ea02a6e 100644 (file)
@@ -2435,14 +2435,34 @@ class Parser
                                wfDebug( __METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n" );
                                return $this->mRevisionId;
                        case 'revisionday':
+                               // Let the edit saving system know we should parse the page
+                               // *after* a revision ID has been assigned. This is for null edits.
+                               $this->mOutput->setFlag( 'vary-revision' );
+                               wfDebug( __METHOD__ . ": {{REVISIONDAY}} used, setting vary-revision...\n" );
                                return intval( substr( $this->getRevisionTimestamp(), 6, 2 ) );
                        case 'revisionday2':
+                               // Let the edit saving system know we should parse the page
+                               // *after* a revision ID has been assigned. This is for null edits.
+                               $this->mOutput->setFlag( 'vary-revision' );
+                               wfDebug( __METHOD__ . ": {{REVISIONDAY2}} used, setting vary-revision...\n" );
                                return substr( $this->getRevisionTimestamp(), 6, 2 );
                        case 'revisionmonth':
+                               // Let the edit saving system know we should parse the page
+                               // *after* a revision ID has been assigned. This is for null edits.
+                               $this->mOutput->setFlag( 'vary-revision' );
+                               wfDebug( __METHOD__ . ": {{REVISIONMONTH}} used, setting vary-revision...\n" );
                                return intval( substr( $this->getRevisionTimestamp(), 4, 2 ) );
                        case 'revisionyear':
+                               // Let the edit saving system know we should parse the page
+                               // *after* a revision ID has been assigned. This is for null edits.
+                               $this->mOutput->setFlag( 'vary-revision' );
+                               wfDebug( __METHOD__ . ": {{REVISIONYEAR}} used, setting vary-revision...\n" );
                                return substr( $this->getRevisionTimestamp(), 0, 4 );
                        case 'revisiontimestamp':
+                               // Let the edit saving system know we should parse the page
+                               // *after* a revision ID has been assigned. This is for null edits.
+                               $this->mOutput->setFlag( 'vary-revision' );
+                               wfDebug( __METHOD__ . ": {{REVISIONTIMESTAMP}} used, setting vary-revision...\n" );
                                return $this->getRevisionTimestamp();
                        case 'namespace':
                                return str_replace('_',' ',$wgContLang->getNsText( $this->mTitle->getNamespace() ) );
@@ -2757,7 +2777,7 @@ class Parser
                                                $i = strlen( $text );
                                        } else {
                                                // Search backwards for leading whitespace
-                                               $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i - 1 ) ) : 0;
+                                               $wsStart = $i ? ( $i - strspn( $revText, ' ', strlen( $text ) - $i ) ) : 0;
                                                // Search forwards for trailing whitespace
                                                // $wsEnd will be the position of the last space
                                                $wsEnd = $endPos + 2 + strspn( $text, ' ', $endPos + 3 );
@@ -2767,11 +2787,18 @@ class Parser
                                                {
                                                        $startPos = $wsStart;
                                                        $endPos = $wsEnd + 1;
+                                                       // Remove leading whitespace from the end of the accumulator
+                                                       // Sanity check first though
+                                                       $wsLength = $i - $wsStart;
+                                                       if ( $wsLength > 0 && substr( $accum, -$wsLength ) === str_repeat( ' ', $wsLength ) ) {
+                                                               $accum = substr( $accum, 0, -$wsLength );
+                                                       }
                                                } else {
                                                        // No line to eat, just take the comment itself
                                                        $startPos = $i;
                                                        $endPos += 2;
                                                }
+
                                                $inner = substr( $text, $startPos, $endPos - $startPos + 1 );
                                                $accum .= '<comment>' . htmlspecialchars( $inner ) . '</comment>';
                                                $i = $endPos + 1;
@@ -5405,7 +5432,7 @@ class PPFrame {
                        } elseif ( $root->nodeName == 'comment' ) {
                                # HTML-style comment
                                if ( $this->parser->ot['html'] 
-                                       || ( $this->parser->ot['pre'] && $this->mOptions->getRemoveComments() ) 
+                                       || ( $this->parser->ot['pre'] && $this->parser->mOptions->getRemoveComments() ) 
                                        || ( $flags & self::STRIP_COMMENTS ) ) 
                                {
                                        $s = '';