From b5511c68c311021f146954355cd702a43942eef4 Mon Sep 17 00:00:00 2001
From: umherirrender
Date: Sun, 1 Apr 2012 12:27:59 +0200
Subject: [PATCH] (bug 34355) add a variable and parser function for the
namespace number
Change-Id: Ie162cfda7ddd38d4278ceee5fd23f5a4e579cb96
---
RELEASE-NOTES-1.20 | 1 +
includes/MagicWord.php | 1 +
includes/parser/CoreParserFunctions.php | 7 +++++++
includes/parser/Parser.php | 3 +++
languages/messages/MessagesEn.php | 1 +
tests/parser/parserTests.txt | 11 +++++++++++
6 files changed, 24 insertions(+)
diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20
index 668cc7594f..d65bf7f478 100644
--- a/RELEASE-NOTES-1.20
+++ b/RELEASE-NOTES-1.20
@@ -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.
diff --git a/includes/MagicWord.php b/includes/MagicWord.php
index 941d97fc54..131ae1ddea 100644
--- a/includes/MagicWord.php
+++ b/includes/MagicWord.php
@@ -95,6 +95,7 @@ class MagicWord {
'fullpagenamee',
'namespace',
'namespacee',
+ 'namespacenumber',
'currentweek',
'currentdow',
'localweek',
diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php
index 7614bf500b..e578f273d4 100644
--- a/includes/parser/CoreParserFunctions.php
+++ b/includes/parser/CoreParserFunctions.php
@@ -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() )
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 99a283dcb8..89540316f5 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -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;
diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php
index 7dcfc60c83..7feec9dc67 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -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' ),
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index d304b19c76..e0eb60ef67 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -2294,6 +2294,17 @@ title=[[User:Ãvar Arnfjörð Bjarmason]]
!! end
+!! test
+Magic Word: {{NAMESPACENUMBER}}
+!! options
+title=[[User:Ãvar Arnfjörð Bjarmason]]
+!! input
+{{NAMESPACENUMBER}}
+!! result
+2
+
+!! end
+
!! test
Magic Word: {{NUMBEROFFILES}}
!! input
--
2.20.1