Page MenuHomePhabricator

pagesize.diff

Authored By
bzimport
Nov 21 2014, 10:05 PM
Size
3 KB
Referenced Files
None
Subscribers
None

pagesize.diff

Index: includes/Parser.php
===================================================================
--- includes/Parser.php (revision 33266)
+++ includes/Parser.php (working copy)
@@ -3285,6 +3285,21 @@
}
/**
+ * Increment the expensive function count
+ *
+ * @return boolean False if the limit has been exceeded
+ */
+
+ function incrementExpensiveFunctionCount() {
+ global $wgExpensiveParserFunctionLimit;
+ $this->mExpensiveFunctionCount++;
+ if ( $this->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit ) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
* Strip double-underscore items like __NOGALLERY__ and __NOTOC__
* Fills $this->mDoubleUnderscores, returns the modified text
*/
Index: includes/CoreParserFunctions.php
===================================================================
--- includes/CoreParserFunctions.php (revision 33266)
+++ includes/CoreParserFunctions.php (working copy)
@@ -42,6 +42,7 @@
$parser->setFunctionHook( 'defaultsort', array( __CLASS__, 'defaultsort' ), SFH_NO_HASH );
$parser->setFunctionHook( 'filepath', array( __CLASS__, 'filepath' ), SFH_NO_HASH );
$parser->setFunctionHook( 'pagesincategory', array( __CLASS__, 'pagesincategory' ), SFH_NO_HASH );
+ $parser->setFunctionHook( 'pagesize', array( __CLASS__, 'pagesize' ), SFH_NO_HASH );
$parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
if ( $wgAllowDisplayTitle ) {
@@ -217,22 +218,37 @@
}
static function pagesincategory( $parser, $category = '', $raw = null ) {
- global $wgExpensiveParserFunctionLimit;
- if ($category == '') {
+ if ( ! $parser->incrementExpensiveFunctionCount() )
return 0;
+
+ if ($category == '')
+ return 0;
+
+ $category = Category::newFromName($category);
+ $count = $category->getPageCount();
+ if ( !$count ) {
+ $count = 0;
}
- $parser->mExpensiveFunctionCount++;
- if ($parser->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit) {
- $category = Category::newFromName($category);
- $count = $category->getPageCount();
- if ( !$count ) {
- $count = 0;
- }
- return self::formatRaw( $count, $raw );
- }
- return 0;
+ return self::formatRaw( $count, $raw );
}
+ static function pagesize( $parser, $page = '', $raw = null ) {
+ if ( ! $parser->incrementExpensiveFunctionCount() )
+ return 0;
+
+ $length = 0;
+ $title = Title::newFromText($page);
+ if ( $title ) {
+ $length = $title->getLength();
+
+ // Register dependency in templatelinks
+ $id = $title->getArticleId();
+ $revid = Revision::newFromTitle($title);
+ $parser->mOutput->addTemplate($title, $id, $revid);
+ }
+ return self::formatRaw( $length, $raw );
+ }
+
static function language( $parser, $arg = '' ) {
global $wgContLang;
$lang = $wgContLang->getLanguageName( strtolower( $arg ) );
@@ -336,5 +352,15 @@
);
return $parser->extensionSubstitution( $params, $frame );
}
+
+ static function incrementExpensiveFunctionCount($parser) {
+ global $wgExpensiveParserFunctionLimit;
+ $parser->mExpensiveFunctionCount++;
+ if ($parser->mExpensiveFunctionCount <= $wgExpensiveParserFunctionLimit) {
+ return true;
+ }
+ return false;
+ }
+
}
Index: languages/messages/MessagesEn.php
===================================================================
--- languages/messages/MessagesEn.php (revision 33266)
+++ languages/messages/MessagesEn.php (working copy)
@@ -339,6 +339,7 @@
'tag' => array( 0, 'tag' ),
'hiddencat' => array( 1, '__HIDDENCAT__' ),
'pagesincategory' => array( 1, 'PAGESINCATEGORY', 'PAGESINCAT' ),
+ 'pagesize' => array( 1, 'PAGESIZE' ),
);
/**

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4296
Default Alt Text
pagesize.diff (3 KB)

Event Timeline