Skip to content

Fix mw.message plain() to substitute $N params in raw messages - #433

Merged
kristian-clausal merged 1 commit into
tatuylonen:mainfrom
RaNo99:fix-mw-message-plain-params
Oct 6, 2026
Merged

kristian-clausal merged 1 commit into
tatuylonen:mainfrom
RaNo99:fix-mw-message-plain-params

Conversation

@RaNo99

@RaNo99 RaNo99 commented Oct 1, 2026

Copy link
Copy Markdown

mw.message.newRawMessage() stores the message text in data.rawMessage and its params in data.params, but plain() returned data.keys, which newRawMessage() never sets. So plain() returned nil for raw messages, and any module that builds a message from a raw string plus params emitted the unsubstituted text with literal $1, $2 placeholders.

This shows up with Module:Citation/CS1. Its substitute() helper treats a falsy message result as "no replacement" and silently falls back to the raw string, so warnings came out as e.g. ... {{$1}}/$2 ... instead of the intended ... [[Template:...]] ....

The fix follows the MediaWiki Messages API: substitute $N (one-based, multi-digit supported) with the corresponding param, and leave unknown placeholders untouched. Key-based messages keep the previous data.keys behavior.

Added two tests in tests/test_lua.py, covering basic substitution and multi-digit $N.

mw.message.newRawMessage() stores the message text in data.rawMessage and its params in data.params, but plain() returned data.keys, which newRawMessage never sets. So plain() returned nil for raw messages, and modules that build a message from a raw string plus params emitted the unsubstituted text with literal $1, $2 placeholders. This affected Module:Citation/CS1, whose substitute() falls back to the raw string when a message is falsy.

Match the MediaWiki Messages API: substitute $N (one-based, multi-digit supported) with the corresponding param and leave unknown placeholders untouched. Keep returning data.keys for key-based messages as before.
@kristian-clausal kristian-clausal self-assigned this Oct 2, 2026
@kristian-clausal
kristian-clausal merged commit 04e9833 into tatuylonen:main Oct 6, 2026
6 checks passed
@kristian-clausal

Copy link
Copy Markdown
Collaborator

Thank you for noticing and taking care of this, this looks excellent to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants