한국   대만   중국   일본 
r33551 MediaWiki - Code Review archive

r33551 MediaWiki - Code Review archive

Repository: MediaWiki
Revision: r33550 ? | r33551 | r33552  >
Date: 15:01, 18 April 2008
Author: simetrical
Status: old
Tags:
Comment:
( bug 12698 ) Create PAGESIZE parser function, to return the size of a page. Quite possibly this is getting out of hand; in that case, revert. Patch based on one by CBM/carl-m.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) ( history )
  • /trunk/phase3/includes/CoreParserFunctions.php (modified) ( history )
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) ( history )

Diff [ purge ]

Index: trunk/phase3/includes/CoreParserFunctions.php
? ? @@ -42,6 +42,7 @@
43 43 $parser->setFunctionHook( 'defaultsort', array( __CLASS__, 'defaultsort' ), SFH_NO_HASH );
44 44 $parser->setFunctionHook( 'filepath', array( __CLASS__, 'filepath' ), SFH_NO_HASH );
45 45 $parser->setFunctionHook( 'pagesincategory', array( __CLASS__, 'pagesincategory' ), SFH_NO_HASH );
 46 + $parser->setFunctionHook( 'pagesize', array( __CLASS__, 'pagesize' ), SFH_NO_HASH );
46 47 $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
47 48
48 49 if ( $wgAllowDisplayTitle ) {
? ? @@ -241,6 +242,43 @@
242 243 return self::formatRaw( $count, $raw );
243 244 }
244 245
 246 + /**
 247 + * Return the size of the given page, or 0 if it's nonexistent. This is an
 248 + * expensive parser function and can't be called too many times per page.
 249 + *
 250 + * @FIXME This doesn't work correctly on preview for getting the size of
 251 + * the current page.
 252 + * @FIXME Title::getLength() documentation claims that it adds things to
 253 + * the link cache, so the local cache here should be unnecessary, but in
 254 + * fact calling getLength() repeatedly for the same $page does seem to
 255 + * run one query for each call?
 256 + */
 257 + static function pagesize( $parser, $page = '', $raw = null ) {
 258 + static $cache = array();
 259 + $title = Title::newFromText($page);
 260 +
 261 + if( !is_object( $title ) ) {
 262 + $cache[$page] = 0;
 263 + return self::formatRaw( 0, $raw );
 264 + }
 265 +
 266 + # Normalize name for cache
 267 + $page = $title->getPrefixedText();
 268 +
 269 + $length = 0;
 270 + if( isset( $cache[$page] ) ) {
 271 + $length = $cache[$page];
 272 + } elseif( $parser->incrementExpensiveFunctionCount() ) {
 273 + $length = $cache[$page] = $title->getLength();
 274 +
 275 + // Register dependency in templatelinks
 276 + $id = $title->getArticleId();
 277 + $revid = Revision::newFromTitle($title);
 278 + $parser->mOutput->addTemplate($title, $id, $revid);
 279 + }
 280 + return self::formatRaw( $length, $raw );
 281 + }
 282 +
245 283 static function language( $parser, $arg = '' ) {
246 284 global $wgContLang;
247 285 $lang = $wgContLang->getLanguageName( strtolower( $arg ) );
Index: trunk/phase3/languages/messages/MessagesEn.php
? ? @@ -339,6 +339,7 @@
340 340 'tag' => array( 0, 'tag' ),
341 341 'hiddencat' => array( 1, '__HIDDENCAT__' ),
342 342 'pagesincategory' => array( 1, 'PAGESINCATEGORY', 'PAGESINCAT' ),
 343 + 'pagesize' => array( 1, 'PAGESIZE' ),
343 344 );
344 345
345 346 /**
Index: trunk/phase3/RELEASE-NOTES
? ? @@ -82,6 +82,7 @@
83 83 * Allow \C and \Q as TeX commands to match \R, \N, \Z
84 84 * On Special:UserRights, when you can add a group you can't remove or remove
85 85 one you can't add, a notice is printed to warn you
 86 +* (bug 12698) Create PAGESIZE parser function, to return the size of a page
86 87
87 88 === Bug fixes in 1.13 ===
88 89

Past revisions this follows-up on

Revision Commit summary Author Date
r33549 * Add Parser::incrementExpensiveFunctionCount() and use it in CoreParserFunct... simetrical 14:34, 18 April 2008

Status & tagging log

  • 15:26, 12 September 2011  Meno25 ( talk | contribs )  changed the status of r33551 [ removed: ok  added: old]