Added {{REVISIONSIZE}} variable to get the current size of a revision.
authorumherirrender <umherirrender_de.wp@web.de>
Wed, 4 Sep 2013 19:09:36 +0000 (21:09 +0200)
committerReedy <reedy@wikimedia.org>
Sat, 21 Sep 2013 02:49:35 +0000 (03:49 +0100)
This avoids giving the own page name to {{PAGESIZE:}} and allows
PAGESIZE on subst: to give the size before save.

Viewing a oldid page will give the corresponding size to that revision.
(Like REVISIONUSER or REVISIONTIMESTAMP)

This partially reverts Idfac13de37d05317f65e4131534543e66cf74873
because there is no need to let PAGESIZE handle extra, when the given
title is the own page.

Change-Id: If9e608d54904c21ac6b095e91ff6e0a15da0fb4c

RELEASE-NOTES-1.22
includes/MagicWord.php
includes/parser/CoreParserFunctions.php
includes/parser/Parser.php
languages/messages/MessagesEn.php

index 3ba86f5..3112e26 100644 (file)
@@ -218,6 +218,7 @@ production.
 * Revision deletion backend code is moved out of SpecialRevisiondelete
 * Add a variable (wgRedactedFunctionArguments) to redact the values sent as certain function
   parameters from exception stack traces.
+* Added {{REVISIONSIZE}} variable to get the current size of a revision.
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
@@ -234,8 +235,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.
+* (bug 39590) Self-transclusions now show the most up to date result always
+  after save instead of being a revision behind.
 * A bias in wfRandomString() toward digits 1-7 has been corrected. Generated
   strings will now start with digits 0 and 8-f as often as they should.
 * (bug 45371) Removed Parser_LinkHooks and CoreLinkFunctions classes.
index adb2ab7..427a1ad 100644 (file)
@@ -124,6 +124,7 @@ class MagicWord {
                'revisionyear',
                'revisiontimestamp',
                'revisionuser',
+               'revisionsize',
                'subpagename',
                'subpagenamee',
                'talkspace',
index 8df0e2c..70a94fe 100644 (file)
@@ -719,13 +719,7 @@ class CoreParserFunctions {
                $page = $title->getPrefixedText();
 
                $length = 0;
-               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] ) ) {
+               if ( isset( $cache[$page] ) ) {
                        $length = $cache[$page];
                } elseif ( $parser->incrementExpensiveFunctionCount() ) {
                        $rev = Revision::newFromTitle( $title, false, Revision::READ_NORMAL );
index 3376734..eac2202 100644 (file)
@@ -191,6 +191,7 @@ class Parser {
        var $mRevisionId;   # ID to display in {{REVISIONID}} tags
        var $mRevisionTimestamp; # The timestamp of the specified revision ID
        var $mRevisionUser; # User to display in {{REVISIONUSER}} tag
+       var $mRevisionSize; # Size to display in {{REVISIONSIZE}} variable
        var $mRevIdForTs;   # The revision ID which was used to fetch the timestamp
        var $mInputSize = false; # For {{PAGESIZE}} on current page.
 
@@ -292,7 +293,7 @@ class Parser {
                $this->mLinkHolders = new LinkHolderArray( $this );
                $this->mLinkID = 0;
                $this->mRevisionObject = $this->mRevisionTimestamp =
-                       $this->mRevisionId = $this->mRevisionUser = null;
+                       $this->mRevisionId = $this->mRevisionUser = $this->mRevisionSize = null;
                $this->mVarCache = array();
                $this->mUser = null;
                $this->mLangLinkLanguages = array();
@@ -375,11 +376,13 @@ class Parser {
                $oldRevisionObject = $this->mRevisionObject;
                $oldRevisionTimestamp = $this->mRevisionTimestamp;
                $oldRevisionUser = $this->mRevisionUser;
+               $oldRevisionSize = $this->mRevisionSize;
                if ( $revid !== null ) {
                        $this->mRevisionId = $revid;
                        $this->mRevisionObject = null;
                        $this->mRevisionTimestamp = null;
                        $this->mRevisionUser = null;
+                       $this->mRevisionSize = null;
                }
 
                wfRunHooks( 'ParserBeforeStrip', array( &$this, &$text, &$this->mStripState ) );
@@ -566,6 +569,7 @@ class Parser {
                $this->mRevisionObject = $oldRevisionObject;
                $this->mRevisionTimestamp = $oldRevisionTimestamp;
                $this->mRevisionUser = $oldRevisionUser;
+               $this->mRevisionSize = $oldRevisionSize;
                $this->mInputSize = false;
                wfProfileOut( $fname );
                wfProfileOut( __METHOD__ );
@@ -2904,6 +2908,13 @@ class Parser {
                                wfDebug( __METHOD__ . ": {{REVISIONUSER}} used, setting vary-revision...\n" );
                                $value = $this->getRevisionUser();
                                break;
+                       case 'revisionsize':
+                               # Let the edit saving system know we should parse the page
+                               # *after* a revision ID has been assigned. This is for null edits.
+                               $this->mOutput->setFlag( 'vary-revision' );
+                               wfDebug( __METHOD__ . ": {{REVISIONSIZE}} used, setting vary-revision...\n" );
+                               $value = $this->getRevisionSize();
+                               break;
                        case 'namespace':
                                $value = str_replace( '_', ' ', $wgContLang->getNsText( $this->mTitle->getNamespace() ) );
                                break;
@@ -5803,6 +5814,27 @@ class Parser {
                return $this->mRevisionUser;
        }
 
+       /**
+        * Get the size of the revision
+        *
+        * @return int|null revision size
+        */
+       function getRevisionSize() {
+               if ( is_null( $this->mRevisionSize ) ) {
+                       $revObject = $this->getRevisionObject();
+
+                       # if this variable is subst: the revision id will be blank,
+                       # so just use the parser input size, because the own substituation
+                       # will change the size.
+                       if ( $revObject ) {
+                               $this->mRevisionSize = $revObject->getSize();
+                       } elseif ( $this->ot['wiki'] || $this->mOptions->getIsPreview() ) {
+                               $this->mRevisionSize = $this->mInputSize;
+                       }
+               }
+               return $this->mRevisionSize;
+       }
+
        /**
         * Mutator for $mDefaultSort
         *
index 5e66259..75b2de9 100644 (file)
@@ -321,6 +321,7 @@ $magicWords = array(
        'revisionyear'            => array( 1,    'REVISIONYEAR' ),
        'revisiontimestamp'       => array( 1,    'REVISIONTIMESTAMP' ),
        'revisionuser'            => array( 1,    'REVISIONUSER' ),
+       'revisionsize'            => array( 1,    'REVISIONSIZE' ),
        'plural'                  => array( 0,    'PLURAL:' ),
        'fullurl'                 => array( 0,    'FULLURL:' ),
        'fullurle'                => array( 0,    'FULLURLE:' ),