Link


template purpose[edit]

This is a Template for internal and external Links in WikiSon notation.

Motivation[edit]

In Mediawiki there are at least five different ways to use a link - we'd like to hide this complexity and add new functionality:

  1. [[Main Page]]
    Main Page - internal link with no text
  2. [[Main Page|Start Page]]
    Start Page - internal link with text
  3. [http://partner.bitplan.com] 
    [1] - external link as footnote
  4. [http://partner.bitplan.com BITPlan partner site] 
    BITPlan partner site - external link with text
  5. http://partner.bitplan.com 
    http://partner.bitplan.com - automatic external link

Motivation[edit]

The Concept behind a link is

This calls for the WikiSon notation

{{Link
|target=sometarget
|title=sometitle
}}

Link as WikiSon[edit]

Using the WikiSon Concept approach the Link Concept is represented via the Wiki Category:Link
Especially there is a List of Links page available.

Properties set:

Examples[edit]

{{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

implementation[edit]

Prerequisite[edit]

LocalSettings.php needs to have the StringFunctions enabled:

# WF 2015-01-20
# allow string functions
$wgPFEnableStringFunctions=true;

Template source[edit]

The complexity of this template macro needs to be hidden

original Link Template[edit]
{{#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]]
pretty printed Template macro[edit]

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]]

How the Link Macro works[edit]

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:

Substring[edit]
{{#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 exists and non empty[edit]
{{#if: test string | value if test string is not empty | value if test string is empty (or only white space) }}
if equals[edit]
{{#ifeq: string 1 | string 2 | value if identical | value if different }}
setting Semantic values[edit]
{{#set:Has population=2,234,105
|Located in country=France
|Has mayor=Bertrand Delanoë
}}
🖨 🚪