{{PAGESIZE:{{FULLPAGENAME}}}}, {{{{FULLPAGENAME}}}} not outdated
authorBrian Wolff <bawolff+wn@gmail.com>
Tue, 15 Jan 2013 21:38:29 +0000 (17:38 -0400)
committerBrian Wolff <bawolff+wn@gmail.com>
Sat, 27 Apr 2013 23:45:32 +0000 (20:45 -0300)
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
includes/parser/CoreParserFunctions.php
includes/parser/Parser.php

index eda1e7c..ec424d3 100644 (file)
@@ -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
index e6342e4..493611a 100644 (file)
@@ -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 );
index 836ddf5..957aa6a 100644 (file)
@@ -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 );