(bug 34355) add a variable and parser function for the namespace number
authorumherirrender <umherirrender_de.wp@web.de>
Sun, 1 Apr 2012 10:27:59 +0000 (12:27 +0200)
committerBrion Vibber <brion@pobox.com>
Tue, 3 Apr 2012 20:25:06 +0000 (13:25 -0700)
Change-Id: Ie162cfda7ddd38d4278ceee5fd23f5a4e579cb96

RELEASE-NOTES-1.20
includes/MagicWord.php
includes/parser/CoreParserFunctions.php
includes/parser/Parser.php
languages/messages/MessagesEn.php
tests/parser/parserTests.txt

index 668cc75..d65bf7f 100644 (file)
@@ -28,6 +28,7 @@ production.
 * (bug 18062) new message when edit or create the local page of a shared file
 * (bug 22870) Separate interface message when creating a page
 * (bug 17615) nosummary option should be reassigned on preview/captcha
+* (bug 34355) add a variable and parser function for the namespace number
 
 === Bug fixes in 1.20 ===
 * (bug 30245) Use the correct way to construct a log page title.
index 941d97f..131ae1d 100644 (file)
@@ -95,6 +95,7 @@ class MagicWord {
                'fullpagenamee',
                'namespace',
                'namespacee',
+               'namespacenumber',
                'currentweek',
                'currentdow',
                'localweek',
index 7614bf5..e578f27 100644 (file)
@@ -62,6 +62,7 @@ class CoreParserFunctions {
                $parser->setFunctionHook( 'protectionlevel',  array( __CLASS__, 'protectionlevel'  ), SFH_NO_HASH );
                $parser->setFunctionHook( 'namespace',        array( __CLASS__, 'mwnamespace'      ), SFH_NO_HASH );
                $parser->setFunctionHook( 'namespacee',       array( __CLASS__, 'namespacee'       ), SFH_NO_HASH );
+               $parser->setFunctionHook( 'namespacenumber',  array( __CLASS__, 'namespacenumber'  ), 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 );
@@ -437,6 +438,12 @@ class CoreParserFunctions {
                        return '';
                return wfUrlencode( $t->getNsText() );
        }
+       static function namespacenumber( $parser, $title = null ) {
+               $t = Title::newFromText( $title );
+               if ( is_null( $t ) )
+                       return '';
+               return $t->getNamespace();
+       }
        static function talkspace( $parser, $title = null ) {
                $t = Title::newFromText( $title );
                if ( is_null( $t ) || !$t->canTalk() )
index 99a283d..8954031 100644 (file)
@@ -2760,6 +2760,9 @@ class Parser {
                        case 'namespacee':
                                $value = wfUrlencode( $wgContLang->getNsText( $this->mTitle->getNamespace() ) );
                                break;
+                       case 'namespacenumber':
+                               $value = $this->mTitle->getNamespace();
+                               break;
                        case 'talkspace':
                                $value = $this->mTitle->canTalk() ? str_replace( '_',' ',$this->mTitle->getTalkNsText() ) : '';
                                break;
index 7dcfc60..7feec9d 100644 (file)
@@ -240,6 +240,7 @@ $magicWords = array(
        'pagenamee'              => array( 1,    'PAGENAMEE'              ),
        'namespace'              => array( 1,    'NAMESPACE'              ),
        'namespacee'             => array( 1,    'NAMESPACEE'             ),
+       'namespacenumber'        => array( 1,    'NAMESPACENUMBER'        ),
        'talkspace'              => array( 1,    'TALKSPACE'              ),
        'talkspacee'             => array( 1,    'TALKSPACEE'              ),
        'subjectspace'           => array( 1,    'SUBJECTSPACE', 'ARTICLESPACE' ),
index d304b19..e0eb60e 100644 (file)
@@ -2294,6 +2294,17 @@ title=[[User:Ævar Arnfjörð Bjarmason]]
 </p>
 !! end
 
+!! test
+Magic Word: {{NAMESPACENUMBER}}
+!! options
+title=[[User:Ævar Arnfjörð Bjarmason]]
+!! input
+{{NAMESPACENUMBER}}
+!! result
+<p>2
+</p>
+!! end
+
 !! test
 Magic Word: {{NUMBEROFFILES}}
 !! input