Difference between revisions of "Template:Link"

From BITPlan Wiki
Jump to navigation Jump to search
m (transfered by WikiBackup wikiTask at 2016-02-12T15:55:54Z)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<noinclude><!-- THIS FILE IS PROTECTED - smartGENERATOR WILL NOT OVERWRITE IT -->{{TemplateSequence
 
<noinclude><!-- THIS FILE IS PROTECTED - smartGENERATOR WILL NOT OVERWRITE IT -->{{TemplateSequence
|prev=Template:Language
+
|prev=Template:Languagelink
|next=Template:PageSequence
+
|next=Template:MdiIcon
 
}}
 
}}
 
== template purpose ==
 
== template purpose ==
Line 102: Line 102:
 
{{Link
 
{{Link
 
|target=sometarget
 
|target=sometarget
|text=sometext
+
|title=sometitle
 
}}
 
}}
 
</pre>
 
</pre>
 +
 
=== Link as WikiSon ===
 
=== Link as WikiSon ===
 
Using the WikiSon Concept approach the Link Concept is represented via
 
Using the WikiSon Concept approach the Link Concept is represented via
Line 110: Line 111:
 
Especially there is a [[List of Links]] page available.
 
Especially there is a [[List of Links]] page available.
  
=== Importance ===
+
Properties set:
this is a fundamental concept should not be broken. Therefore
+
* {{Link|target=Property:Link targetUrl}}
{{Fixme|todo=This template needs to be protected soon|done=true}}
 
{{Fixme|todo=This template needs to be distributed in the smartMediaWiki network of wikis|done=false}}
 
  
 
=== Examples ===
 
=== Examples ===
Line 145: Line 144:
  
 
=== implementation ===
 
=== implementation ===
==== Prerquisite ====
+
==== Prerequisite ====
 
LocalSettings.php needs to have the StringFunctions enabled:
 
LocalSettings.php needs to have the StringFunctions enabled:
 
<source lang='php'>
 
<source lang='php'>
Line 152: Line 151:
 
$wgPFEnableStringFunctions=true;
 
$wgPFEnableStringFunctions=true;
 
</source>
 
</source>
 +
 
==== Template source ====
 
==== Template source ====
 
The complexity of this template macro needs to be hidden
 
The complexity of this template macro needs to be hidden
Line 238: Line 238:
 
}}
 
}}
 
</pre>
 
</pre>
 
+
=== Properties set ===
 +
# {{Link|target=Property:Link_target}}
 +
# {{Link|target=Property:Link_targetPage}}
 +
# {{Link|target=Property:Link_targetUrl}}
 +
# {{Link|target=Property:Link_title}}
 
[[Categorie:Link]]
 
[[Categorie:Link]]
 
[[Category:Template]]</noinclude><includeonly>{{#set:Link target={{{target|}}}
 
[[Category:Template]]</noinclude><includeonly>{{#set:Link target={{{target|}}}

Latest revision as of 05:37, 7 December 2019

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.

Properties set:

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

Prerequisite

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ë
}}

Properties set

  1. Property:Link_target
  2. Property:Link_targetPage
  3. Property:Link_targetUrl
  4. Property:Link_title

Categorie:Link