Template talk:Allpages

From Meta, a Wikimedia project coordination wiki

Subst[edit]

Instead of using subst=subst:, use <includeonly>subst:</includeonly>. Jon Harald Søby 13:07, 15 May 2006 (UTC)[reply]

That is less versatile, parameter subst allows two ways of including (also "subst=", the empty string).--Patrick 01:19, 16 May 2006 (UTC)[reply]
@Jon Harald Søby and @Patrick: I updated this with generalized safesubst: code (removing T7678 workarounds for the old parser and the need to track all the defined namespaces). It now also works with namespace aliases, (e.g., the old "image" name for "file", etc.) or anything the ns: parser function understands. There are a few minor caveats left like how {{ns:4D}} surprisingly results in "Meta" because of how PHP interprets "numeric strings" (FYI: this changes in PHP 8.0+ but might not fix how this parser function is implemented). —Uzume (talk) 09:20, 23 February 2023 (UTC)[reply]

Switch magic[edit]

In template:Allpages (edittalklinkshistory)} the added trick to protect {{{1}}} is advanced template magic: The first parameter (= case) of #switch: normally clobbers an undefined (!) {{{1}}} as shown in ParserFunctions/5678, the second case an undefined {{{2}}}}, etc. But it's possible to have a case for empty values, actually used here for {{ns:0}} (main namespace). The old code was roughly:

|-2
|{{ns:-2}}=Media code
|-1
|{{ns:-1}}=Special code
|0
|=Main code

With that code an undefined {{{1}}} was shown as -2. An undefined {{{2}}} was no issue, it was always used with an empty default {{{2|}}}. The new code rearranged things to handle the main namespace first, and matching an empty string three times:

|||0
|=Main code
|-2
|{{ns:-2}}=Media code
|-1
|{{ns:-1}}=Special code

The first line |||0 matches an empty string (1st case), an empty string (2nd case), and 0 (3rd case). The second line |= matches an empty string (again, 4th case), and finally terminates this set of cases by the code (right hand side of equal sign).

The 2nd and 4th case for an empty string never have any effect, after something's matched it's finished, and the 1st case did this. But 1st and 2nd case also affect any undefined {{{1}}} and {{{2}}}, and that's relevant for a substituted version of this template (not yet documented). -- Omniplex (w:t) 02:23, 16 May 2006 (UTC)[reply]

subst=subst: experiment[edit]

Quick check because I might need it on Help:MediaWiki namespace (click edit to see the wikitext):
Name "MediaWiki" {{Allpages|MediaWiki}}
By number "8" MediaWiki
The same experiment after fixing the template:
By name "MediaWiki" MediaWiki
By number "9" MediaWiki talk