Index: trunk/phase3/includes/CoreParserFunctions.php
===================================================================
--- trunk/phase3/includes/CoreParserFunctions.php (revision 33550)
+++ trunk/phase3/includes/CoreParserFunctions.php (revision 33551)
@@ -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 ) {
@@ -241,6 +242,43 @@
return self::formatRaw( $count, $raw );
}
+ /**
+ * 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.
+ *
+ * @FIXME This doesn't work correctly on preview for getting the size of
+ * the current page.
+ * @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
+ * run one query for each call?
+ */
+ static function pagesize( $parser, $page = '', $raw = null ) {
+ static $cache = array();
+ $title = Title::newFromText($page);
+
+ if( !is_object( $title ) ) {
+ $cache[$page] = 0;
+ return self::formatRaw( 0, $raw );
+ }
+
+ # Normalize name for cache
+ $page = $title->getPrefixedText();
+
+ $length = 0;
+ if( isset( $cache[$page] ) ) {
+ $length = $cache[$page];
+ } elseif( $parser->incrementExpensiveFunctionCount() ) {
+ $length = $cache[$page] = $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 ) );
Index: trunk/phase3/languages/messages/MessagesEn.php
===================================================================
--- trunk/phase3/languages/messages/MessagesEn.php (revision 33550)
+++ trunk/phase3/languages/messages/MessagesEn.php (revision 33551)
@@ -339,6 +339,7 @@
'tag' => array( 0, 'tag' ),
'hiddencat' => array( 1, '__HIDDENCAT__' ),
'pagesincategory' => array( 1, 'PAGESINCATEGORY', 'PAGESINCAT' ),
+ 'pagesize' => array( 1, 'PAGESIZE' ),
);
/**
Index: trunk/phase3/RELEASE-NOTES
===================================================================
--- trunk/phase3/RELEASE-NOTES (revision 33550)
+++ trunk/phase3/RELEASE-NOTES (revision 33551)
@@ -82,6 +82,7 @@
* Allow \C and \Q as TeX commands to match \R, \N, \Z
* On Special:UserRights, when you can add a group you can't remove or remove
one you can't add, a notice is printed to warn you
+* (bug 12698) Create PAGESIZE parser function, to return the size of a page
=== Bug fixes in 1.13 ===