Page MenuHomePhabricator

Decide what the link text should be when a link to a page with a display title contains a fragment
Closed, ResolvedPublic

Description

Consider a page Hello that has its display title set to Greetings. What should the following links be rendered as?


[[Hello]]
[[Hello#World]]
[[Hello#World|Hello]]
[[Hello#World|World]]
[[Hello#World|Hello#World]]
[[Hello#World|#World]]

Currently, the link text for those links are rendered as:


[[Hello]]: Greetings
[[Hello#World]]: Greetings
[[Hello#World|Hello]]: Hello
[[Hello#World|World]]: World
[[Hello#World|Hello#World]]: Greetings
[[Hello#World|#World]]: #World

Is that the desired behavior? For example, should [[Hello#World]] and [[Hello#World|Hello#World]] include the anchor in the link text? Should it matter whether the anchor World exists on the page Hello? Are the other links as expected?

Any cases that do not currently have the expected behavior should be fixed, and unit tests should be added to document and test for those choices.

Event Timeline

cicalese removed a subscriber: CCicalese_WMF.
cicalese subscribed.
cicalese updated the task description. (Show Details)

This is the behaviour I would expect:

[[Hello]] → Hello
[[Hello#World]] → Hello#World
[[Hello#World|Hello]] → Hello
[[Hello#World|World]] → World
[[Hello#World|Hello#World]] → Hello#World
[[Hello#World|#World]] → #World

For example, should [[Hello#World]] and [[Hello#World|Hello#World]] include the anchor in the link text?

This (resolved) bug report states that the anchor should not be included in the link text for these situations, which is the current behaviour.

I personally do not have a strong opinion on that bug, only trying to understand how current behaviour has come to be.

This is the behaviour I would expect:

[[Hello]] → Hello
[[Hello#World]] → Hello#World
[[Hello#World|Hello]] → Hello
[[Hello#World|World]] → World
[[Hello#World|Hello#World]] → Hello#World
[[Hello#World|#World]] → #World

This is indeed the behavior of core MediaWiki in the absence of the DisplayTitle extension. But, this task is about what the behavior with DisplayTitle should be. At a minimum, [[Hello]] is rendered as a link with the link text Greetings.

For example, should [[Hello#World]] and [[Hello#World|Hello#World]] include the anchor in the link text?

This (resolved) bug report states that the anchor should not be included in the link text for these situations, which is the current behaviour.

That bug is about the behavior for Semantic MediaWiki subobjects, which contain a long unique identifier for the subobject as the anchor. In that case, displaying the anchor in the link text would be unpleasant.

I personally do not have a strong opinion on that bug, only trying to understand how current behaviour has come to be.

The current behavior is essentially a side effect of the current implementation. The behavior in the presence of anchors was never specified except for Semantic MediaWiki subobjects. This task is an opportunity to give some thought to this to see if any of the cases would be better with different behavior. For example, I can imagine circumstances where rendering [[Hello#World]] with link text Greetings#World might be the desired behavior. It is unclear whether that could be cleanly implemented without breaking the Semantic MediaWiki subobject behavior, however.

The one other special case dictated by Semantic MediaWiki, which does not have an anchor in its basic form, is [[Hello|Hello]]. One might think that could be an override of the display title behavior, requesting that Hello be used as the link text rather than Greetings. However, some Semantic MediaWiki result formats return links in that form, so they would not be able to have the desired display title behavior if the alternative meaning were assumed. Instead, the requested link text is ignored if it exactly matches the link, so [[Hello|Hello]] is rendered the same way as [[Hello]] with Greetings as the link text. Similarly, [[Hello#World|Hello#World]] is rendered as Greetings, currently, because the link text exactly matches the link, so it is rendered as if it were [[Hello#World]]. If the behavior of [[Hello#World]] were changed to be rendered as Greetings#World, then [[Hello#World|Hello#World]] would be rendered as Greetings#World if the current behavior of the link text matching were retained.

Semantic MediaWiki does introduce some special cases that are problematic, which is why https://gerrit.wikimedia.org/r/c/mediawiki/extensions/DisplayTitle/+/810553/ was proposed. But, I don't want to further complicate the codebase unnecessarily, and it turned out that patch was not necessary to fix the missing link bug.

I'm not sure that any changes to the current behavior are strongly desired, but this task exists to figure that out. Whatever is decided, unit tests should be added to ensure that the agreed upon behavior is retained in future versions of the extension.

cicalese triaged this task as Medium priority.Jul 15 2023, 3:49 AM
cicalese claimed this task.
cicalese moved this task from Backlog to Closed on the MediaWiki-extensions-DisplayTitle board.

I'm going to mark this resolved at this point, since choices have been made in the code that are checked in the tests. If somebody has significant counterarguments to the current choices, this could be revisited.