Hi all,
I'm trying to work out how to add another action tab to the Special:WhatLinksHere page.
I am using the SkinTemplateNavigation::Universal hook, so my code gets called for all special pages. I am then examining the global $wgTitle to figure out what page is being viewed, with the idea being to only add my tab if I discover Special:WhatLinksHere is the page being viewed.
Unfortunately I can't quite figure out how to identify the page being accessed. I am using $wgTitle->getNamespace() and aborting if it's not NS_SPECIAL, which leaves just the root of the title to check.
I was going to compare $wgTitle->getRootTitle() against "WhatLinksHere" but there seems to be a bug in Title::getRootTitle() for Special pages, and it returns the same value as Title::getText(), namely "WhatLinksHere/SomePage", instead of chopping off the "/SomePage". But I think this is a moot point, because I just discovered that non-English wikis seem to have localised names for the special pages, so checking against "WhatLinksHere" won't work on non-English wikis.
Does anyone know how I might go about discovering whether I'm viewing Special:WhatLinksHere from within a SkinTemplateNavigation hook? I'll also need the name of the page being investigated ("SomePage" in the above example) so I can use it in a URL.
Any suggestions would be gratefully appreciated!
Many thanks, Adam.
Does anyone know how I might go about discovering whether I'm viewing Special:WhatLinksHere from within a SkinTemplateNavigation hook?
Well as usual asking the question is all you need to find the answer out yourself ;-)
I found I can use Title::isSpecial() to check for a specific page. In my case I check $wgTitle->isSpecial('Whatlinkshere'), which is true if I'm looking at Special:WhatLinksHere.
I'll also need the name of the page being investigated ("SomePage" in the above example) so I can use it in a URL.
Unfortunately this hasn't been so easy. The docs suggest Title::getSubpageText() would almost work (it's supposed to return "Baz" from "User:Foo/Bar/Baz" which isn't enough, I need "Bar/Baz") but again it doesn't seem to work properly on the special page and it returns "WhatLinksHere/User:Foo/Bar/Baz" instead.
Any idea how I can get rid of "WhatLinksHere" from the front?
Thanks, Adam.
Hi Adam,
I'll also need the name of the page being investigated ("SomePage" in the above example) so I can use it in a URL.
Unfortunately this hasn't been so easy. The docs suggest Title::getSubpageText() would almost work (it's supposed to return "Baz" from "User:Foo/Bar/Baz" which isn't enough, I need "Bar/Baz") but again it doesn't seem to work properly on the special page and it returns "WhatLinksHere/User:Foo/Bar/Baz" instead.
Any idea how I can get rid of "WhatLinksHere" from the front?
preg_replace immediately comes to mind: http://php.net/manual/en/function.preg-replace.php
-- schnee
Any idea how I can get rid of "WhatLinksHere" from the front?
preg_replace immediately comes to mind: http://php.net/manual/en/function.preg-replace.php
The problem there is it's only "WhatLinksHere" in English. Other languages use localised versions, so it would be a massive regex very prone to breakage...
Thanks, Adam.
Hi Adam,
The problem there is it's only "WhatLinksHere" in English. Other languages use localised versions, so it would be a massive regex very prone to breakage...
Hmm, couldn't you pull the localized name(s) from $specialPageAliases ? Check the wiki's language, find the right alias and chop that off.
-- schnee
The problem there is it's only "WhatLinksHere" in English. Other languages use localised versions, so it would be a massive regex very prone to breakage...
Hmm, couldn't you pull the localized name(s) from $specialPageAliases ? Check the wiki's language, find the right alias and chop that off.
That could work, but after looking through the code I found a function in SpecialPageFactory that does this already! (Except instead of looking up the page name it cuts everything off up until the first forward-slash.)
$titleParts = SpecialPageFactory::resolveAlias($wgTitle->getText()); $subpageText = $titleParts[1];
This seems to work well.
Thanks for your help!
Cheers, Adam.
On Sat, 06 Jul 2013 06:36:40 -0700, Adam Nielsen a.nielsen@shikadi.net wrote:
Does anyone know how I might go about discovering whether I'm viewing Special:WhatLinksHere from within a SkinTemplateNavigation hook?
Well as usual asking the question is all you need to find the answer out yourself ;-)
I found I can use Title::isSpecial() to check for a specific page. In my case I check $wgTitle->isSpecial('Whatlinkshere'), which is true if I'm looking at Special:WhatLinksHere.
I'll also need the name of the page being investigated ("SomePage" in the above example) so I can use it in a URL.
Unfortunately this hasn't been so easy. The docs suggest Title::getSubpageText() would almost work (it's supposed to return "Baz" from "User:Foo/Bar/Baz" which isn't enough, I need "Bar/Baz") but again it doesn't seem to work properly on the special page and it returns "WhatLinksHere/User:Foo/Bar/Baz" instead.
Any idea how I can get rid of "WhatLinksHere" from the front?
Thanks, Adam.
Do NOT use $wgTitle. Besides being an awful global it's the wrong title here.
Use $skin->getRelevantTitle() to get the title used for tabs.
mediawiki-l@lists.wikimedia.org