r46630 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r46629‎ | r46630 | r46631 >
Date:01:35, 31 January 2009
Author:mrzman
Status:ok (Comments)
Tags:
Comment:
Allow the {{NAMESPACE}}, {{TALKSPACE}}, and {{SUBJECTSPACE}} magic words (and their urlencoding versions) to be used as parser functions to return the desired namespace for a given title.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/parser/CoreParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/CoreParserFunctions.php
@@ -47,6 +47,12 @@
4848 $parser->setFunctionHook( 'pagesincategory', array( __CLASS__, 'pagesincategory' ), SFH_NO_HASH );
4949 $parser->setFunctionHook( 'pagesize', array( __CLASS__, 'pagesize' ), SFH_NO_HASH );
5050 $parser->setFunctionHook( 'protectionlevel', array( __CLASS__, 'protectionlevel' ), SFH_NO_HASH );
 51+ $parser->setFunctionHook( 'namespace', array( __CLASS__, 'namespace' ), SFH_NO_HASH );
 52+ $parser->setFunctionHook( 'namespacee', array( __CLASS__, 'namespacee' ), SFH_NO_HASH );
 53+ $parser->setFunctionHook( 'talkspace', array( __CLASS__, 'talkspace' ), SFH_NO_HASH );
 54+ $parser->setFunctionHook( 'talkspacee', array( __CLASS__, 'talkspacee' ), SFH_NO_HASH );
 55+ $parser->setFunctionHook( 'subjectspace', array( __CLASS__, 'subjectspace' ), SFH_NO_HASH );
 56+ $parser->setFunctionHook( 'subjectspacee', array( __CLASS__, 'subjectspacee' ), SFH_NO_HASH );
5157 $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS );
5258
5359 if ( $wgAllowDisplayTitle ) {
@@ -248,6 +254,48 @@
249255 return self::formatRaw( SiteStats::numberingroup( strtolower( $name ) ), $raw );
250256 }
251257
 258+
 259+ /*
 260+ * Given a title, return the namespace name that would be given by the
 261+ * corresponding magic word
 262+ */
 263+ static function namespace( $parser, $title = null ) {
 264+ $t = Title::newFromText( $title );
 265+ if ( is_null($t) )
 266+ return '';
 267+ return str_replace( '_', ' ', $t->getNsText() );
 268+ }
 269+ static function namespacee( $parser, $title = null ) {
 270+ $t = Title::newFromText( $title );
 271+ if ( is_null($t) )
 272+ return '';
 273+ return wfUrlencode( $t->getNsText() );
 274+ }
 275+ static function talkspace( $parser, $title = null ) {
 276+ $t = Title::newFromText( $title );
 277+ if ( is_null($t) || !$t->canTalk() )
 278+ return '';
 279+ return str_replace( '_', ' ', $t->getTalkNsText() );
 280+ }
 281+ static function talkspacee( $parser, $title = null ) {
 282+ $t = Title::newFromText( $title );
 283+ if ( is_null($t) || !$t->canTalk() )
 284+ return '';
 285+ return wfUrlencode( $t->getTalkNsText() );
 286+ }
 287+ static function subjectspace( $parser, $title = null ) {
 288+ $t = Title::newFromText( $title );
 289+ if ( is_null($t) )
 290+ return '';
 291+ return str_replace( '_', ' ', $t->getSubjectNsText() );
 292+ }
 293+ static function subjectspacee( $parser, $title = null ) {
 294+ $t = Title::newFromText( $title );
 295+ if ( is_null($t) )
 296+ return '';
 297+ return wfUrlencode( $t->getSubjectNsText() );
 298+ }
 299+
252300 /**
253301 * Return the number of pages in the given category, or 0 if it's nonexis-
254302 * tent. This is an expensive parser function and can't be called too many
Index: trunk/phase3/RELEASE-NOTES
@@ -73,6 +73,8 @@
7474 "mw-confirmemail-pending"
7575 * Local redirects to foreign images are now displayed on the ImagePage when
7676 viewing on the local wiki.
 77+* The {{NAMESPACE}}, {{TALKSPACE}}, and {{SUBJECTSPACE}} magic words can now be
 78+ used as parser functions to return the desired namespace for a given title.
7779
7880 === Bug fixes in 1.15 ===
7981 * (bug 16968) Special:Upload no longer throws useless warnings.

Follow-up revisions

RevisionCommit summaryAuthorDate
r46662(bug 8249) Followup to r46630, add parser function versions of the various PA...mrzman22:25, 31 January 2009

Comments

#Comment by Simetrical (talk | contribs)   23:45, 31 January 2009

I see no limitations here on the number of queries this could cause per page. Shouldn't this be limited like #ifexist and pagesincategory?

#Comment by Simetrical (talk | contribs)   23:46, 31 January 2009

Wait, sorry, this shouldn't cause queries, of course. They never need be unstubbed.

#Comment by Werdna (talk | contribs)   23:38, 11 February 2009

Don't these parser functions need to be localised and added to MagicWords.php?

See r46822 for an example of this...

#Comment by Mr.Z-man (talk | contribs)   00:12, 12 February 2009

they're already there as magic words

#Comment by Werdna (talk | contribs)   00:15, 12 February 2009

Oh, right.

Status & tagging log