Jump to content

Template:Template usage: Difference between revisions

From Fifth Empire Wiki
minor fix
version 2 looks like search link, but can also act with a "Testing regexp" phase
Line 1: Line 1:
<onlyinclude>{{#switch: {{{prefix|{{FULLPAGENAME}}}}}
<!-- for curly brackets code-matching ignore [^{], \{{!}}, and insource:/{}
--><onlyinclude>{{#if:  
{{{pattern|}}}
| <!-- PATTERN true -->
  {{#if:
  {{{prefix|}}}
  | <!-- PREFIX AND PATTERN true, Plainlinks #1


|{{FULLPAGENAME}} = Phase one of two: '''a test regexp''' /<kbd>{{{pattern}}}</kbd>/.
    -->{{plain link | url = {{fullurl:Special:Search|search={{urlencode: 
    hastemplate:"{{{template|Val}}}" <!-- hastemplate, an all-important filter.
    A filter is always recommended for what this template is built for,
    an insource:/regexp pattern/.  But there's always the hastemplate part,
    even if no insource:/regexp/ part.


|#default = Readied '''a tested regexp''' /<kbd>{{{pattern}}}</kbd>/.}}<!--
    --> insource:/{<!-- 1st a space. Start /{regexp/ with curly bracket.
    You saw the starting / of the /regexp/.


--><span class="plainlinks">[{{fullurl:Special:Search|search={{urlencode: 
    -->[{{#invoke:String|sub<!-- first [ of "[Xx]"
hastemplate:{{{template|Val}}} <!-- hastemplate, an all-important filter.
    Now save from an expensive, /regexp/i, case-insensitive search  
A filter is always recommended for, what is expected, an insource:/regexp pattern/.
    by outputing [Xx] where x is first letter of template name. -->
-->{{#if:{{{pattern|}}}<!-- Do insource. If no pattern, hastemplate is done.
    |{{uc:{{{template|val}}}}}|1|1}}{{#invoke:String|sub
  -->| insource:/\{<!-- 1st a space. Start /{regexp/ with curly bracket.
    |{{lc:{{{template|val}}}}}|1|1}}]{{#invoke:String|sub
  -->[{{#invoke:String|sub<!--
    |{{{template|val}}}|2}}\{{!}}<!-- Template name and its pipe: \|, i.e. {{!}}
  Now save from an expensive, /regexp/i, case-insensitive search  
    Trickiest part: [character class] inverted with ^:  [^any char NOT }]  
  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.
    -->[^}]*<!-- Zero or more (*) All this shows in bold in the search results
  Always add a filter to the search domain to make the search less expensive.
   
  Never let all namespaces be searched at once because user defaults to that.
    -->{{{pattern}}}/<!--User part: last part of regexp, shows in bold too.
  Purpose of this template: make inefficient searches fast via tests/limits.
    You saw the ending / of the /regexp/.
  Start with a space.
    You see the the space before prefix next:
--> {{#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
-->| prefix:{{FULLPAGENAME}}
    }}<!-- end #if -->
  }} <!-- end urlencode -->
}}<!-- end fullurl  --> </span> Perform a search {{#if:
{{{pattern|}}}
| within all instances of  
| for }} template {{ucfirst: {{{template|val}}}}} ] <!--


DONE. Now inform the user what the search link does.
    --> prefix:{{#switch:{{{prefix}}}
        |#default = {{{prefix}}}
        |n = {{NAMESPACE}}:
        |0|: = {{ns:0}}:
        |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}}:
        |108 = {{ns:108}}:
        |109 = {{ns:109}}:
        |118 = {{ns:118}}:
        |119 = {{ns:119}}:
      }}
    }}<!-- saw end urlencode -->
    }}<!-- end fullurl  
    For show, appearance of link looks just like the query: -->


It starts the search domain in the current page "fullpagename",
    | name = {{{name|hastemplate:"{{{template|Val}}}"<!--
that is a specific page or personal sandbox. Hone the regexp
    --> insource:/{<!--
before releasing it into the wild. 
    -->{{#invoke:String|sub
Use ":" for main, "n" for current namespace.
    |{{uc:{{{template|val}}}}}|1|1}}{{#invoke:String|sub
    |{{lc:{{{template|val}}}}}|1|1}}]{{#invoke:String|sub
    |{{{template|val}}}|2}}\{{!}}<!--
    -->[^}]*<!--
    -->{{{pattern}}}/<!-- Namespace numbers need upkeep
    --> prefix:{{#switch:{{{prefix}}}
        |#default = {{{prefix}}}
        |n = {{NAMESPACE}}:
        |0|: = {{ns:0}}:
        |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}}:
        |108 = {{ns:108}}:
        |109 = {{ns:109}}:
        |118 = {{ns:118}}:
        |119 = {{ns:119}}:
      }}}}}<!-- three extra brackets due to {{{name}}} -->
    }}<!-- End of plainlinks #1, true true


--> {{#switch:{{{prefix|{{FULLPAGENAME}}}}}
  -->| <!-- PREFIX now false, PATTERN still true -->
|{{FULLPAGENAME}} = on just this page.
    {{plain link <!-- plainlinks #2 -->
|:|0 = in the main namespace.
      | url =
|n = in the {{NAMESPACE}} namespace.
        {{fullurl:
|1 = in the {{ns:1}} namespace.
          Special:Search
|2 = in the {{ns:2}} namespace.
          |search={{urlencode: 
|3 = in the {{ns:3}} namespace.
            hastemplate:"{{{template|Val}}}" insource:/{<!--
|4 = in the {{ns:4}} namespace.
            -->{{#invoke:String|sub
|5 = in the {{ns:5}} namespace.
            |{{uc:{{{template|val}}}}}|1|1}}{{#invoke:String|sub
|6 = in the {{ns:6}} namespace.
            |{{lc:{{{template|val}}}}}|1|1}}]{{#invoke:String|sub
|7 = in the {{ns:7}} namespace.
            |{{{template|val}}}|2}}\{{!}}<!--
|8 = in the {{ns:8}} namespace.
            -->[^}]*<!--
|9 = in the {{ns:9}} namespace.
            -->{{{pattern}}}/<!--
|10 = in the {{ns:10}} namespace.
            --> prefix:{{FULLPAGENAME}}
|11 = in the {{ns:11}} namespace.
          }}
|12 = in the {{ns:12}} namespace.
        }}
|13 = in the {{ns:13}} namespace.
      | name = {{{name|Test regexp. Locate {{{template|Val}}}}}}
|14 = in the {{ns:14}} namespace.
    }}<!-- end plainlinks #2 -->
|15 = in the {{ns:15}} namespace.
  }}<!-- end first nested #if:prefix  -->
|100 = in the {{ns:100}} namespace.
| <!-- PATTERN false -->
|101 = in the {{ns:101}} namespace.
  {{#if: <!-- start second nested #if:prefix -->
|108 = in the {{ns:108}} namespace.
  {{{prefix|}}}
|109 = in the {{ns:109}} namespace.
  | <!-- PATTERN false PREFIX true -->
|118 = in the {{ns:118}} namespace.
    {{plain link <!-- plainlinks #3 -->
|119 = in the {{ns:119}} namespace.
      | url =
|#default = in all titles starting with the characters "{{{prefix}}}".
        {{fullurl:
}}</onlyinclude>
          Special:Search
          |search={{urlencode: 
            hastemplate:"{{{template|Val}}}" prefix:{{{prefix}}}<!--
            --> prefix:{{#switch:{{{prefix}}}
            |#default = {{{prefix}}}
            |n = {{NAMESPACE}}:
            |0|: = {{ns:0}}:
            |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}}:
            |108 = {{ns:108}}:
            |109 = {{ns:109}}:
            |118 = {{ns:118}}:
            |119 = {{ns:119}}:
            }}
          }}
        }}
      | name =
      {{{name|hastemplate:"{{{template|Val}}}"<!--
      --> prefix:{{#switch:{{{prefix}}}
      |#default = {{{prefix}}}
      |n = {{NAMESPACE}}:
      |0|: = {{ns:0}}:
      |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}}:
      |108 = {{ns:108}}:
      |109 = {{ns:109}}:
      |118 = {{ns:118}}:
      |119 = {{ns:119}}:
      }}}}}<!-- three extra brackets due to {{{name}}} -->
    }} <!-- end plainlinks #3
  -->| <!-- PREFIX now false, PATTERN still false -->
    {{plain link <!-- plainlinks #4 -->
      | url =
        {{fullurl:
          Special:Search
          |search={{urlencode: 
            hastemplate:"{{{template|Val}}}"
          }}
        }}
      | name = {{{name|hastemplate:"{{{template|Val}}}"}}}
    }} <!-- end plainlinks #4 -->
  }} <!-- end of second nested #if:prefix -->
}}</onlyinclude><!-- end of first, opening #if:pattern -->
<noinclude>{{Documentation}}</noinclude>
<noinclude>{{Documentation}}</noinclude>

Revision as of 20:15, 29 June 2015

hastemplate:"Val"