This is a Template for internal and external Links in WikiSon notation.
In Mediawiki there are at least five different ways to use a link - we'd like to hide this complexity and add new functionality:
[[Main Page]]Main Page - internal link with no text
[[Main Page|Start Page]]Start Page - internal link with text
[http://partner.bitplan.com][1] - external link as footnote
[http://partner.bitplan.com BITPlan partner site]BITPlan partner site - external link with text
http://partner.bitplan.comhttp://partner.bitplan.com - automatic external link
The Concept behind a link is
This calls for the WikiSon notation
{{Link |target=sometarget |title=sometitle }}
Using the WikiSon Concept approach the Link Concept is represented via
the Wiki Category:Link
Especially there is a List of Links page available.
this is a fundamental concept should not be broken. Therefore
done | true |
---|---|
todo | This template needs to be protected soon |
done | false |
---|---|
todo | This template needs to be distributed in the smartMediaWiki network of wikis |
{{Link}}
internal default link to Main Page Main Page
{{Link|target=Main Page}}
internal link to Main Page Main Page
{{Link|target=Main Page|title=Main Page}}
internal link to Main Page with title Main Page
{{Link|target=http://partner.bitplan.com}}
external link [1]
{{Link|target=http://partner.bitplan.com|title=BITPlan Partner wiki}}
external link with title BITPlan Partner wiki
LocalSettings.php needs to have the StringFunctions enabled:
# WF 2015-01-20
# allow string functions
$wgPFEnableStringFunctions=true;
The complexity of this template macro needs to be hidden
{{#set:Link target={{{target|}}} |Link title={{{title|}}} }}{{#ifeq: {{#sub:{{{target|}}}|0|4}} | http | {{#set:Link targetUrl={{{target|}}}}}{{#if: {{{title|}}} | [{{{target|http://www.smartMediaWiki.com}}} {{{title}}}] | [{{{target|http://www.smartMediaWiki.com}}}] }}| {{#set:Link targetPage={{{target|}}}}}{{#if: {{{title|}}} | [[{{{target|Main Page}}}|{{{title}}}]] | [[{{{target|Main Page}}}]] }}}}[[Category:Link]]
this version would unfortunately create unwanted newlines in the macro result
<!-- set concept attributes target (mandatory) and title (optional) -->
{{#set:Link target={{{target|}}}
|Link title={{{title|}}}
}}
<!-- check whether link is external or internal by comparing the firsts 4 chars with "http" -->
{{#ifeq:
{{#sub:{{{target|}}}|0|4}}
| http
| <!-- in the http case (external link) set the targetURL property - it has the type "URL" and not "Text" like target or "Page" like targetPage -->
{{#set:Link targetUrl={{{target|}}}}}
<!-- display external link with our without title -->
{{#if: {{{title|}}}
| [{{{target|http://www.smartMediaWiki.com}}} {{{title}}}]
| [{{{target|http://www.smartMediaWiki.com}}}]
}}
| <!-- in the non-http case (internal link) set the targetPage property - it has the type "Page" and not "Text" like target or "Url" like targetUrl -->
{{#set:Link targetPage={{{target|}}}}}
<!-- display internal link with our without title -->
{{#if: {{{title|}}}
| [[{{{target|Main Page}}}|{{{title}}}]]
| [[{{{target|Main Page}}}]]
}}
}}
<!-- set the Category so that any page using this is displayed in this category -->
[[Category:Link]]
The Link Macro checks whether the link is external or internal and displays the correct version. It sets the Link Concept's attributes by setting the correspond Semantic Media Wiki properties. it uses the following helper funcitons:
{{#sub:string|start|length}} The start parameter, if positive (or zero), specifies a zero-based index of the first character to be returned. Example: {{#sub:Icecream|3}} returns cream. {{#sub:Icecream|0|3}} returns Ice.
{{#if: test string | value if test string is not empty | value if test string is empty (or only white space) }}
{{#ifeq: string 1 | string 2 | value if identical | value if different }}
{{#set:Has population=2,234,105 |Located in country=France |Has mayor=Bertrand Delanoë }}