Page MenuHomePhabricator

add a variable and parser function for the namespace number
Closed, ResolvedPublic

Description

The {{NAMESPACE}} variable always give the namespace text, but this text can change, due to a configuration or localisation change. Having a way to get the namespace number makes it possible to avoid a breaking of conditions or transclusion by a change of a namespace.

Using {{NAMESPACE}} and {{ns:0}} inside a #ifeq does not have this problem, but when using the {{NAMESPACE}} in transclusion of a page, you have this problem or you have to use a big switch to map the name against the number, but getting the number direct from MediaWiki sounds better.

Please add a {{NAMESPACENUMBER}} variable and also a parser function {{NAMESPACENUMBER:pagename}} (like NAMESPACE).

Maybe call it NAMESPACEID, I am not sure, which is a better name.

Thanks.


Version: 1.20.x
Severity: enhancement

Details

Reference
bz34355

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 12:11 AM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz34355.
bzimport added a subscriber: Unknown Object (MLST).

I'm a bit leery of this because the ids may become much more variable in the future... but it's probably not a problem to do.

Workaround: [[de:Vorlage:NAMESPACENUMBER]]

Commited a patch with gerrit 4056

I find it strange that NAMESPACENUMBER was added that works on full pagenames but nothing was added to do the same with just namespace names—the corollary to ns: and nse:. It is easy enough to workaround as I can always just smash on a random pagename to a namespace and then pass to NAMESPACENUMBER: but that seems crudely unnecessary and a strange oversight.

I noticed this in trying to create links to Special:Allpages which only takes namespace numbers as the values to the querystring parameter &namespace=.

I have since found out I can also just add subpage references to Special:Allpages, e.g., [[Special:Allpages/Help:D]].