Jump to content

扩展:TemplateStylesExtender

本頁使用了標題或全文手工轉換
From mediawiki.org
This page is a translated version of the page Extension:TemplateStylesExtender and the translation is 78% complete.
MediaWiki扩展手册
TemplateStylesExtender
发行状态: 稳定版
实现 解析器扩展
描述 Extends Extension:TemplateStyles with new selectors
作者 Octfx留言
最新版本 2.0.0 (2025-06-02)
MediaWiki 1.43+
PHP >=8.0
Composer octfx/template-styles-extender
许可协议 GNU通用公眾授權條款2.0或更新版本
下載

  • $wgTemplateStylesExtenderCustomPropertiesDeclaration
  • $wgTemplateStylesExtenderExtendCustomPropertiesValues
  • $wgTemplateStylesExtenderEnableUnscopingSupport
  • $wgTemplateStylesExtenderUnscopingPermission

TemplateStylesExtender扩展对Extension:TemplateStyles(模板样式) 进行了扩展,支持新的选择器和匹配器。 TemplateStylesExtender is developed based on css-sanitizer 5.5.0, which is being used by MediaWiki 1.43.

功能

  • Declare CSS custom properties/variables
  • Use CSS custom properties/variables in most properties
  • Implement additional properties and values as listed below
Module Changes Upstream task
Basic User Interface Module Level 4 Added property: pointer-events T342271
Box Sizing Module Level 4 Backported for css-sanitizer 5.5.0 T375344
Cascading and Inheritance Level 5 Added value: revert-layer -
Color Module Level 4 Added: Alpha HEX notation T265675
Color Module Level 5 Added: Relative color, color() -
Containment Module Level 3 Added properties: contain, content-visibility -
Filter Effects Module Level 2 Added property: backdrop-filter -
Fonts Module Level 4 Added properties: font-optical-sizing, font-variation-settings, ascent-override, descent-override, font-display, line-gap-override -
Fonts Module Level 5 Added property: size-adjust -
Masking Module Level 1 Added property: -webkit-mask-image -
Ruby Annotation Layout Module Level 1 Added properties: ruby-align, ruby-position T277755
Scroll Snap Module Level 1 Added properties: scroll-margin, scroll-padding, scroll-snap-align, scroll-snap-stop, scroll-snap-type T271598
Values and Units Module Level 4 Added function: clamp() T394619

安裝

  • 下载文件,并将其放置在您extensions/文件夹中的TemplateStylesExtender目录内。
  • 請新增下列代码到您的LocalSettings.php 文件的底部:
    wfLoadExtension( 'TemplateStyles' );
    wfLoadExtension( 'TemplateStylesExtender' );
    
  • 按需求配置。
  • Yes 完成 – 請导航至您的wiki上的Special:Version,以验证此扩展已成功安装。

配置

Configuration 描述 默认
$wgTemplateStylesExtenderCustomPropertiesDeclaration Allow CSS custom properties (CSS variables) to be declared as properties true
$wgTemplateStylesExtenderExtendCustomPropertiesValues Allow the CSS custom properties (CSS variables) to be used as values in all properties true
$wgTemplateStylesExtenderEnableUnscopingSupport Allows users with unscope permissions to unscope CSS by setting a wrapclass attribute. false
$wgTemplateStylesExtenderUnscopingPermission Specify a permission group that is allowed to unscope CSS. editinterface

注意CSS变量

当然:root选择器不起作用,因为模板样式会在前面加上.mw-parser-output

一种可行的修复方案是将整个内容包围在div中,并为其添加声明,例如

div#content-wrap {
   --padding: 10px
}

.content {
   padding: var( --padding )
}

Wikitext

<div id="content-wrap">
   <div class="content">
      The WikiText...
   </div>
</div>

CSS取消包围

例如:<templatestyles src="Foo/style.css" wrapclass="mediawiki" />会导致CSS被包围在.mediawiki中,而不是在.mw-parser-output中。

要在页面内包括这样的调用时,用户需要有editinterface权限才能够编辑。 你也可以选择调用一个包括了此样式的模板。

參見