Page MenuHomePhabricator

DiscussionTools produces invalid fragments for topic titles with curly brackets (or other non-wgLegalTitleChars?)
Open, Needs TriagePublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

What happens?: It fails complaining about invalid characters inside the special page title. The complain is correct, yet the creation of anchors/fragments with curly brackets breaks the ability to use GoToComment links to refer to comments inside such topics.

What should have happened instead?: GoToComment should either accept the parameter despite having invalid characters, or DiscussionTools should skip invalid title character when creating anchors/fragments.

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia): wmf, zhwiki

Other information (browser name/version, screenshots, etc.):

  • This affected Convenient-Discussions's ability to generate GoToComment wikilink syntaxes, as the gadget attempts to feed a GoToComment special page title with curly brackets in it to mw.Title.newFromText, which is designed to reject any titles containing anything outside of wgLegalTitleChars. (CD/src/pageRegistry.js#L55)
  • I haven't tested whether other non-wgLegalTitleChars characters would cause the same issue, but I guess at least some would. Fixes should look up for wgLegalTitleChars instead of hard-coding curly brackets.
  • Note that the browser anchor part works completely fine (i.e. I can navigate with TheTalkPage#c-魔琴-20260518082400-{123}, just not Special:GoToComment/c-魔琴-20260518082400-{123}) , and some might have been using the anchors with curly brackets. It might be a breaking change to remove all illegal title characters from the algorithm for generating anchors/fragments.

Event Timeline

Thanks for pointing to errors in how CD handles this.

  • This affected Convenient-Discussions's ability to generate GoToComment wikilink syntaxes, as the gadget attempts to feed a GoToComment special page title with curly brackets in it to mw.Title.newFromText, which is designed to reject any titles containing anything outside of wgLegalTitleChars. (CD/src/pageRegistry.js#L55)

So, is there no way to generate a Special:GoToComment URL so that it jumps to the comment automatically? For the time being, I replaced the Special:GoToComment/[id] URL with Special:FindComment + idorname search parameter, e.g. https://test.wikipedia.org/w/index.php?title=Special:FindComment&idorname=c-JWBTH-20260519104400-test%3F_{123}.

So, is there no way to generate a Special:GoToComment URL so that it jumps to the comment automatically? For the time being, I replaced the Special:GoToComment/ URL with Special:FindComment + idorname search parameter, e.g. https://test.wikipedia.org/w/index.php?title=Special:FindComment&idorname=c-JWBTH-20260519104400-test%3F_{123}.

No, as that's a flaw in MW's generation of comment anchors.

And note that CD did nothing wrong on the creation of GoToComment links, and in most cases that do work. I'd recommend adding a null check and fallback to FindComment only if GoToComment failed.

We encountered this problem before, see: https://gerrit.wikimedia.org/g/mediawiki/extensions/DiscussionTools/+/6a7bfe2debd24e5d3fd52566eeb77f2d3aeb664a/includes/SpecialFindComment.php#105

(T389741) Comment IDs/names may use characters that are not valid in page titles, like '<'.
Omit the message with the wikilink to Special:GoToComment/… if the link would be invalid.
They can only be linked to using external links to Special:FindComment?idorname=…
or wikilinks to the target page with a fragment identifier, for example Talk:Foo#….
It's a pity we haven't realized this before deciding on this linking scheme. Oops.

You're right that, to solve this, we'd probably have to change our IDs to remove or encode characters that would be invalid in titles.

In the referenced task I gave up on solving this properly, since updating the existing data is somewhat involved and it didn't seem worth the effort, but it is possible in principle, following similar steps as in T356196.

I have two ideas that would not require modifying existing IDs:

  1. Accept ?idorname= in Special:GoToComment. This will not solve the wikilink problem, but at least we have a way to go to those comments without an extra click.
    • This approach is easier than the second that I can probably write a patch.
  2. Invent an escape scheme specifically designed for Special:GoToComment and Special:FindComment. The special page handlers then unescape the input and work on the result.
    • We might need a PHP-side and JS-side API designed to escape and unescape for the said purpose.

Change #1289458 had a related patch set uploaded (by 1F616EMO; author: 1F616EMO):

[mediawiki/extensions/DiscussionTools@master] GoToComment: Support idorname URL parameter

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

Change #1289458 merged by jenkins-bot:

[mediawiki/extensions/DiscussionTools@master] GoToComment: Support idorname URL parameter

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

Thanks for the patch @1F616EMO!

I'm not sure what are the criteria to close this task – feel free to close it if you think this sufficiently addresses it, or clarify if you think something else needs to be changed somewhere.

@matmarex There are two sub-problems in this issue, all regarding to comment IDs with illegal title characters as of now:

  1. There does not exist a URL that allows jumping to such a comment without extra clicks. (Fixed)
  2. There does not exist a wikitext syntax that allows linking to such a comment. (Still not fixed)

The acceptance criteria to (2) is that one can use native wikitext (ideally wikilinks [[...]]) to link to any comments, including those that contains illegal title characters as of now. This can be solved by modifying the ID generation algorithm, introducing an escape scheme, or even introducing a new magic word (I imagine something like {{#comment:c-Example-YYYYMMDDHHMMSS}}, similar to how we invented {{#interwikilink}} for moswiki) for linking to comments. A workaround (given that (1) have been solved) is to use the external link syntax, but I see that more as a hack than a solution.

Also, it would be good if we can solve this too:

  1. There does not exist a way to access such a comment by passing in its ID as the sub-pagename of Special:GoToComment, e.g. Special:GoToComment/c-Example-YYYYMMDDHHMMSS (Will be fixed alongside (2) if we decide to work on the IDs or an escape scheme, otherwise hard to fix)

All the above sub-problems find root in the same common issue, that comment IDs contains illegal title characters.

The acceptance criteria to (2) is that one can use native wikitext (ideally wikilinks [[...]]) to link to any comments, including those that contains illegal title characters as of now. This can be solved by […] introducing a new magic word (I imagine something like {{#comment:c-Example-YYYYMMDDHHMMSS}}, similar to how we invented {{#interwikilink}} for moswiki) for linking to comments.

That wouldn’t work in edit summaries, which is AFAIK the only place where the external link syntax is not only inconvenient, but impossible – edit comments allow neither external links nor magic words. Unlike interwiki links to moswiki, I think links to comments is a fairly common need in edit summaries (e.g. a change implemented in an article based on talk page consensus or a user blocked following a noticeboard discussion), so I’d avoid solving the problem with a magic word if possible.

That wouldn’t work in edit summaries, which is AFAIK the only place where the external link syntax is not only inconvenient, but impossible […] links to comments is a fairly common need in edit summaries (e.g. a change implemented in an article based on talk page consensus or a user blocked following a noticeboard discussion), so I’d avoid solving the problem with a magic word if possible.

Then an escape scheme would be the most feasible way. It would be confusing to those who manually construct GoToComment links by copying URL fragments, but requiring manually construction is already bad UX independent of this issue, and we might want to add a button in DT for copying such a wikilink anyways.

I will open a new feature request regarding the buttons later today, and perhaps a patch too.

Just tested that the pipe character | is also not working, as seen by CD refusing to give a GoToComment wikilink at
https://wiki-twi.1f616emo.xyz/index.php?title=Special:FindComment&idorname=c-1F616EMO-20260524022400-How_about_|some_cute_pipes|%3F.