Fix regression in r27416 -- {{REVISIONID}} was broken on save since a parsed copy...
authorBrion Vibber <brion@users.mediawiki.org>
Thu, 15 Nov 2007 02:54:28 +0000 (02:54 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Thu, 15 Nov 2007 02:54:28 +0000 (02:54 +0000)
The parser now sets a "vary-revision" flag on the ParserOutput when using {{REVISIONID}}; Article then reparses the page after insertion if and only if required.

RELEASE-NOTES
includes/Article.php
includes/Parser.php
includes/ParserOutput.php

index f082afd..ad2cf08 100644 (file)
@@ -20,10 +20,6 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 
 === Configuration changes in 1.12 ===
 
-=== Removed features in 1.12 ===
-* {{REVISIONID}} will no longer give the correct revision ID for current revision 
-  views. It will still work for history views. 
-
 === New features in 1.12 ===
 * (bug 10735) Add a warning for non-descriptive filenames at Special:Upload
 * Add {{filepath:}} parser function to get full path to an uploaded file,
index 7f23be4..76391af 100644 (file)
@@ -2425,18 +2425,19 @@ class Article {
         * Prepare text which is about to be saved.
         * Returns a stdclass with source, pst and output members
         */
-       function prepareTextForEdit( $text ) {
-               if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text ) {
+       function prepareTextForEdit( $text, $revid=null ) {
+               if ( $this->mPreparedEdit && $this->mPreparedEdit->newText == $text && $this->mPreparedEdit->revid == $revid) {
                        // Already prepared
                        return $this->mPreparedEdit;
                }
                global $wgParser;
                $edit = (object)array();
+               $edit->revid = $revid;
                $edit->newText = $text;
                $edit->pst = $this->preSaveTransform( $text );
                $options = new ParserOptions;
                $options->setTidy( true );
-               $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true );
+               $edit->output = $wgParser->parse( $edit->pst, $this->mTitle, $options, true, true, $revid );
                $edit->oldText = $this->getContent();
                $this->mPreparedEdit = $edit;
                return $edit;
@@ -2462,9 +2463,11 @@ class Article {
 
                # Parse the text
                # Be careful not to double-PST: $text is usually already PST-ed once
-               if ( !$this->mPreparedEdit ) {
-                       $editInfo = $this->prepareTextForEdit( $text );
+               if ( !$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag( 'vary-revision' ) ) {
+                       wfDebug( __METHOD__ . ": No prepared edit or vary-revision is set...\n" );
+                       $editInfo = $this->prepareTextForEdit( $text, $newid );
                } else {
+                       wfDebug( __METHOD__ . ": No vary-revision, using prepared edit...\n" );
                        $editInfo = $this->mPreparedEdit;
                }
 
index 3f6a3c6..0ad8b82 100644 (file)
@@ -2528,6 +2528,10 @@ class Parser
                                $subjPage = $this->mTitle->getSubjectPage();
                                return $subjPage->getPrefixedUrl();
                        case 'revisionid':
+                               // Let the edit saving system know we should parse the page
+                               // *after* a revision ID has been assigned.
+                               $this->mOutput->setFlag( 'vary-revision' );
+                               wfDebug( __METHOD__ . ": {{REVISIONID}} used, setting vary-revision...\n" );
                                return $this->mRevisionId;
                        case 'revisionday':
                                return intval( substr( $this->getRevisionTimestamp(), 6, 2 ) );
index d4daf1d..5b79593 100644 (file)
@@ -165,6 +165,17 @@ class ParserOutput
                return $this->displayTitle;
        }
        
+       /**
+        * Fairly generic flag setter thingy.
+        */
+       public function setFlag( $flag ) {
+               $this->mFlags[$flag] = true;
+       }
+       
+       public function getFlag( $flag ) {
+               return isset( $this->mFlags[$flag] );
+       }
+       
 }