Jump to content

Template:Template usage: Difference between revisions

From Fifth Empire Wiki
enable custom prefix parameter usage, remove template namespaces for now
m 53 revisions imported from wikipedia:Template:Template_usage
 
(43 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<noinclude>{{Documentation}}</noinclude>
<!-- Curly brackets matching should ignore [^}], \{{!}}; insource:/\{} is OK.
--><onlyinclude><!--
Make a search link.
-->{{plain link
  |url =
    {{fullurl:Special:Search|search=<!--
        -->{{urlencode:<!-- encodes spaces, so let's avoid unnecessary spaces.


<onlyinclude>{{#switch: {{{prefix|{{FULLPAGENAME}}}}}
          Build this query:
          hastemplate: template insource:/\{\{ *[Tt]emplate *\| *[^}]*pattern/


|{{FULLPAGENAME}} = Phase one of two: '''a test regexp''' /<kbd>{{{pattern}}}</kbd>/.
          Add the ever present "hastemplate:" filter and a space
          -->hastemplate:"{{{template|{{{1|Template usage}}}}}}" <!--


|#default = Readied '''a tested regexp''' /<kbd>{{{pattern}}}</kbd>/.}}<!--
          Add the "insource:/\{\{ *"
          -->insource:/\{\{ *<!--


--><span class="plainlinks">[{{fullurl:Special:Search|search={{urlencode: 
          Add the "[Tt]".
hastemplate:{{{template|Val}}} <!-- hastemplate, an all-important filter.
          Save from an expensive, /regexp/i.
A filter is always recommended for, what is expected, an insource:/regexp pattern/.
          -->[{{#invoke:String|sub<!-- saw first [ of a "[Tt]-->
-->{{#if:{{{pattern|}}}<!-- Do insource. If no pattern, hastemplate is done.
          |{{uc:{{{template|{{{1|Template usage}}}}}}}}|1|1}}{{#invoke:String|sub
  -->| insource:/\{<!-- 1st a space. Start /\{regexp/ with escaped curly bracket.
          |{{lc:{{{template|{{{1|Template usage}}}}}}}}|1|1}}]{{#invoke:String|sub  
  -->[{{#invoke:String|sub<!--
          <!--                                               ^
  Now save from an expensive, /regexp/i, case-insensitive search
                                                    You saw ].  
  by outputing [Xx] where x is first letter of template name. -->
  |{{uc:{{{template|val}}}}}|1|1}}{{#invoke:String|sub
  |{{lc:{{{template|val}}}}}|1|1}}]{{#invoke:String|sub
  |{{{template|val}}}|2}}\{{!}}<!-- Template name and its pipe: \|, i.e. \{{!}}
  Trickiest part: [character class "any char NOT^ a } ] "one or more of"+.
  -->[^}]*<!-- Zero or more (*) of the [character class], "NO^ curly brackets".
  -->{{{pattern}}}/<!--User part: the sub-pattern regexp, match within template.
  And you see the ending / of the regexp/. 
-->}}<!-- end #if:pattern. No else part. Nothing to do if no pattern is given.
  There's always the hastemplate part, even if no insource:/regexp/ part.


  There's also always another filter, usually prefix, but defaults to intitle.
          Add "emplate", the rest of the template name, starting from char 2.-->
  Always add a filter to the search domain to make the search less expensive.
          |{{{template|{{{1|Template usage}}}}}}|2}}<!--  
  Never let all namespaces be searched at once because user defaults to that.
  Purpose of this template: make inefficient searches fast via tests/limits.
  Start with a space.
--> {{#if:{{{prefix|}}} |
  {{#switch:{{{prefix}}}
    |#default = prefix:{{{prefix}}}
    |n = prefix:{{NAMESPACE}}:
    |0|: = prefix:{{ns:0}}:
    |1 = prefix:{{ns:1}}:
    |2 = prefix:{{ns:2}}:
    |3 = prefix:{{ns:3}}:
    |4 = prefix:{{ns:4}}:
    |5 = prefix:{{ns:5}}:
    |6 = prefix:{{ns:6}}:
    |7 = prefix:{{ns:7}}:
    |8 = prefix:{{ns:8}}:
    |9 = prefix:{{ns:9}}:
    |10 = prefix:{{ns:10}}:
    |11 = prefix:{{ns:11}}:
    |12 = prefix:{{ns:12}}:
    |13 = prefix:{{ns:13}}:
    |14 = prefix:{{ns:14}}:
    |15 = prefix:{{ns:15}}:
    |100 = prefix:{{ns:100}}:
    |101 = prefix:{{ns:101}}:
    |108 = prefix:{{ns:108}}:
    |109 = prefix:{{ns:109}}:
    |118 = prefix:{{ns:118}}:
    |119 = prefix:{{ns:119}}:
  }}<!-- else if prefix not given, filter down to current page name
  -->| intitle:{{FULLPAGENAME}}}}}}</span> Perform a search {{#if:{{{pattern|}}}
| within all instances of | for }} template {{ucfirst: {{{template|val}}}}} ] <!--


DONENow inform the user what the search link does.
          Add the tricky regexp part.
          --> *\{{!}}[^}]*<!-- optional space " *" around initial pipe
          initial pipe is \|, i.e. \{{!}}
          Trickiest part: [character class] inverted with ^: [^any char NOT }]
          Zero or more (*) of those "non-curly brackets".
          All this stuff always matches, shows in bold in the search results


It starts the search domain in the current page "fullpagename",
          Add the users regexp pattern part and closing /.
that is a specific page or personal sandbox.  Hone the regexp  
          -->{{{pattern|{{{2|''regexp''}}}}}}/<!--
before releasing it into the wild.
Use ":" for main, "n" for current namespace.


--> {{#switch:{{{prefix|{{FULLPAGENAME}}}}}
          Add "prefix:" You see the space before it.
|{{FULLPAGENAME}} = on just this page.
          --> prefix:<!--
|:|0 = in the main namespace.
          -->{{#switch:<!-- add namespace "numbers and letters" recognition -->
|n = in the {{NAMESPACE}} namespace.
            {{{prefix|{{{3|}}}}}}
|1 = in the {{ns:1}} namespace.
            |#default = {{{prefix|{{{3|{{FULLPAGENAME}}}}}}}}
|2 = in the {{ns:2}} namespace.
            |n = {{NAMESPACE}}
|3 = in the {{ns:3}} namespace.
            |0|: = :
|4 = in the {{ns:4}} namespace.
            |1 = {{ns:1}}:
|5 = in the {{ns:5}} namespace.
            |2 = {{ns:2}}:
|6 = in the {{ns:6}} namespace.
            |3 = {{ns:3}}:
|7 = in the {{ns:7}} namespace.
            |4 = {{ns:4}}:
|8 = in the {{ns:8}} namespace.
            |5 = {{ns:5}}:
|9 = in the {{ns:9}} namespace.
            |6 = {{ns:6}}:
|10 = in the {{ns:10}} namespace.
            |7 = {{ns:7}}:
|11 = in the {{ns:11}} namespace.
            |8 = {{ns:8}}:
|12 = in the {{ns:12}} namespace.
            |9 = {{ns:9}}:
|13 = in the {{ns:13}} namespace.
            |10 = {{ns:10}}:
|14 = in the {{ns:14}} namespace.
            |11 = {{ns:11}}:
|15 = in the {{ns:15}} namespace.
            |12 = {{ns:12}}:
|100 = in the {{ns:100}} namespace.
            |13 = {{ns:13}}:
|101 = in the {{ns:101}} namespace.
            |14 = {{ns:14}}:
|108 = in the {{ns:108}} namespace.
            |15 = {{ns:15}}:
|109 = in the {{ns:109}} namespace.
            |100 = {{ns:100}}:
|118 = in the {{ns:118}} namespace.
            |101 = {{ns:101}}:
|119 = in the {{ns:119}} namespace.
            |118 = {{ns:118}}:
|#default = in all titles starting with the characters "{{{prefix}}}".
            |119 = {{ns:119}}:
}}</onlyinclude>
            |710 = {{ns:710}}:
            |711 = {{ns:711}}:
            |828 = {{ns:828}}:
            |829 = {{ns:829}}:
          }}
        }}<!-- End urlencode. -->
      }}<!-- End fullurl
    url done
    Now for name param of plainlinks.
 
  Appearance of link looks just like the query, unless labeled.
  So we're rebuilding the query just for show this time. -->
  |name = <!-- for commentary see duplicate above -->
    {{#if:
      {{{label|{{{4|}}}}}}
      |{{{label|{{{4}}}}}}
      |{{#if:
        {{{prefix|{{{3|}}}}}}
 
        |hastemplate:"{{{template|{{{1|Template usage}}}}}}" <!--
        -->insource:/\{\{ *<!--
        -->&#91;{{#invoke:String|sub<!-- saw first [ of a "[Tt]"  -->
          |{{uc:{{{template|{{{1|Template usage}}}}}}}}|1|1}}{{#invoke:String|sub
          |{{lc:{{{template|{{{1|Template usage}}}}}}}}|1|1}}&#93;{{#invoke:String|sub
          |{{{template|{{{1|Template usage}}}}}}|2}}<!--    ^
        --> *\{{!}}&#91;^}&#93;*<!-- optional space " *" around initial pipe
        -->{{#invoke:String|replace
          |{{#invoke:String|replace
            |{{{pattern|{{{2|''regexp''}}}}}}<!-- Given pattern
          -->|[|&#91;}}<!-- Replace any/all [ with HTML symbol
        -->|]|&#93;}}/<!-- replace any/all ] with there HTML symbol
        --> prefix:<!--
        -->{{#switch:<!-- add namespace "numbers and letters" recognition -->
          {{{prefix|{{{3|}}}}}}
          |#default = {{{prefix|{{{3|{{FULLPAGENAME}}}}}}}}
          |n = {{NAMESPACE}}
          |0|: = <nowiki />:
          |1 = {{ns:1}}:
          |2 = {{ns:2}}:
          |3 = {{ns:3}}:
          |4 = {{ns:4}}:
          |5 = {{ns:5}}:
          |6 = {{ns:6}}:
          |7 = {{ns:7}}:
          |8 = {{ns:8}}:
          |9 = {{ns:9}}:
          |10 = {{ns:10}}:
          |11 = {{ns:11}}:
          |12 = {{ns:12}}:
          |13 = {{ns:13}}:
          |14 = {{ns:14}}:
          |15 = {{ns:15}}:
          |100 = {{ns:100}}:
          |101 = {{ns:101}}:
          |118 = {{ns:118}}:
          |119 = {{ns:119}}:
          |710 = {{ns:710}}:
          |711 = {{ns:711}}:
          |828 = {{ns:828}}:
          |829 = {{ns:829}}:
        }}
      |{{#invoke:String|replace
          |{{#invoke:String|replace
            |'''Testing''' <kbd>{{{pattern|{{{2}}}}}}</kbd> '''on this page'''<!--
          -->|[|&#91;}}<!-- Replace any/all [ with HTML symbol
        -->|]|&#93;}}<!-- replace any/all ] with there HTML symbol-->
      }}
  }}
}}<!-- End of plainlinks
--></onlyinclude><noinclude>{{Documentation}}</noinclude>

Latest revision as of 20:49, 24 January 2026

Testing {{{2}}} on this page