From 2d542d3fd5acacf544386417cbef625fa2d2693a Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Tue, 15 Jan 2013 17:38:29 -0400 Subject: [PATCH] {{PAGESIZE:{{FULLPAGENAME}}}}, {{{{FULLPAGENAME}}}} not outdated Previously, when parsing {{PAGESIZE:{{FULLPAGENAME}}}} or {{ {{FULLPAGENAME}} }} (a self-transclusion), we used the version currently in the db, which is outdated because the moment we save the page there will be a new version. This often causes confusion when testing templates that often have examples of template use in the doc section which would be one version out of date. This change causes those variables to give results for the most recent version of the page. For self-templates that's done by reparsing the page after save. For self page sizes this is done by taking the size of the input to Parser::parse. Note that {{subst:PAGESIZE:{{subst:FULLPAGENAME}}}} will still yield previous revision like before. bug: 39590 Change-Id: Idfac13de37d05317f65e4131534543e66cf74873 --- RELEASE-NOTES-1.22 | 2 ++ includes/parser/CoreParserFunctions.php | 14 +++++++++----- includes/parser/Parser.php | 9 +++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index eda1e7cb74..ec424d31ac 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -61,6 +61,8 @@ production. * mw.util.tooltipAccessKeyRegexp: The regex now matches "option-" as well. Support for Mac "option" was added in 1.16, but the regex was never updated. * (bug 46768) Usernames of blocking users now display correctly, even if numeric. +* (bug 39590) {{PAGESIZE}} for the current page and self-transclusions now + show the most up to date result always instead of being a revision behind. === API changes in 1.22 === * (bug 46626) xmldoublequote parameter was removed. Because of a bug, the diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index e6342e4334..493611a244 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -671,8 +671,6 @@ class CoreParserFunctions { * Return the size of the given page, or 0 if it's nonexistent. This is an * expensive parser function and can't be called too many times per page. * - * @todo FIXME: This doesn't work correctly on preview for getting the size - * of the current page. * @todo FIXME: Title::getLength() documentation claims that it adds things * to the link cache, so the local cache here should be unnecessary, but * in fact calling getLength() repeatedly for the same $page does seem to @@ -680,8 +678,8 @@ class CoreParserFunctions { * @todo Document parameters * * @param $parser Parser - * @param string $page TODO DOCUMENT (Default: empty string) - * @param $raw TODO DOCUMENT (Default: null) + * @param $page String Name of page to check (Default: empty string) + * @param $raw String Should number be human readable with commas or just number * @return string */ static function pagesize( $parser, $page = '', $raw = null ) { @@ -697,7 +695,13 @@ class CoreParserFunctions { $page = $title->getPrefixedText(); $length = 0; - if ( isset( $cache[$page] ) ) { + if ( $title->equals( $parser->getTitle() ) + && $parser->mInputSize !== false + ) { + # We are on current page (and not in PST), so + # take length of input to parser. + $length = $parser->mInputSize; + } elseif( isset( $cache[$page] ) ) { $length = $cache[$page]; } elseif ( $parser->incrementExpensiveFunctionCount() ) { $rev = Revision::newFromTitle( $title, false, Revision::READ_NORMAL ); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 836ddf59cf..957aa6a790 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -193,6 +193,7 @@ class Parser { var $mRevisionTimestamp; # The timestamp of the specified revision ID var $mRevisionUser; # User to display in {{REVISIONUSER}} tag var $mRevIdForTs; # The revision ID which was used to fetch the timestamp + var $mInputSize = false; # For {{PAGESIZE}} on current page. /** * @var string @@ -361,6 +362,8 @@ class Parser { $this->startParse( $title, $options, self::OT_HTML, $clearState ); + $this->mInputSize = strlen( $text ); + # Remove the strip marker tag prefix from the input, if present. if ( $clearState ) { $text = str_replace( $this->mUniqPrefix, '', $text ); @@ -519,6 +522,7 @@ class Parser { $this->mRevisionObject = $oldRevisionObject; $this->mRevisionTimestamp = $oldRevisionTimestamp; $this->mRevisionUser = $oldRevisionUser; + $this->mInputSize = false; wfProfileOut( $fname ); wfProfileOut( __METHOD__ ); @@ -3645,6 +3649,11 @@ class Parser { if ( isset( $stuff['deps'] ) ) { foreach ( $stuff['deps'] as $dep ) { $this->mOutput->addTemplate( $dep['title'], $dep['page_id'], $dep['rev_id'] ); + if ( $dep['title']->equals( $this->getTitle() ) ) { + // If we transclude ourselves, the final result + // will change based on the new version of the page + $this->mOutput->setFlag( 'vary-revision' ); + } } } return array( $text, $finalTitle ); -- 2.20.1