Zum Inhalt springen

„Erweiterung:TemplateStyles“ – Versionsunterschied

aus AufEinWort, der freien Forschung
Die Seite wurde neu angelegt: „https://www.mediawiki.org/wiki/Extension:TemplateStyles/de '''TemplateStyles''' ist eine Parser-Erweiterung, mit der Benutzer benutzerdefinierten CSS-Code auf Wiki-Seiten speichern und diese Stile über das Tag <code>‎<'''templatestyles'''></code> in Artikel einbetten können. The extension allows only a safe subset of CSS syntax stored in embeddable style pages. This is powered by the css-sanitizer library. Editors are encouraged to include styles fo…“
 
K Textersetzung - „Erweiterung MediaWiki AufEinWort“ durch „MediaWiki Erweiterung AufEinWort“
 
Zeile 50: Zeile 50:


Other classes on the <code>body</code> or <code>html</code> elements may be targeted in the same manner. See phab:T197617. 1.32+
Other classes on the <code>body</code> or <code>html</code> elements may be targeted in the same manner. See phab:T197617. 1.32+
[[Kategorie:Erweiterung MediaWiki AufEinWort nachinstallt]]
[[Kategorie:MediaWiki Erweiterung AufEinWort nachinstallt]]

Aktuelle Version vom 11. Oktober 2025, 08:51 Uhr

https://www.mediawiki.org/wiki/Extension:TemplateStyles/de

TemplateStyles ist eine Parser-Erweiterung, mit der Benutzer benutzerdefinierten CSS-Code auf Wiki-Seiten speichern und diese Stile über das Tag ‎<templatestyles> in Artikel einbetten können. The extension allows only a safe subset of CSS syntax stored in embeddable style pages. This is powered by the css-sanitizer library.

Editors are encouraged to include styles for a template via TemplateStyles because this allows the same users to edit both the template and its styles, and this way styles are only loaded when needed (compared to adding to the sitewide MediaWiki:Common.css).

For instructions on how to use the extension as an editor on a wiki, see Hilfe:TemplateStyles.

Verwendung

The CSS page must be created first. By default any subpage in the Template namespace with a title ending in ".css" will be created with the "Bereinigtes CSS" content model if it contains no syntax errors.

The set of namespaces may be adjusted with $wgTemplateStylesNamespaces, or Special:ChangeContentModel may be used on any page. Then, in the template's wikitext, add the <templatestyles src="..." /> tag to load the styles.

The CSS saved using the "Bereinigtes CSS" content model must meet strict validity requirements: invalid CSS, unrecognized at-rules, and unrecognized or unsupported properties or property values cannot be saved. If invalid CSS is somehow saved, the offending constructs will be removed when the CSS is outputted to the browser.

The value of the src attribute on the tag is the title of the page, defaulting to the Template namespace. (This default can be changed via $wgTemplateStylesDefaultNamespace.) For example, <templatestylessrc="Example/styles.css" /> will load the page "Template:Example/styles.css".This will fail if that page does not exist or has a content model other than "Bereinigtes CSS".

Styles can be scoped within the page by using the optional wrapper parameter to the tag, e.g. <templatestyles src="Example/styles.css"wrapper="div.example" /> would scope the styles loaded to any <divclass="example"> inside the main parsed content. Any CSS simple selector sequence can be used for the wrapper parameter. This is intended to allow side-by-side comparison of live and sandbox versions of a template.

Use of sanitized CSS is tracked like transclusion of templates and will show up as a transclusion on Special:WhatLinksHere.

Caveats

  • Styles added by TemplateStyles are scoped into .mw-parser-output to avoid tampering with the user interface outside of the main parsed content.
    • To use TemplateStyles to style something like w:MediaWiki:Protectedpagetext, you would need to enclose the message's contents in <div class="mw-parser-output">...</div>.
  • The styles should be written to target specific CSS classes, and anything that generates elements with those classes should also be sure to include the styles themselves rather than relying on some other template to do so.
    • Styles included by a template can currently affect content on the page outside of the content generated by that template, but this ability may be removed in the future and should not be relied upon.

(See discussion from phab:T155813#2996589 and in phab:T176272.)

    • Including styles on a template that affects contents outside of that template will cause those styles not to be applied when editing a section that doesn't contain that template. Example: including styles on an info box that affect all tables of the page, when editing a section that doesn't contain the infobox, those tables won't be styled when previewing that section.
  • TemplateStyles does not support defining CSS variables, see phab:T320322 (CSS variables defined elsewhere, such as in MediaWiki:Common.css, can be referenced from TemplateStyles).
  • TemplateStyles allows a few non-standardized CSS properties.

Requests to support additional properties should be filed in Phabricator in the css-sanitizer and TemplateStyles projects.

    • Requests should include links to standards-track documents (e.g., on w3.org) describing the syntax of the properties being requested and an analysis of current browser support for the properties (e.g., a link to a caniuse.com page about the properties).
    • Vendor-prefixed properties (e.g. anything starting with -webkit-, -moz-, or -ms-) are likely to be declined if they're not needed for modern browsers.
  • @font-face rules must use a font-family prefixed with "TemplateStyles".

This should largely prevent redefining fonts used elsewhere in the document.

  • To target styles based on skins, use a selector such as body.skin-vector .myClass; specification of the body element is required and must be followed by a descendant combinator (i.e. the space).

Other classes on the body or html elements may be targeted in the same manner. See phab:T197617. 1.32+