From e8d13ad1a2b22801ccfce4891e3fea9cea8adc90 Mon Sep 17 00:00:00 2001
From: divadsn
Date: Fri, 6 Jan 2017 19:44:36 +0000
Subject: [PATCH] Add a new {{PAGELANGUAGE}} variable for use in wikitext
Returns the language code of the page being parsed.
Bug: T59603
Change-Id: I229edd6251cf1120b3395d1811dbb9d96d9cd8ee
---
RELEASE-NOTES-1.29 | 2 ++
includes/MagicWord.php | 1 +
includes/parser/Parser.php | 3 +++
languages/messages/MessagesEn.php | 1 +
tests/parser/parserTests.txt | 11 +++++++++++
5 files changed, 18 insertions(+)
diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29
index 7c60fa7fb9..3630abc47a 100644
--- a/RELEASE-NOTES-1.29
+++ b/RELEASE-NOTES-1.29
@@ -41,6 +41,8 @@ production.
via mw.config.get('wgPageParseReport').
* Added $wgSoftBlockRanges, to allow for automatically blocking anonymous edits
from certain IP ranges (e.g. private IPs).
+* (T59603) Added new magic word {{PAGELANGUAGE}} which returns the language code
+ of the page being parsed.
=== External library changes in 1.29 ===
diff --git a/includes/MagicWord.php b/includes/MagicWord.php
index 391e05aea1..5968e87903 100644
--- a/includes/MagicWord.php
+++ b/includes/MagicWord.php
@@ -169,6 +169,7 @@ class MagicWord {
'localtimestamp',
'directionmark',
'contentlanguage',
+ 'pagelanguage',
'numberofadmins',
'cascadingsources',
];
diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php
index 157946c385..79fc1722f9 100644
--- a/includes/parser/Parser.php
+++ b/includes/parser/Parser.php
@@ -2812,6 +2812,9 @@ class Parser {
case 'contentlanguage':
global $wgLanguageCode;
return $wgLanguageCode;
+ case 'pagelanguage':
+ $value = $pageLang->getCode();
+ break;
case 'cascadingsources':
$value = CoreParserFunctions::cascadingsources( $this );
break;
diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php
index 67369e2ec4..99d3f64864 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -349,6 +349,7 @@ $magicWords = [
'directionmark' => [ 1, 'DIRECTIONMARK', 'DIRMARK' ],
'language' => [ 0, '#LANGUAGE:' ],
'contentlanguage' => [ 1, 'CONTENTLANGUAGE', 'CONTENTLANG' ],
+ 'pagelanguage' => [ 1, 'PAGELANGUAGE' ],
'pagesinnamespace' => [ 1, 'PAGESINNAMESPACE:', 'PAGESINNS:' ],
'numberofadmins' => [ 1, 'NUMBEROFADMINS' ],
'formatnum' => [ 0, 'FORMATNUM' ],
diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt
index 56816e1127..16d724d964 100644
--- a/tests/parser/parserTests.txt
+++ b/tests/parser/parserTests.txt
@@ -10289,6 +10289,17 @@ Magic Word: {{SITENAME}}
!! end
+!! test
+Magic Word: {{PAGELANGUAGE}}
+!! options
+language=fr
+!! wikitext
+{{PAGELANGUAGE}}
+!! html
+fr
+
+!! end
+
!! test
Case-sensitive magic words, when cased differently, should just be template transclusions
!! wikitext
--
2.20.1