Benutzer:Andreas Plank/Vorlagenprogrammierung

Aus Offene Naturführer BiolFlor
Wechseln zu: Navigation, Suche

Programmierung

Wiki Transclusion

Jede Seite mit {{:Seitentitel}}. Siehe http://www.mediawiki.org/wiki/Transclusion.

Funktionen

Verschachteln immer mit Einrücken benutzten aber ohne versehentlich Leerzeichen einzufügen:

····················
<!-- 

 description
  -->{{#if: …<!--  
  then-->|<!-- 
  else-->|
  }}<!-- if: end  -->
<!-- 

 Erklärung
  -->{{#if: …<!--  
  dann -->|<!-- 
  sonst-->|
  }}<!-- if: end  -->
····················

Hinweis: ifelse-Konstrukte können auch erreicht werden durch verschachteln von Vorlagen-Parametern, d.h. der äußere überschreibt den inneren Parameter:

<!-- 
die folgende Verschachtelung …
  -->{{{result|{{{scientific name|}}}}}}<!-- 

  … ist dasselbe wie …

  -->{{#if: {{{result|}}}<!--  
  dann -->|{{{result|}}}<!-- 
  sonst-->|{{{scientific name|}}}<!--
  -->}}<!-- 
-->

Jedoch funtioniert dies nicht wenn eine Vorlage leere Werte an eine zweite Vorlage weitergibt, weil selbst dann Werte mit „“ als „gesetzt“ interpretiert werden. Für diesen Fall muß mann dann ein {{#if: …}}-Konstrukt nehmen welches „“-Werte dann als FALSE oder „nicht gesezt“ korrekt interpretiert.

Ein Beispiel ohne beim Kommentieren versehentlich Leerzeichen einzufügen:

 <!--
------- Abschnitte kommentieren -------
 -->
 Wiki-Code
 <!--
=======================================
   Großer  Abschnitt kommentiert 
=======================================
 --><!-- 
  (start#switch) test
  -->{{#switch: {{{zu testende Vorlagenvariable}}}
     | Prüfwert = gebe zurück
     | {{{V-Variable_1|}}}{{{V-Variable_2|}}} = gebe zurück
     | gebe zurück Voreinstellung
     }}<!-- (end#switch)
  -->

Als Parameter funktionieren auch Berechnungen mit {{#expr: <ausdruck>}}:

Folgende {{PLURAL:$1|Seite ist|$1 Seiten sind}} in dieser Kategorie enthalten:
{{#expr:  }}
{{#ifexpr: 1 | is anything but zero | is 0}}
{{#ifexpr: 2 < 5 | <!-- :true --> | <!-- :false -->}}
{{#ifexist: Seitenname | <!-- exists --> | <!-- non existing -->}}
{{#if: {{{content|}}} | <!-- (content:true) ... --> | <!-- (content:false) ...-->}}
{{#if: {{{1|}}} | <!-- (1:true) ... --> | <!-- (1:false) ...-->}}
{{#ifeq: string 1 | string 2 | true | false }}

{{#switch:{{CONTENTLANGUAGE}}|#default=english...|de|de-formal=deutsch...}}
{{#switch:{{#var:var-name}}|#default=...|0|1=...}}

{{#var:var-name}}
{{#vardefine:index|{{#expr:{{#var:index}}+1}}}} +1 dazuaddieren
{{#if:{{#varexists:index}}|{{#vardefine:index|{{#expr:{{#var:index}}+1}}}}|{{#vardefine:index|1}}}}
{{#vardefine:var-name|var-value}}

{{lc:MACHE KleIN}} mache klein
{{uc:mache groß}} MACHE GROß
{{urlencode:Meine ÜRL}} Meine+%C3%9CRL
{{anchorencode:Meine Änchors}} Meine_.C3.84nchors
{{#titleparts:  Dies & das }}  Dies &amp; das

{{#arraymap:eins, zwei|,|<!-- temp-Variable -->§|<!-- Ausgabe temp-Variable -->§|<!-- neuer Trenner -->&#32;•&#32;}} → eins • zwei

Extrahiere Zeichenfolgen:

Test auf „:“ {{#sub:…|0|{{#pos:…|:|0}}}}
#rpos → -1 wenn nichts gefunden
#pos  → (leer) wenn nichts gefunden
{{#explode: Mein erstes zweites drittes Wort und ein Schlußwort| |1}} → erstes
{{#explode: Mein erstes zweites drittes Wort und ein Schlußwort| |-1}} → Schlußwort

Variablen

Siehe auch http://www.mediawiki.org/wiki/Help:Magic_words/de#Parser-Funktionen

__NOTOC__
__TOC__
{{fullurl:Category:Top level|action=edit}} https://offene-naturfuehrer.de/bfl/index.php?title=Kategorie:Top_level&action=edit
{{localurl:Category:Top level|action=render}}  /bfl/index.php?title=Kategorie:Top_level&action=render
{{filepath:Silhouettes_of_ferns.svg|nowiki}} https://species-id.net/o/media/1/1a/Silhouettes_of_ferns.svg
{{filepath:Silhouettes_of_ferns.svg}} https://species-id.net/o/media/1/1a/Silhouettes_of_ferns.svg
{{#titleparts:  {{TALKPAGENAME}}| 1 }}     Benutzer Diskussion:Andreas Plank
{{#titleparts:  {{FULLPAGENAME}}| 1 }}     Benutzer:Andreas Plank
{{#titleparts: {{FULLPAGENAME}} | <!-- wieviel /Titel/Titel/ --> 2 | <!-- welchen /Titel/Titel/ --> 2 }}
{{int:edit}}:      Bearbeiten (Systemnachrichten in )
{{SITENAME}}:      Offene Naturführer BiolFlor
{{SERVERNAME}}:    offene-naturfuehrer.de
{{FULLPAGENAME}}:  Benutzer:Andreas Plank/Vorlagenprogrammierung
{{PAGENAME}}:      Andreas Plank/Vorlagenprogrammierung
{{BASEPAGENAME}}:  Andreas Plank
{{TALKPAGENAME}}:  Benutzer Diskussion:Andreas Plank/Vorlagenprogrammierung
{{TALKSPACE}}:     Benutzer Diskussion
{{ARTICLESPACE}}:  Benutzer
{{SUBPAGENAME}}:   Vorlagenprogrammierung
{{Special:Allpages/Help:}}
{{Special:PrefixIndex/Benutzer:Andreas Plank/}} ergibt:
Andreas Plank/BashAndreas Plank/BilderAndreas Plank/Bilder drucken
Andreas Plank/Blender Tastenkombinationen Version 2.59Andreas Plank/FilmeAndreas Plank/Filter SMW
Andreas Plank/FormsAndreas Plank/FunktionenAndreas Plank/Heimische Kräuter
Andreas Plank/IdeenAndreas Plank/KnospenAndreas Plank/Kopiervorlagen
Andreas Plank/LinksAndreas Plank/LogAndreas Plank/MySQL
Andreas Plank/PythonAndreas Plank/Reguläre AusdrückeAndreas Plank/Schlüsselvorlagen
Andreas Plank/SedAndreas Plank/SilhouettenAndreas Plank/Tachina
Andreas Plank/Test 2Andreas Plank/TestsAndreas Plank/Videobearbeitung
Andreas Plank/VimAndreas Plank/VorlagenprogrammierungAndreas Plank/vector.css
Andreas Plank/vector.js


{{ns:Media}}:          Medium
{{ns:Special}}:        Spezial
{{ns:Talk}}:           Diskussion
{{ns:User}}:           Benutzer
{{ns:User_talk}}:      Benutzer Diskussion
{{ns:Project}}:        Offene Naturführer BiolFlor
{{ns:Project_talk}}:   Offene Naturführer BiolFlor Diskussion
{{ns:Image}}:          Datei
{{ns:Image_talk}}:     Datei Diskussion
{{ns:MediaWiki}}:      MediaWiki
{{ns:MediaWiki_talk}}: MediaWiki Diskussion
{{ns:Template}}:       Vorlage
{{ns:Template_talk}}:  Vorlage Diskussion
{{ns:Help}}:           Hilfe
{{ns:Help_talk}}:      Hilfe Diskussion
{{ns:Category}}:       Kategorie
{{ns:Category_talk}}:  Kategorie Diskussion


Gadgets/Helferlein

 MediaWiki:Gadget-HotCat
   Hinweistext
 MediaWiki:Gadget-HotCat.js
   JavaScript
 MediaWiki:Gadget-HotCat.css
   CSS

 MediaWiki:Gadgets-definition
   Alle Definitionen: was wo + welche Skripte + MeinDefinierterAbschnitt
   HotCat|HotCat.js
   …
   HotCat|HotCat.css|HotCat.js

 MediaWiki:Gadget-section-MeinDefinierterAbschnitt
  → "Benutzte Überschrift"

Pfeile/Sonderzeichen

0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
0x2190
0x21a0
0x21b0
0x21c0
0x21d0
0x21e0
0x21f0
 ⌜⌝⌞⌟
 ⌌⌍⌎⌏ ⌢⌣
 ┌┬─┐
 ││ │
 ├┼─┤
 └┴─┘


Load Resource loader JavaScript

<span id="show_test_dialog">Zeige</span>
<div id="test_dialog" style="display:none;" title="Dies ist ein Test">Hier ist der Text</div>

JavaScript dazu:

mw.loader.using( ['jquery.ui.dialog'], function(){
  $(document).ready( function () {
    $('#show_test_dialog').click(function (){
      $('#test_dialog').dialog({
      height: 140,
      modal: true
    });
    });
  });
});

Templates

{{#declare:property1=templatePrameter1
|property2=templatePrameter2
|property3=templatePrameter3
}}

R-Ablage

setwd("/home/plankandreas/Dokumente")
fromto <- c(1:30)
for(i in  fromto){
if(i==1)
  cat("<includeonly><table style=\"background:transparent; margin-top:0.5em;{{{Format gesamt|}}}\">{{#if:{{{Titel|}}}|<tr><td style=\"text-align:center; font-weight:bold;\">{{{Titel}}}</td></tr>}}<tr><td><!--
-->", file="ImageSwitch_de.txt")
  cat("{{#if:{{{Bild ",i,"|{{{",(i-1) * 4 +1,"|}}}}}}<!-- 
  -->|<!-- ",i,":true 
  -->{{ImageSwitch/aux<!-- 
    -->|1={{{Bild ",i,"|{{{",(i-1) * 4 +1,"|}}}}}}<!-- 
    -->|2={{{Ergebnis Text ",i,"|{{{",(i-1) * 4 +2,"|}}}}}}<!-- 
    -->|3={{{Beschreibung ",i,"|{{{",(i-1) * 4 +3,"|}}}}}}<!-- 
    -->|width={{{Bildbreite|150}}}<!-- 
    -->|lines={{{Beschriftungszeilen|1}}}<!-- 
    -->|link={{{Ergebnis ",i,"|{{{",(i-1) * 4 +4,"|}}}}}}<!-- 
    -->|image framestyle={{{Format Bildrahmen|}}}<!-- 
    -->|caption style={{{Format Titelbeschriftung|vertical-align:bottom;text-align:center;}}}<!-- 
  -->}}<!-- -->}}<!--
-->", sep="", file ="ImageSwitch_de.txt", append=TRUE)#
if(i==max(fromto))
  cat("<!--
--></td></tr>{{#if:{{{Bild ",i+1,"|{{{",(i) * 4 +1,"|}}}}}}|<tr><td style=\"text-align:center; color:red;\"><!--
-->{{#switch:{{CONTENTLANGUAGE}} 
  |#default=The maximum number of images (",i ,") is exceeded!
  |de |de-formal=Maximale Bilderanzahl (",i ,") ist überschritten!}}<!--
--></td></tr>}}</table>
</includeonly><noinclude>
{{documentation}}
</noinclude>", file="ImageSwitch_de.txt", append=TRUE, sep="")
}# end for 

# ImageSwitch-aux
setwd("/home/plankandreas/Dokumente")
cat('<table class="ImageSwitchGallery" style="width:{{#If:{{{width|}}}|{{#Expr:{{{width}}}+10}}|160}}px; float:left;">
  <tr style="text-align:center;{{{caption style|}}}">
    <td style="font-size:1em; height:{{#Expr:0.2+1.5*{{{lines|1}}}}}em; padding:0px;">
      <div style="width:{{#If:{{{width|}}}|{{#Expr:{{{width}}}+7}}|157}}px; line-height:1.3em; padding-left:6px; padding-right:6px; padding-top:2px; padding-bottom:1px; overflow-y:auto; margin:0px; padding-top:2px; border:none; border-width:0px;">[[<!-- Link -->{{{link|}}}|<!-- Text -->{{Trim|1={{{2|}}} }}]] <!--
  --></div>
    </td>
  </tr>
  <tr>
    <td style="height:{{{width|150}}}px;vertical-align:top; {{{image framestyle|}}}"><!--
  -->[[{{Trim| 1={{{1|}}} }}|center|none|{{{width|150}}}x{{{width|150}}}px|{{Trim|1={{{3|}}} }}|link={{{link|}}}]]<!--
  --></td>
  </tr>
  <tr><td style="height:0px;text-align:right;padding-right:10px;padding-left:10px;"><div class="plainlinks" style="position:relative;height:0px;top:-23px;" title="{{#switch:{{CONTENTLANGUAGE}} |#default=New window: details of file “{{Trim| 1={{{1|}}} }}”.|de |de-formal=In neuem Fenster: Details zur Datei „{{Trim| 1={{{1|}}} }}“.}}">[<!-- -->{{fullurl: {{Trim| 1={{{1|}}} }}<!-- -->}} [[File:Magnify-clip-tiny bottom-right-white-gradient.png|link=]]<!-- -->]</div></td></tr>
</table>', file="ImageSwitch_aux.txt", sep="")

setwd("/home/plankandreas/Dokumente")
fromto <- c(1:30)
for(i in  fromto){
if(i==1)
  cat("<includeonly><table style=\"background:transparent; margin-top:0.5em;{{{style|}}}\">{{#if:{{{title|}}}|<tr><td style=\"text-align:center; font-weight:bold;\">{{{title}}}</td></tr>}}<tr><td><!--
-->", file="ImageSwitch_en.txt")
  cat("{{#if:{{{image ",i,"|{{{",(i-1) * 4 +1,"|}}}}}}<!-- 
  -->|<!-- ",i,":true 
  -->{{ImageSwitch/aux<!-- 
    -->|1={{{image ",i,"|{{{",(i-1) * 4 +1,"|}}}}}}<!-- 
    -->|2={{{result text ",i,"|{{{",(i-1) * 4 +2,"|}}}}}}<!-- 
    -->|3={{{lead ",i,"|{{{",(i-1) * 4 +3,"|}}}}}}<!-- 
    -->|width={{{image width|150}}}<!-- 
    -->|lines={{{caption lines|1}}}<!-- 
    -->|link={{{result ",i,"|{{{",(i-1) * 4 +4,"|}}}}}}<!-- 
    -->|image framestyle={{{image framestyle|}}}<!-- 
    -->|caption style={{{caption style|vertical-align:bottom;text-align:center;}}}<!-- 
  -->}}<!-- -->}}<!--
-->", sep="", file ="ImageSwitch_en.txt", append=TRUE)#
if(i==max(fromto))
  cat("<!--
--></td></tr>{{#if:{{{image ",i+1,"|{{{",(i) * 4 +1,"|}}}}}}|<tr><td style=\"text-align:center; color:red;\"><!--
-->{{#switch:{{CONTENTLANGUAGE}} 
  |#default=The maximum number of images (",i ,") is exceeded!
  |de |de-formal=Maximale Bilderanzahl (",i ,") ist überschritten!}}<!--
--></td></tr>}}</table>
</includeonly><noinclude>
{{documentation}}
</noinclude>", file="ImageSwitch_en.txt", append=TRUE, sep="")
}# end for 
setwd("/home/plankandreas/Dokumente/Wikitexte")
fromto <- 1:15
for(i in  fromto){
if(i==1)
 cat("", file ="Switch.txt")
  cat("<!-- Link ",i," -->
{{#if: {{{result text ",i,"|}}}{{{result ",i,"|}}}
 |{{Switch/Lead 
  | keyID  ={{{id}}}  
  | leadID = {{{leadID|►}}}
  | subheading      = {{{subheading ",i,"|}}}
  | subheadingstyle = {{{subheading style ",i,"|}}}
  | resulttext= {{#if: {{{result text ",i,"|}}} | {{{result text ",i,"}}} | {{{result ",i,"}}}}} 
  | resultlink= {{StripFormatting | {{{result ",i,"}}}}}
  | remarks   = {{{remarks ",i,"|}}}
  | image a   = {{{image ",i,"|}}}
  | label a   = {{{label ",i,"|}}}
  | caption a = {{{caption ",i,"|}}}
  | image a width  = {{{image ",i," width|80}}}
  | image a height = {{{image ",i," height|80}}}
  }}
}}", sep="", file ="Switch.txt", append=TRUE)#
# if(i==max(fromto))
#   cat()
}# end for 

Links/Hinweise

http://de.hortipedia.com/wiki/Aesculus_pavia Logos für Morphologie von Pflanzen