Topic on Project:Support desk

getNamespace after save complete

7
217.247.165.60 (talkcontribs)

In an extension using LinkerMakeExternalLink, <code>$wgTitle->getNamespace()</code> doesn't return the namespace after saving a page (category in my test). It returns as "0".

Do have to call the context? How would I do that?

MW 1.25.2

88.130.92.150 (talkcontribs)

The hook LinkerMakeExternalLink does not have the Title object as one of its parameters. Did you make sure that you have got it somehow, e.g. with global $wgTitle; or using a function to get the Title object?

217.247.165.60 (talkcontribs)

Yes, $wgTitle is there. Found the problem: $wgTitle returns as "API".

And it stays that way, even with <code>$titleThis = RequestContext::getMain()->getTitle();</code>

Legoktm (talkcontribs)
Subfader (talkcontribs)

Yep, I guess we can close this here.

Ciencia Al Poder (talkcontribs)

That hook isn't supposed to be used to change it depending on the page being displayed... But well, if you need it, you can grab the title from another hook and save it to your own global (or better, a class member variable if the extension has it's own class) to use it later.

Subfader (talkcontribs)

Yes I need LinkerMakeExternalLink cos I have to check the atributes. Actually I need the NS, but that's the same problem.

Creating an own global with another hook sounds like a good workaround. Cheers!

Reply to "getNamespace after save complete"