From: Brion Vibber Date: Sun, 27 Nov 2005 06:04:41 +0000 (+0000) Subject: * (bug 3979) Save correct {{REVISIONID}} into parser cache on edit X-Git-Tag: 1.6.0~1113 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=bcf653c8f95e119c3f0f93cdfd59ae2bd5557f3c;p=lhc%2Fweb%2Fwiklou.git * (bug 3979) Save correct {{REVISIONID}} into parser cache on edit * Substitute {{REVISIONID}} correctly in diff display Removed hook for revision-id override, avar will change his extension to use the new system --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 9aa1e9b535..93011b5c4d 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -255,6 +255,8 @@ fully support the editing toolbar, but was found to be too confusing. a page * Support 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 === diff --git a/includes/Article.php b/includes/Article.php index 3025156104..563191c5d2 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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 ) { diff --git a/includes/DifferenceEngine.php b/includes/DifferenceEngine.php index 26509294f8..77e9583787 100644 --- a/includes/DifferenceEngine.php +++ b/includes/DifferenceEngine.php @@ -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( "

{$this->mPagetitle}

\n" ); + if( is_object( $this->mNewRev ) ) { + $wgOut->setRevisionId( $this->mNewRev->getId() ); + } $wgOut->addWikiText( $this->mNewtext ); wfProfileOut( $fname ); diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 180c6a6ef3..84b27bfaa5 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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(); } diff --git a/includes/Parser.php b/includes/Parser.php index 571c487289..f40d3ea0ce 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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: