模板:Link
template purpose
This is a Template for internal and external Links in WikiSon notation.
Help
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:
[[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 texthttp://partner.bitplan.com
http://partner.bitplan.com - automatic external link
WikiSon Link
Motivation
The Concept behind a link is <uml> Class Link { target title } ' BITPlan Corporate identity skin params ' Copyright (c) 2015 BITPlan GmbH ' see http://wiki.bitplan.com/PlantUmlSkinParams#BITPlanCI ' skinparams generated by com.bitplan.restmodelmanager hide Circle skinparam note{
BackGroundColor #FFFFFF FontSize 14 ArrowColor #FF8000 BorderColor #FF8000 FontColor black FontName Technical
}
skinparam component{
BackGroundColor #FFFFFF FontSize 14 ArrowColor #FF8000 BorderColor #FF8000 FontColor black FontName Arial
}
skinparam package{
BackGroundColor #FFFFFF FontSize 14 ArrowColor #FF8000 BorderColor #FF8000 FontColor black FontName Arial
}
skinparam usecase{
BackGroundColor #FFFFFF FontSize 14 ArrowColor #FF8000 BorderColor #FF8000 FontColor black FontName Arial
}
skinparam activity{
BackGroundColor #FFFFFF FontSize 14 ArrowColor #FF8000 BorderColor #FF8000 FontColor black FontName Arial
}
skinparam classAttribute{
BackGroundColor #FFFFFF FontSize 14 ArrowColor #FF8000 BorderColor #FF8000 FontColor black FontName Technical
}
skinparam interface{
BackGroundColor #FFFFFF FontSize 14 ArrowColor #FF8000 BorderColor #FF8000 FontColor black FontName Arial
}
skinparam class{
BackGroundColor #FFFFFF FontSize 14 ArrowColor #FF8000 BorderColor #FF8000 FontColor black FontName Technical
} </uml> This calls for the WikiSon notation
{{Link |target=sometarget |text=sometext }}
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 模板:Fixme 模板:Fixme
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: https://www.mediawiki.org/wiki/Extension:StringFunctions/en#.23sub:
- #ifeq: https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions/en#.23ifeq
- #if: https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions/en#.23if
- #set: https://semantic-mediawiki.org/wiki/Help:Setting_values
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ë }}
SMW PageSchema use
generated version of this template
< noinclude> Dies ist die Vorlage „Link“. Sie sollte im folgenden Format genutzt werden: < pre> {{Link |target= |title= }} </ pre> Klick auf „Bearbeiten“, um den Quelltext der Vorlage anzusehen. </ noinclude>< includeonly>{| class="wikitable" ! target | [[Link_target::{{{target|}}}]] |- ! title | [[Link_title::{{{title|}}}]] ... |} [[Kategorie:Link]] </ includeonly>