Template:Clean URL: Difference between revisions

From stencil.wiki
No edit summary
No edit summary
 
(27 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<noinclude>{{clean URL|http://shop.colourcodeprinting.com/}}</noinclude><includeonly>[{{#rmatch:{{{1|}}}|/^http:\/\/(.+?)\/$/|$0}} {{#rmatch:{{{1|}}}|/^http:\/\/(.+?)\/$/|$0}}]</includeonly>
<!-- This should probably become a Lua module at some point, the #if chaining is going to get cumbersome if too many more patterns are added --><noinclude>
This template cleans up the display of external URLs, to simplify how they are shown on the wiki.
 
== Usage ==
The URL should be passed as the only parameter of template. While the link itself will remain unchanged, the protocol, subdomains of www, and trailing slashes will all be cut from the text displayed.
 
<pre>{{clean URL|https://www.riso.co.jp/}}</pre>
{{clean URL|https://www.riso.co.jp/}}
 
=== Pattern recognition ===
Certain domains are recognized by this template, with custom simplification. ''This template can be edited to facilitate additional pattern matches as needed.''
 
==== Instagram ====
<pre>{{clean URL|https://www.instagram.com/risokagaku/}}</pre>
{{clean URL|https://www.instagram.com/risokagaku/}}
<pre>{{clean URL|@risokagaku}}</pre>
{{clean URL|@risokagaku}}
 
==== Archive.org ====
<pre>{{clean URL|https://web.archive.org/web/19990508115212/http://www4.mediagalaxy.co.jp/riso/}}</pre>
{{clean URL|https://web.archive.org/web/19990508115212/http://www4.mediagalaxy.co.jp/riso/}}
 
==== Missing HTTP or HTTPS:// ====
<pre>{{clean URL|www.riso.co.jp/}}</pre>
{{clean URL|www.riso.co.jp/}}
 
== Known issues ==
This template is primarily used to process URLs which are themselves ''parameters from other templates''—it's usually called in a format like <code><nowiki>{{clean URL|{{{1}}}}}</nowiki></code>. However, when it is called directly on a URL, if that address contains protected MediaWiki characters like <code>|</code> and <code>=</code> (very common in URLs with parameters) it will break the template call. In these cases you must first escape these characters.
 
== TemplateData ==
<templatedata>
{
"params": {
"1": {
"label": "URL",
"description": "The URL to clean",
"type": "url",
"required": true
}
},
"description": "An external URL display simplifier."
}
</templatedata>
</noinclude><includeonly><!--
-->{{#ifexpr:{{#invoke:String|find|{{lc:{{{1|}}}}}|instagram.com}}>0
  |[{{{1|}}} @{{#rmatch:{{{1|}}}|/^(?:https?:\/\/)?(?:www\.)?(?:instagram.com\/)([a-zA-Z0-9\._]+)/|\1}}]
  |{{#ifexpr:{{#invoke:String|find|{{lc:{{{1|}}}}}|@}}>0
    |[https://instagram.com/{{#rreplace:{{{1|}}}|@|}}/ {{{1|}}}]
    |{{#ifexpr:{{#invoke:String|find|{{lc:{{{1|}}}}}|archive.org}}>0
      |[{{{1|}}} <nowiki>[archived]</nowiki>]
      |{{#ifexpr: {{#invoke:String|find|{{lc:{{{1|}}}}}|http}} or {{#invoke:String|find|{{lc:{{{1|}}}}}|https}}
        |[{{{1|}}} {{#rmatch:{{{1|}}}|/^(?:https?:\/\/)?(?:www\.)?(.+?)\/?$/|\1}}]
        |[https://{{{1}}} {{#rmatch:{{{1|}}}|/^(?:https?:\/\/)?(?:www\.)?(.+?)\/?$/|\1}}]
      }}
    }}
  }}
}}</includeonly>

Latest revision as of 00:07, 9 January 2025

This template cleans up the display of external URLs, to simplify how they are shown on the wiki.

Usage

The URL should be passed as the only parameter of template. While the link itself will remain unchanged, the protocol, subdomains of www, and trailing slashes will all be cut from the text displayed.

{{clean URL|https://www.riso.co.jp/}}

riso.co.jp

Pattern recognition

Certain domains are recognized by this template, with custom simplification. This template can be edited to facilitate additional pattern matches as needed.

Instagram

{{clean URL|https://www.instagram.com/risokagaku/}}

@risokagaku

{{clean URL|@risokagaku}}

@risokagaku

Archive.org

{{clean URL|https://web.archive.org/web/19990508115212/http://www4.mediagalaxy.co.jp/riso/}}

[archived]

Missing HTTP or HTTPS://

{{clean URL|www.riso.co.jp/}}

riso.co.jp

Known issues

This template is primarily used to process URLs which are themselves parameters from other templates—it's usually called in a format like {{clean URL|{{{1}}}}}. However, when it is called directly on a URL, if that address contains protected MediaWiki characters like | and = (very common in URLs with parameters) it will break the template call. In these cases you must first escape these characters.

TemplateData

An external URL display simplifier.

Template parameters[Edit template data]

ParameterDescriptionTypeStatus
URL1

The URL to clean

URLrequired