Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/wikitextprocessor/lua/mw_message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ local function makeMessage(options)

function obj:plain()
checkSelf(self, 'plain')
return data.keys
if not data.rawMessage then
return data.keys
end
-- https://www.mediawiki.org/wiki/Manual:Messages_API
return (data.rawMessage:gsub('$(%d+)', function(n)
return tostring(data.params[tonumber(n)] or '$' .. n)
end))
end

function obj:exists()
Expand Down
30 changes: 30 additions & 0 deletions tests/test_lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,36 @@ def test_el_strip_arg(self):
"",
)

def test_mw_message_raw_message_params(self):
# Module:Citation/CS1 substitutes message parameters with mw.message
self.wtp.start_page("")
self.wtp.add_page(
"Module:test",
828,
"""local export = {}
function export.test(frame)
return mw.message.newRawMessage("$1 and $2 and $3", "one", "two"):plain()
end
return export""",
)
self.assertEqual(
self.wtp.expand("{{#invoke:test|test}}"), "one and two and $3"
)

def test_mw_message_raw_message_double_digit_param(self):
self.wtp.start_page("")
self.wtp.add_page(
"Module:test",
828,
"""local export = {}
function export.test(frame)
return mw.message.newRawMessage("$10 $1", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine", "ten"):plain()
end
return export""",
)
self.assertEqual(self.wtp.expand("{{#invoke:test|test}}"), "ten one")

def test_mw_site_canonical_ns_key(self):
# https://cs.wiktionary.org/wiki/Modul:Maintenance#L-193
# `mw.site.namespaces.Category.name`
Expand Down
Loading