* (bug 3979) Save correct {{REVISIONID}} into parser cache on edit
authorBrion Vibber <brion@users.mediawiki.org>
Sun, 27 Nov 2005 06:04:41 +0000 (06:04 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sun, 27 Nov 2005 06:04:41 +0000 (06:04 +0000)
* Substitute {{REVISIONID}} correctly in diff display
Removed hook for revision-id override, avar will change his extension to use the new system

RELEASE-NOTES
includes/Article.php
includes/DifferenceEngine.php
includes/OutputPage.php
includes/Parser.php

index 9aa1e9b..93011b5 100644 (file)
@@ -255,6 +255,8 @@ fully support the editing toolbar, but was found to be too confusing.
   a page
 * Support <includeonly> in templates loaded through preload= parameter
 * Fix ulimit parameters for wfShellExec when memory_limit is specified in 'm'
+* (bug 3979) Save correct {{REVISIONID}} into parser cache on edit
+* Substitute {{REVISIONID}} correctly in diff display
 
 
 === Caveats ===
index 3025156..563191c 100644 (file)
@@ -810,6 +810,7 @@ class Article {
                                $skin = $wgUser->getSkin();
                        } else if ( $pcache ) {
                                # Display content and save to parser cache
+                               $wgOut->setRevisionId( $this->getRevIdFetched() );
                                $wgOut->addPrimaryWikiText( $text, $this );
                        } else {
                                # Display content, don't attempt to save to parser cache
@@ -818,6 +819,7 @@ class Article {
                                if( !$this->isCurrent() ) {
                                        $oldEditSectionSetting = $wgOut->mParserOptions->setEditSection( false );
                                }
+                               $wgOut->setRevisionId( $this->getRevIdFetched() );
                                $wgOut->addWikiText( $text );
 
                                if( !$this->isCurrent() ) {
@@ -1147,7 +1149,7 @@ class Article {
                $this->editUpdates( $text, $summary, $isminor, $now );
 
                $oldid = 0; # new article
-               $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid );
+               $this->showArticle( $text, wfMsg( 'newarticle' ), false, $isminor, $now, $summary, $oldid, $revisionId );
 
                wfRunHooks( 'ArticleSaveComplete', array( &$this, &$wgUser, $text,
                        $summary, $isminor,
@@ -1396,7 +1398,7 @@ class Article {
                                @unlink($cm->fileCacheName());
                        }
 
-                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision );
+                       $this->showArticle( $text, wfMsg( 'updated' ), $sectionanchor, $isminor, $now, $summary, $lastRevision, $revisionId );
                }
                wfRunHooks( 'ArticleSaveComplete',
                        array( &$this, &$wgUser, $text,
@@ -1410,7 +1412,7 @@ class Article {
         * After we've either updated or inserted the article, update
         * the link tables and redirect to the new page.
         */
-       function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid ) {
+       function showArticle( $text, $subtitle , $sectionanchor = '', $me2, $now, $summary, $oldid, $newid ) {
                global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
                global $wgUseEnotif;
 
@@ -1430,6 +1432,7 @@ class Article {
                # Parse the text and save it to the parser cache
                $wgOut = new OutputPage();
                $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
+               $wgOut->setRevisionId( $newid );
                $wgOut->addPrimaryWikiText( $text, $this );
 
                if ( !$wgUseDumbLinkUpdate ) {
index 2650929..77e9583 100644 (file)
@@ -204,6 +204,9 @@ CONTROL;
                }
 
                $this->loadNewText();
+               if( is_object( $this->mNewRev ) ) {
+                       $wgOut->setRevisionId( $this->mNewRev->getId() );
+               }
                $wgOut->addWikiText( $this->mNewtext );
 
                if( !$this->mNewRev->isCurrent() ) {
@@ -269,6 +272,9 @@ CONTROL;
                # Show current revision
                #
                $wgOut->addHTML( "<hr /><h2>{$this->mPagetitle}</h2>\n" );
+               if( is_object( $this->mNewRev ) ) {
+                       $wgOut->setRevisionId( $this->mNewRev->getId() );
+               }
                $wgOut->addWikiText( $this->mNewtext );
 
                wfProfileOut( $fname );
index 180c6a6..84b27bf 100644 (file)
@@ -55,6 +55,7 @@ class OutputPage {
                $this->mSquidMaxage = 0;
                $this->mScripts = '';
                $this->mETag = false;
+               $this->mRevisionId = null;
        }
 
        function addHeader( $name, $val ) { array_push( $this->mHeaders, $name.': '.$val ) ; }
@@ -235,6 +236,17 @@ class OutputPage {
        function setParserOptions( $options ) {
                return wfSetVar( $this->mParserOptions, $options );
        }
+       
+       /**
+        * Set the revision ID which will be seen by the wiki text parser
+        * for things such as embedded {{REVISIONID}} variable use.
+        * @param mixed $revid an integer, or NULL
+        * @return mixed previous value
+        */
+       function setRevisionId( $revid ) {
+               $val = is_null( $revid ) ? null : intval( $revid );
+               return wfSetVar( $this->mRevisionId, $val );
+       }
 
        /**
         * Convert wikitext to HTML and add it to the buffer
@@ -252,7 +264,8 @@ class OutputPage {
 
        function addWikiTextTitle($text, &$title, $linestart) {
                global $wgParser, $wgUseTidy;
-               $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions, $linestart );
+               $parserOutput = $wgParser->parse( $text, $title, $this->mParserOptions,
+                       $linestart, true, $this->mRevisionId );
                $this->mLanguageLinks += $parserOutput->getLanguageLinks();
                $this->mCategoryLinks += $parserOutput->getCategoryLinks();
                if ( $parserOutput->getCacheTime() == -1 ) {
@@ -268,7 +281,8 @@ class OutputPage {
        function addPrimaryWikiText( $text, $cacheArticle ) {
                global $wgParser, $wgParserCache, $wgUser, $wgUseTidy;
 
-               $parserOutput = $wgParser->parse( $text, $cacheArticle->mTitle, $this->mParserOptions, true );
+               $parserOutput = $wgParser->parse( $text, $cacheArticle->mTitle,
+                       $this->mParserOptions, true, true, $this->mRevisionId );
 
                $text = $parserOutput->getText();
 
@@ -300,7 +314,8 @@ class OutputPage {
         */
        function parse( $text, $linestart = true ) {
                global $wgParser, $wgTitle;
-               $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions, $linestart );
+               $parserOutput = $wgParser->parse( $text, $wgTitle, $this->mParserOptions,
+                       $linestart, true, $this->mRevision );
                return $parserOutput->getText();
        }
 
index 571c487..f40d3ea 100644 (file)
@@ -152,6 +152,7 @@ class Parser
                        'texts' => array(),
                        'titles' => array()
                );
+               $this->mRevisionId = null;
        }
 
        /**
@@ -164,9 +165,10 @@ class Parser
         * @param array $options
         * @param boolean $linestart
         * @param boolean $clearState
+        * @param int $revid number to pass in {{REVISIONID}}
         * @return ParserOutput a ParserOutput
         */
-       function parse( $text, &$title, $options, $linestart = true, $clearState = true ) {
+       function parse( $text, &$title, $options, $linestart = true, $clearState = true, $revid = null ) {
                global $wgUseTidy, $wgContLang;
                $fname = 'Parser::parse';
                wfProfileIn( $fname );
@@ -177,6 +179,7 @@ class Parser
 
                $this->mOptions = $options;
                $this->mTitle =& $title;
+               $this->mRevisionId = $revid;
                $this->mOutputType = OT_HTML;
 
                $this->mStripState = NULL;
@@ -1882,7 +1885,7 @@ class Parser
         * @access private
         */
        function getVariableValue( $index ) {
-               global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgArticle, $wgScriptPath;
+               global $wgContLang, $wgSitename, $wgServer, $wgServerName, $wgScriptPath;
 
                /**
                 * Some of these require message or data lookups and can be
@@ -1895,8 +1898,6 @@ class Parser
 
                $ts = time();
                wfRunHooks( 'ParserGetVariableValueTs', array( &$this, &$ts ) );
-               $revid = $wgArticle->getRevIdFetched();
-               wfRunHooks( 'ParserGetVariableValueRevid', array( &$this, &$revid ) );
 
                switch ( $index ) {
                        case MAG_CURRENTMONTH:
@@ -1918,7 +1919,7 @@ class Parser
                        case MAG_FULLPAGENAMEE:
                                return wfUrlencode( $this->mTitle->getPrefixedText() );
                        case MAG_REVISIONID:
-                               return $revid;
+                               return $this->mRevisionId;
                        case MAG_NAMESPACE:
                                return $wgContLang->getNsText( $this->mTitle->getNamespace() );
                        case MAG_NAMESPACEE: