Page MenuHomePhabricator

mw.message(...).parse() doesn't parse anchor links correctly
Closed, ResolvedPublic

Description

How to reproduce:
Run

mw.messages.set('test message', '[[#anchor|label]]');
mw.message('test message').parse();

at a wiki page.

Expected output:

"<a title=\"#anchor\" href=\"#anchor\">label</a>"

Actual output:

"<a title=\"#anchor\" href=\"/wiki/#anchor\">label</a>"

This makes it impossible to form anchor links from messages, while such use is natural when it comes to JavaScript tools. I've stumbled upon this in the Convenient-Discussions tool.

I'm aware of the limitations of using the messages API in JavaScript, but I believe this feature is important for scripts and not so hard to fix.

Event Timeline

Change 710995 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@master] Fix mw.util.getUrl when given empty title with fragment

https://gerrit.wikimedia.org/r/710995

Change 710995 merged by jenkins-bot:

[mediawiki/core@master] Fix mw.util.getUrl when given empty title with fragment

https://gerrit.wikimedia.org/r/710995

matmarex claimed this task.
matmarex subscribed.

Thanks for the bug report!