Last modified: 2013-03-28 22:18:53 UTC
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-target for redirect target Examples: [[Wikimedia Commons]] [[Wikipedia Commons]] [[€]] [[Does not exist]] [[Wikipedia:Sandbox]] <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&action=edit&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>
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?
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..