From e1bd4911bd669ecdb3a955c2ab7bc26b265dd10f Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sun, 19 Nov 2017 16:22:03 +0000 Subject: [PATCH] Add a property "talkNsText" to mw.title objects Bug: T180911 Change-Id: I847ac4b7587b98be06b25fe14765e9efdc7b774d --- includes/Engines/LuaCommon/lualib/mw.title.lua | 10 +++++++++- tests/phpunit/Engines/LuaCommon/TitleLibraryTests.lua | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/Engines/LuaCommon/lualib/mw.title.lua b/includes/Engines/LuaCommon/lualib/mw.title.lua index b36022f5..e64f55dd 100644 --- a/includes/Engines/LuaCommon/lualib/mw.title.lua +++ b/includes/Engines/LuaCommon/lualib/mw.title.lua @@ -64,7 +64,15 @@ local function makeTitleObject( data ) data.isSpecialPage = data.namespace == mw.site.namespaces.Special.id data.isTalkPage = ns.isTalk data.subjectNsText = ns.subject.name - data.canTalk = ns.talk ~= nil + + if ns.talk ~= nil then + data.canTalk = true + if not data.isExternal then + data.talkNsText = ns.talk.name + end + else + data.canTalk = false + end data.prefixedText = data.text if data.nsText ~= '' then diff --git a/tests/phpunit/Engines/LuaCommon/TitleLibraryTests.lua b/tests/phpunit/Engines/LuaCommon/TitleLibraryTests.lua index f359586a..ccaf2149 100644 --- a/tests/phpunit/Engines/LuaCommon/TitleLibraryTests.lua +++ b/tests/phpunit/Engines/LuaCommon/TitleLibraryTests.lua @@ -266,6 +266,14 @@ local tests = { args = { 'subjectNsText' }, expect = { '', 'Module', '', '', '', 'Module', 'Module' } }, + { name = '.canTalk', func = prop_foreach, + args = { 'canTalk' }, + expect = { true, true, true, true, true, true, true } + }, + { name = '.talkNsText', func = prop_foreach, + args = { 'talkNsText' }, + expect = { 'Talk', 'Module talk', nil, 'Talk', 'Talk', 'Module talk', 'Module talk' } + }, { name = '.fragment', func = prop_foreach, args = { 'fragment' }, expect = { '', '', '', 'frag', '', ' frag frag', ' frag frag' }