Page MenuHomePhabricator

Make it easy for gadgets to understand destination of internal links in content
Open, LowPublic

Description

Add HTML5 data attribute with wikititle, namespace and redirect target for all links on HTML5 enabled wikis. Suggested attribute names:

  • data-mw-title for Wikititle
  • data-mw-ns for namespace number
  • data-mw-fragment for links with fragment
  • data-mw-target for redirect target

Examples:

<a href="/wiki/Wikimedia_Commons"
   title="Wikimedia Commons"
   data-mw-title="Wikimedia Commons"
   data-mw-ns="0"
>Wikimedia Commons</a>
<a href="/wiki/Wikipedia_Commons"
   title="Wikipedia Commons"
   class="mw-redirect"
   data-mw-title="Wikipedia Commons"
   data-mw-ns="0"
   data-mw-target="Wikimedia Commons"
>Wikipedia Commons</a>
<a href="/wiki/%E2%82%AC"
   title="€"
   class="mw-redirect"
   data-mw-title="€"
   data-mw-ns="0"
   data-mw-target="Euro sign"
></a>
<a href="/w/index.php?title=Does_not_exist&amp;action=edit&amp;redlink=1"
   class="new"
   title="Does not exist (page does not exist)"
   data-mw-title="Does not exist"
   data-mw-ns="0"
>Does not exist</a>
<a href="/wiki/Wikipedia:Sandbox"
   title="Wikipedia:Sandbox"
   data-mw-title="Sandbox"
   data-mw-ns="4"
>Wikimedia Commons</a>
<a href="/wiki/Foo_Bar#Fragment_.E2.82.AC"
   title="Foo Bar"
   data-mw-title="Foo Bar"
   data-mw-ns="0"
   data-mw-fragment="Fragment €"
>Foo Bar#Fragment €</a>

Details

Reference
bz38598

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 12:55 AM
bzimport set Reference to bz38598.
bzimport added a subscriber: Unknown Object (MLST).

mr.heat wrote:

Why do you need to *repeat* the title? It's already there.

Why do you need the namespace? It's already in the title. Why can't you use wgNamespaceIds to convert the namespace name to a number?

Also, there is an API to request everything you need. Why can't you use the API?

steefy389 wrote:

The title is used to show the user a tooltip and gets modified from some userscripts, like HotCat. So if we add an data-Tag, it is useful to add the namespace-number. Of course you can extract namespace and pagename from the title or from the URL, but both can get easily changed at some point in the future or even modified before the script is running.

The API needs some parameters to be called, to get infos for a page you need at least the title, so you can't use it to request this information. Additionally, it is another request to the server that isn't necessary.

User:PerfektesChaos summarized this on dewiki too: //de.wikipedia.org/w/index.php?diff=105941306&oldid=105924999

(In reply to comment #1)

Why do you need to *repeat* the title? It's already there.

Why do you need the namespace? It's already in the title. Why can't you use
wgNamespaceIds to convert the namespace name to a number?

Also, there is an API to request everything you need. Why can't you use the
API?

See also mw.Title, which does all of that for you.

e.g.

var t = new mw.Title( 'Image: foo_bar quux.jpg ');
t.getMain()
< "Foo_bar_quux.jpeg"
t.getNamespaceId()
< 6
t.getNamespacePrefix()
< "File:"
// etc..

Fomafix set Security to None.
Jdlrobson changed the task status from Open to Stalled.Jan 13 2021, 8:02 PM
Jdlrobson added a project: MediaWiki-Parser.
Jdlrobson added a subscriber: Jdlrobson.

I'm not sure what the problem statement is. Please elaborate on why this is needed. Presumably this would require changes in the parser.

I think the only possibly legitimate reason to do this would be to get the title without " (page does not exist)" for redlinks. See for example https://sv.wikipedia.org/wiki/MediaWiki:Gadget-MarkDeletedPages.js and https://sv.wikipedia.org/wiki/MediaWiki:Gadget-NormaliseraSignatur.js that have to remove " [inte skriven än]". The fact that some user scripts may modify the title attribute is not a good enough reason to do this, in my humble opinion, as the same script could just as easily modify the data attribute as well.

Krinkle renamed this task from Add HTML5 data attribute with wikititle for all links to Make it easy for gadgets to understand destination of internal links in content.Jan 18 2021, 9:36 PM
Krinkle removed a subscriber: wikibugs-l-list.

Rephrased to solve a problem instead of proposing a generic solution looking for reasons to exist.

As demonstrated in the previous comments, I think this is sufficiently possible and easy to do already. The one thing we could perhaps do is add one attribute (not 2, 3 or 4) with the string representation of the entire link target, which could then be parsed further if needed, using mw.Title. This would be justified if and when extracting it from the title attributes becomes too difficult or no longer possible for some reason, or if we want to make it easier and more stable as it stands today and think it is worth increasing article size by ~ 10% to add this. [1]

[1]: 10% is based on Obama which is 1.39M currently (mw-parser-output), and applying $$('.mw-body-content a').forEach(node => { if (node.href && node.getAttribute('href').startsWith('/')) { node.setAttribute('data-mw-linktarget', node.title); } }) increases the outer HTML length of the parser output element to 1.56M.

Or just remove ⟨red-link-title⟩

If we remove that, we should also remove the red-link feature more generally. Otherwise we would restrict this privilege to sighted users only. I don't have an opinion on that, but they should go hand-in-hand.

Aklapper changed the task status from Stalled to Open.Jan 19 2021, 8:06 AM