Jump to content

Erweiterung:TemplateData

From mediawiki.org
This page is a translated version of the page Extension:TemplateData and the translation is 43% complete.
Outdated translations are marked like this.
This extension comes with MediaWiki 1.35 and above. Daher muss sie nicht erneut heruntergeladen werden. Allerdings müssen die folgenden Anweisungen trotzdem beachtet werden.
MediaWiki-Erweiterungen
TemplateData
Freigabestatus: stabil
Einbindung Tag , API
Beschreibung Ermöglicht Informationen über Templates zu speichern, abzurufen und zu visualisieren
Autor(en) Timo Tijhof, Moriel Schottlender, James Forrester, Trevor Parscal, Bartosz Dziewoński, Marielle Volz, ...
Letzte Version 0.1.2 (Kontinuierliche Aktualisierungen)
Kompatibilitätspolitik Snapshots werden zusammen mit MediaWiki veröffentlicht. Der Master ist nicht abwärtskompatibel.
MediaWiki >= 1.43
PHP 5.4+
Datenbankänderungen Nein
Lizenz GNU General Public License 2.0 oder neuer
Herunterladen
  • $wgTemplateDataUseGUI
‎<templatedata>
Quarterly downloads 277 (Ranked 19th)
Public wikis using 6,971 (Ranked 24th)
Übersetze die TemplateData-Erweiterung, wenn sie auf translatewiki.net verfügbar ist
Probleme Offene Aufgaben · Einen Fehler melden

Die Erweiterung TemplateData stellt den Tag ‎<templatedata> und eine API zur Verfügung, die es Redakteuren ermöglicht zu bestimmen, wie die Templates aufgerufen werden sollen. Diese Informationen sind als schön formatierte Tabelle für die Endbenutzer und als JSON-API verfügbar. Dadurch können andere Programme (z. B. VisualEditor) Schnittstellen für die Arbeit mit Templates und ihren Parametern erstellen. Siehe Hilfe:TemplateData für eine detaillierte Hilfe.

Installation

  • Die Erweiterung herunterladen und die Datei(en) in ein Verzeichnis namens TemplateData im Ordner extensions/ ablegen.
    Entwickler und Code-Beitragende sollten stattdessen die Erweiterung von Git installieren, mit:cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
  • Folgenden Code am Ende deiner LocalSettings.php -Datei einfügen:
    wfLoadExtension( 'TemplateData' );
    
  • Yes Erledigt – Navigiere zu Special:Version in deinem Wiki, um zu überprüfen, ob die Erweiterung erfolgreich installiert wurde.

Bearbeitung von Daten

Die TemplateData-Erweiterung funktioniert, indem ein ‎<templatedata>-Tag im Wikitext einer Vorlagenseite definiert wird (optional kann es auch von einer anderen Seite transkludiert werden). Dies ist so konzipiert, dass es mit dem in vielen Wikis üblichen Layout kompatibel ist, bei dem die Vorlagendokumentation auf einer separaten Seite eingebunden wird (ist aber nicht erforderlich). Der Inhalt des ‎<templatedata>-Tags muss gültiges JSON im unten beschriebenen Format sein; beachten Sie, dass alle Beschreibungen im Klartext sein müssen (innerhalb der Vorlagendaten wird kein Wikitext akzeptiert).

Wenn ein ‎<templatedata>-Block auf einer Seite enthalten ist, führt die TemplateData-Erweiterung beim Speichern der Seite die folgenden Prüfungen durch:

  1. Der Inhalt muss gültiges JSON sein;
  2. Jedes Element innerhalb der JSON-Struktur muss vom erwarteten Typ sein, wie unten angegeben (z. B. Objekt, Array oder Primitiv); und
  1. Für die Elemente, die eine bestimmte Liste möglicher Werte haben (z. B. type), muss der Wert im JSON-Objekt einem dieser Werte entsprechen.

If any of these checks fails, the server will not be permitted saving and an error message will be displayed above the edit page.

For autovalue items, T4700 prevents subst: from working in any template that is added inside a tag, including ‎<ref> and ‎<gallery> tags. The TemplateData block will save correctly, but the resulting wikitext will not be parsed correctly when the template is used.

Beachten Sie, dass Sie nicht {{#tag:templatedata}} anstelle von Special:MyLanguage/Help:TemplateData#Template data editor method verwenden können.

Format

Nachfolgend sehen Sie eine visualisierte Version der JSON-Daten, wie sie auf der Vorlagenseite definiert und von ‎<templatedata>‎</templatedata>-Tags umgeben sind. Die formale Spezifikation ist im TemplateData-Repository verfügbar. Die neueste Version finden Sie in Specification.md.

TemplateData-Objekt

Das TemplateData-Objekt ist ein "JSON-Wurzelelement", das in einem ‎<templatedata>-Element auf der Vorlagenseite enthalten ist.

Schlüssel Typ Beschreibung
description InterfaceText oder null Eine kurze Beschreibung der Vorlage. Es muss im Klartext sein. Sobald sie ausgefüllt ist, kann sie bei der Bearbeitung einer einzelnen Vorlage als Beschriftung angezeigt werden und vielleicht auch in den Suchergebnissen, wenn Nutzer eine von vielen Vorlagen auswählen. Der Standardwert ist null.

→ For more details see: description

params Objekt, das Param-Objekte enthält Ein Objekt, das jeden Parameternamen der Vorlage einem entsprechenden Param-Objekt zuordnet, das die Eigenschaften dieses Parameters beschreibt.

→ For more details see: params

paramOrder Array mit Zeichenfolgen für Parameternamen Die logische Reihenfolge, in der die Parameter angezeigt werden sollen. Das Array enthält jeden Parameterschlüssel genau einmal. Jeder String muss ein gültiger Schlüssel im params-Objekt sein.

→ For more details see: paramOrder

sets Array mit
Set-Objekten
Ein Array mit Set-Spezifikationen. Ein Set ist eine Gruppe von Parametern, die zusammen verwendet werden sollten. Der Standardwert ist []. Beachten Sie, dass sich die sets-Funktionalität noch in der Entwicklung befindet.
format Zeichenkette, entweder inline oder block Wie die Wikitext-Darstellung der Vorlage gestaltet sein SOLLTE. Der Standardwert ist inline. See #Custom_formats for other custom formats.
maps Object containing Map objects An object that links a simplified name of a third party consumer of the template data (i.e. Citoid, Special:MyLanguage/Wikidata, etc.) to a map object that in turn links a name of a consumer parameter to one or more corresponding names of template parameters.

Param object

Schlüssel Typ Standard Beschreibung
label InterfaceText null A (very) brief name for the parameter. Try to keep under 20-ish characters.

→ For more details see: label

description InterfaceText null A brief description of the parameter, for users to know which to pick from an option list.

→ For more details see: description

required Wahrheitswert false Whether the parameter is required for the template to work (true if this parameter must be specified).

→ For more details see: required

suggested Wahrheitswert false Whether the parameter is suggested for the template to be useful (true if this parameter should be specified).

→ For more details see: suggested

deprecated Wahrheitswert oder Zeichenkette false Whether the parameter is deprecated. The value can be a string of instructions giving the user guidance what instead can be done, or be simply true.

→ For more details see: deprecated

aliases Array containing strings [] List of aliases. An alias is an alternative name for the parameter that may be used instead of (not in addition to) the primary name. Aliases are not documented in a separate Parameter object. If they need more information, they should be in their own property marked "deprecated".

→ For more details see: aliases

default InterfaceText null A fixed default value used by the template if no value is assigned to the parameter, or a description thereof.

→ For more details see: default

autovalue Zeichenkette null A dynamically-generated default value in wikitext, such as today's date or the editing user's name; this will often involve wikitext substitution, such as {{subst:CURRENTYEAR}}.

→ For more details see: autovalue

example InterfaceText null An example text for the parameter, to help users fill in the proper value.

→ For more details see: example

type Zeichenkette "unknown" The type of the parameter, for (soft) type hinting. One of:
Zeichenkettenwert Art von Parameter
"unknown" Assumed type if not set

→ For more details see: value ‘unknown’

"number" Any numerical value (without decimal points or thousand separators)

→ For more details see: value ‘number’

"string" Any textual value. May contain line breaks.

→ For more details see: value ‘string’

"line" Short text field – use for names, labels, and other short-form fields. This is supposed to be text that is not expected to contain line breaks.

→ For more details see: value ‘line’

"boolean" A boolean value ('1' for true, '0' for false, '' for unknown), see three-valued logic.

→ For more details see: value ‘boolean’

"date" A date in ISO 8601 format, e.g. "2014-05-09" or "2014-05-09T16:01:12Z"

→ For more details see: value ‘date’

"url" A URL, including protocol, e.g. "http://www.example.org", "https://example.org", or "//example.org".

→ For more details see: value ‘url’

"wiki-page-name" A valid MediaWiki page name for the current wiki. Doesn't have to exist, but if not, should be a valid page name which could be created.

→ For more details see: value ‘wiki-page-name’

"wiki-file-name" A valid MediaWiki file name for the current wiki. Doesn't have to exist, but if not, should be a valid file name which could be uploaded. Should not include the namespace (e.g. "Foo.svg" not "File:Foo.svg" or "Bild:Foo.svg").

→ For more details see: value ‘wiki-file-name’

"wiki-template-name" A valid MediaWiki Template name for the current wiki.

→ For more details see: value ‘wiki-template-name’

"wiki-user-name" A valid MediaWiki user name for the current wiki. Doesn't have to exist, but if not, should be a valid user name which could be created. Should not include the namespace (e.g. "Foo" not "User:Foo" or "Usario:Foo").

→ For more details see: value ‘wiki-user-name’

"content" Page content in wikitext, such as text style, links, images, etc.

→ For more details see: value ‘content’

"unbalanced-wikitext" Raw wikitext that should not be treated as standalone content because it is unbalanced – for example, templates concatenating incomplete wikitext as a bigger whole, such as {{echo|before=<u>|after=</u>}}

→ For more details see: value ‘unbalanced-wikitext’

→ For more details see: type

inherits Zeichenkette none
substituted
The name key of another parameter (must be a valid key in the params object). The current Parameter Object will inherit properties from the specified Parameter Object, with local properties overriding the inherited ones.

→ For more details see: inherits

suggestedvalues Array containing strings [] An optional parameter property. Creates a list of parameter values to help users select the desired value. For the suggested values to be displayed as a combo box in VisualEditor, the parameter’s type must be set to one of the following: content, line, string, number, unknown or unbalanced wikitext.

→ For more details see: suggestedvalues

Set object

Schlüssel

Object or primitive type

Beschreibung

label InterfaceText A (very) brief name for the parameter set. Try to keep under 20-ish characters.
params Array of strings One or more names of parameters to include in the set (each must be a valid key in the params object). A parameter may be in multiple sets. Not every parameter must be in a set.

Maps structure

Maps is a single data structure that goes multiple levels deep. It became common to call the second level a “map object”.

Schlüssel Typ Standard Beschreibung
name of consumer object {} An object that links a name of a consumer to a map object that in turn links a name of a consumer parameter to one or more corresponding names of template parameters.

The names of the template parameters can be specified either as a string (one name), an array of strings (several names), or an array of arrays of strings (several sets of names); each of these strings must be a valid key in the params object elsewhere in the same template's TemplateData.

A specific template parameter may be in multiple maps, and it may be used in the values of multiple keys in a given map, but not every template parameter must be in a map.

A shortened example from English Wikipedia's Template:Cite_news#TemplateData illustrates the structure of map objects.

{
	"proveit": {
		"main": "title",
		"textarea": [
			"quote"
		]
	},
	"citoid": {
		"title": "title",
		"url": "url",
		"publisher": "publisher",
		"publicationTitle": "work",
		"date": "date",
		"ISSN": [
			"issn"
		],
		"ISBN": [
			"isbn"
		],
		"contributor": "others",
		"author": [
			[
				"first",
				"last"
			],
			[
				"first2",
				"last2"
			],
			[
				"first9",
				"last9"
			]
		],
		"editor": [
			[
				"editor-first",
				"editor-last"
			]
		]
	}
}

InterfaceText (string or object)

A free-form plain-text string (i.e. no wikitext or HTML) in the content-language of the wiki, or an object containing those strings keyed by language code.

The default value for all InterfaceText fields is null.

String type

If it is a string, it must contain a non-localized string in the content language of the local wiki.

Object type

If it is an object, the object must have this mapping:

Schlüssel Typ Beschreibung
Wikipedia language code Zeichenkette Localized string for users of that interface language.

Example of object mapping:

Schlüssel Wert
"en" "Welcome to Wikipedia"
"de" "Willkommen bei Wikipedia"
"fr" "Bienvenue sur Wikipédia"
"nl" "Welkom op Wikipedia"
"it" "Benvenuti su Wikipedia"
"es" "Bienvenidos a Wikipedia"
"ru" "Добро пожаловать в Википедию"

Beispiel

An example TemplateData structure as specified within wikitext on a template page.

<templatedata>
{
    "description": "Label unsigned comments in a conversation.",
    "params": {
        "user": {
            "label": "User's name",
            "type": "wiki-user-name",
            "required": true,
            "description": "User name of person who forgot to sign their comment.",
            "aliases": ["1"]
        },
        "date": {
            "label": "Date",
            "suggested": true,
            "description": {
                "en": "Timestamp of when the comment was posted, in YYYY-MM-DD format."
            },
            "aliases": ["2"],
            "autovalue": "{{subst:#time:Y-m-d}}"
        },
        "year": {
            "label": "Year",
            "type": "number"
        },
        "month": {
            "label": "Month",
            "inherits": "year"
        },
        "day": {
            "label": "Day",
            "inherits": "year"
        },
        "comment": {
            "required": false
        }
    },
    "sets": [
        {
            "label": "Date",
            "params": ["year", "month", "day"]
        }
    ],
    "maps": {
        "ExampleConsumer": {
            "foo": "user",
            "bar": ["year", "month", "day"],
            "quux": [
                "date",
                ["day", "month"],
                ["month", "year"],
                "year"
            ]
        }
    }
}
</templatedata>

Below is how the above example would be displayed on the template page:

Label unsigned comments in a conversation.

Template parameters

ParameterDescriptionTypeStatus
User's nameuser 1

User name of person who forgot to sign their comment.

Userrequired
Datedate 2

Timestamp of when the comment was posted, in YYYY-MM-DD format.

Auto value
{{subst:#time:Y-m-d}}
Unknownsuggested
Yearyear

no description

Numberoptional
Monthmonth

no description

Numberoptional
Dayday

no description

Numberoptional
commentcomment

no description

Unknownoptional

API

See the generated help at Special:ApiHelp/templatedata. A sample invocation (formatted for human readability) is:

This returns the template data for Template:Cite web. The ‎<templatedata>...‎</templatedata> block for this template is on its transcluded template documentation page, en:Template:Cite web/doc.

Additions and changes to JSON as received from the API

The JSON structure provided in response to an API HTTP get request is significantly different than that which is defined in the ‎<templatedata>...‎</templatedata> block. In response to the API request, extension TemplateData makes the following changes to the JSON object:

    1. Add the title key with the name of the page from which the data was requested (e.g. "Template:Cite web").
    2. Add the sets key
    3. Change all TemplateText occurrences that are just strings to objects with a single key for the current wiki's Wikipedia language code
    4. Remove all inherits keys.
      • Add all properties from parameter from which an inheritance is defined which are not superseded by explicitly defined keys in the inheritor's Parameter Object.
    5. Add default values for all keys in each Parameter Object which have not been explicitly defined or inherited.

Visualised differences in a TemplateData JSON object delivered by the API

Wrapper objects added to JSON delivered by API
These are not defined in the JSON object enclosed by the ‎<templatedata> tags on the template page.
JSON Root
Schlüssel Typ Beschreibung
pages Page Object The Page object (contains one key which is the page number). If multiple pages were requested at one time there will be multiple Page Objects.

Seitenobjekt
Schlüssel Typ Beschreibung
(Seitenzahl) TemplateData-Objekt The TemplateData Object containing the information payload. The key is a static page number for the template page from which the JSON data was requested.
TemplateData Object (added by API)
The following key is added to the root of the JSON object which is enclosed in ‎<templatedata> tags on the template page.
Schlüssel Typ Beschreibung
title Zeichenkette The page name of the template (e.g. "Template:Cite web").
This key is not contained in the JSON structure on the template page. It is added to the structure by the MediaWiki software in route to delivery via the API.
sets Array containing Set Objects An array containing set specifications. A set is a group of parameters that should be used together.
If this does not exist on the template page it is added as an empty array to the structure provided by the API.
Parameter Objects from API
Schlüssel Typ Beschreibung
label InterfaceText translated to InterfaceText object, if not already in that format.
required Wahrheitswert If not defined, default value of false added.
description InterfaceText oder null If defined as a string, converted to a InterfaceText object. If not defined, key is added with a null value.
deprecated Wahrheitswert oder Zeichenkette If not defined, default value of false added.
aliases Array von Zeichenketten If not defined, a default empty array is assigned (i.e. [] ).
default Zeichenkette If not defined, default of "" is assigned.
type Zeichenkette If not defined, default of "unknown" is assigned.
inherits (entfernt) This key is removed and all inherited keys are added. Keys defined for the current parameter take precedence and any keys not defined on either the current param, or the one from which it inherits are given the default value.
InterfraceText (Objekt oder null):
An object containing strings keyed by language code.
Schlüssel Objekt oder
primitive Typ
Beschreibung
Objekt
(containing localized strings by Wikipedia language code)
If a TemplateData field on the template page contains a string, not an object with localized strings, MediaWiki translates it into an InterfaceText Object with a string assigned to the key name of the source Wikipedia Wikipedia language code. Der Standardwert für alle InterfaceText-Felder ist null
(Sprachcode des Wikis) Zeichenkette Localized string for users of that interface language.

Example of JSON object provided by API

The response to an API request for the TemplateData structure in the Example section (above) can be seen:

Konfiguration

Variable Standard Beschreibung
$wgTemplateDataUseGUI true Experimental dialog interface to edit templatedata JSON

Siehe auch