Template:URL: Difference between revisions

From Vigyanwiki
Template>Verdy p
m (simplify tests for presence of parameter 2, and of the titleparts limitation and its work-round ; additional fix for "ftp://" URLs)
m (53 revisions imported from alpha:Template:URL)
 
(36 intermediate revisions by 22 users not shown)
Line 1: Line 1:
<includeonly>{{#if:{{{1|}}}|<!--
<includeonly>{{#invoke:URL|url}}</includeonly>{{#invoke:Check for unknown parameters|check|unknown={{main other|[[Category:Pages using URL template with unknown parameters|_VALUE_{{PAGENAME}}]]}}|preview=Page using [[Template:URL]] with unknown parameter "_VALUE_"|ignoreblank=y | 1 | 2 }}<noinclude>{{documentation}}</noinclude>
  --><span class="url"><!--
  -->{{#ifeq:{{#titleparts:{{{1|}}}|1|1}}|{{{1|}}}|<!-- work-around when titleparts doesn't accept the URL and returns the full string instead: don't attempt to transform the displayed URL
      -->[{{#if:1|{{{1|}}}}}]<!-- This #if:1 allows trimming leading spaces in the full URL: {{{1|}}}
  -->|<!--
      -->{{#switch:{{lc:{{#titleparts:{{{1|}}}|2}}}}<!--
      -->|https:/<!--
      -->|http:/<!--
      -->|ftp:/=<!-- an FTP URL is a valid URI scheme and MUST NOT imply a default "http://" (as generated in the #default case)
        -->[{{#if:1|{{{1|}}}}} <!-- This #if:1 allows trimming leading spaces in the full URL: {{{1|}}}
        -->{{#if:{{{2|}}}|{{#if:1|{{{2|}}}}}| <!-- This #if:1 allows trimming leading spaces in the specified display text : {{{2|}}}
            -->{{lc:<!-- domain name in lowercase
              -->{{#ifeq:{{lc:{{padleft:|4|{{#titleparts:{{{1|}}}|1|3}}}}}}|www.<!--
              -->|{{Str right|{{#titleparts:{{{1|}}}|1|3}}|4}}<!--
              -->|{{#titleparts:{{{1|}}}||3}}<!--
              -->}}<!--
            -->}}<!--
            -->{{#if:{{#titleparts:{{{1|}}}||4}}<!-- rest of the ressource path
            -->|/{{#titleparts:{{{1|}}}||4}}<!--
            -->}}<!--
        -->}}<!--
        -->]<!--
      -->|#default=<!-- Warning! this case implies a default "http://" URI scheme, and should NOT occur if there's another accepted URI scheme in the URL
        -->[http://{{#if:1|{{{1|}}}}} <!-- This #if:1 allows trimming leading spaces in the full URL: {{{1|}}}
        -->{{#if:{{{2|}}}|{{#if:1|{{{2|}}}}}| <!-- This #if:1 allows trimming leading spaces in the specified display text : {{{2|}}}
            -->{{lc:<!-- domain name in lowercase
              -->{{#ifeq:{{lc:{{padleft:|4|{{#titleparts:{{{1|}}}|1|1}}}}}}|www.<!--
              -->|{{Str right|{{#titleparts:{{{1|}}}|1|1}}|4}}<!--
              -->|{{#titleparts:{{{1|}}}|1|1}}<!--
              -->}}<!--
            -->}}<!--
            -->{{#if:{{#titleparts:{{{1|}}}||2}}<!-- rest of the ressource path
            -->|/{{#titleparts:{{{1|}}}||2}}<!--
            -->}}<!--
        -->}}<!--
        -->]<!--
      -->}}<!--
  --></span><!--
-->|{{tlx|URL|example.com}}<!--
-->}}</includeonly><noinclude>{{documentation}}</noinclude>

Latest revision as of 15:16, 22 December 2022

Template documentation