From: Alex Z Date: Sat, 31 Jan 2009 01:35:18 +0000 (+0000) Subject: Allow the {{NAMESPACE}}, {{TALKSPACE}}, and {{SUBJECTSPACE}} magic words (and their... X-Git-Tag: 1.31.0-rc.0~43109 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=a01e8619681f7612ff56be1e1c4931391bf9902c;p=lhc%2Fweb%2Fwiklou.git 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. --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 81f9615c6e..20c41a1dcb 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -73,6 +73,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN "mw-confirmemail-pending" * Local redirects to foreign images are now displayed on the ImagePage when viewing on the local wiki. +* The {{NAMESPACE}}, {{TALKSPACE}}, and {{SUBJECTSPACE}} magic words can now be + used as parser functions to return the desired namespace for a given title. === Bug fixes in 1.15 === * (bug 16968) Special:Upload no longer throws useless warnings. diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index cbeb144228..1045fad2a0 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -47,6 +47,12 @@ class CoreParserFunctions { $parser->setFunctionHook( 'pagesincategory', array( __CLASS__, 'pagesincategory' ), SFH_NO_HASH ); $parser->setFunctionHook( 'pagesize', array( __CLASS__, 'pagesize' ), SFH_NO_HASH ); $parser->setFunctionHook( 'protectionlevel', array( __CLASS__, 'protectionlevel' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'namespace', array( __CLASS__, 'namespace' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'namespacee', array( __CLASS__, 'namespacee' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'talkspace', array( __CLASS__, 'talkspace' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'talkspacee', array( __CLASS__, 'talkspacee' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'subjectspace', array( __CLASS__, 'subjectspace' ), SFH_NO_HASH ); + $parser->setFunctionHook( 'subjectspacee', array( __CLASS__, 'subjectspacee' ), SFH_NO_HASH ); $parser->setFunctionHook( 'tag', array( __CLASS__, 'tagObj' ), SFH_OBJECT_ARGS ); if ( $wgAllowDisplayTitle ) { @@ -248,6 +254,48 @@ class CoreParserFunctions { return self::formatRaw( SiteStats::numberingroup( strtolower( $name ) ), $raw ); } + + /* + * Given a title, return the namespace name that would be given by the + * corresponding magic word + */ + static function namespace( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return str_replace( '_', ' ', $t->getNsText() ); + } + static function namespacee( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return wfUrlencode( $t->getNsText() ); + } + static function talkspace( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) || !$t->canTalk() ) + return ''; + return str_replace( '_', ' ', $t->getTalkNsText() ); + } + static function talkspacee( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) || !$t->canTalk() ) + return ''; + return wfUrlencode( $t->getTalkNsText() ); + } + static function subjectspace( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return str_replace( '_', ' ', $t->getSubjectNsText() ); + } + static function subjectspacee( $parser, $title = null ) { + $t = Title::newFromText( $title ); + if ( is_null($t) ) + return ''; + return wfUrlencode( $t->getSubjectNsText() ); + } + /** * Return the number of pages in the given category, or 0 if it's nonexis- * tent. This is an expensive parser function and can't be called too many