Template:Link

From BITPlan can4eve Wiki
Jump to navigation Jump to search

template purpose

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

Motivation

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

WikiSon Link

Motivation

The Concept behind a link is

This calls for the WikiSon notation

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

Link as WikiSon

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

Importance

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


Examples

{{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 [2]

{{Link|target=http://partner.bitplan.com|title=BITPlan Partner wiki}}

external link with title BITPlan Partner wiki

implementation

Prerquisite

LocalSettings.php needs to have the StringFunctions enabled:

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

Template source

The complexity of this template macro needs to be hidden

original Link Template
{{#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

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

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

Categorie:Link