From: umherirrender Date: Wed, 4 Sep 2013 19:09:36 +0000 (+0200) Subject: Added {{REVISIONSIZE}} variable to get the current size of a revision. X-Git-Tag: 1.31.0-rc.0~18710 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/One?a=commitdiff_plain;h=35065c9db563349bf5f84c9c1cc1853f7e37431b;p=lhc%2Fweb%2Fwiklou.git Added {{REVISIONSIZE}} variable to get the current size of a revision. 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 --- diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 3ba86f533d..3112e2681d 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -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. diff --git a/includes/MagicWord.php b/includes/MagicWord.php index adb2ab7747..427a1adc5e 100644 --- a/includes/MagicWord.php +++ b/includes/MagicWord.php @@ -124,6 +124,7 @@ class MagicWord { 'revisionyear', 'revisiontimestamp', 'revisionuser', + 'revisionsize', 'subpagename', 'subpagenamee', 'talkspace', diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 8df0e2cf57..70a94fe5c1 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -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 ); diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 3376734a8d..eac2202ec1 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 * diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 5e66259bc3..75b2de97a5 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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:' ),