Help:TemplateStyles/zh

模板樣式是一個無需管理員權限即可實現對於模板的複雜樣式.

工作原理
編輯者添加 到一個頁面，然後 的內容將被解析為CSS、被過濾、載入到那些使用 標籤的頁面（直接使用或是模板嵌入）.

必須是 （）內容模型，預設是在模板名字空間並且以 結尾. 推薦的模式是把 的樣式儲存在子頁面，例如.

如果 缺少了命名空間前缀，那就會預設為模板命名空間. 因此，舉例來說， 將會載入.

標籤應該被放置在使用樣式的內容前面，例如在模板的最上方. 這是為了避免頁面載入時只有部分被渲染而發生無樣式內容閃爍的可能性.

這解決了什麼問題？
Traditionally, there are two ways to style templates (or any other content): by using inline styles (that is, using HTML code and adding attributes like  to it) or by using certain special system messages such as MediaWiki:Common.css. Neither of those approaches work very well.

For inline styling:


 * There is no separation of content and presentation. In cases where the content does not come from a template (e.g. tables in articles), that will result in article wikitext that's unintelligible for most editors.
 * Since styles are mixed with wikitext, syntax highlighting and other forms of CSS editing support are difficult or impossible.
 * Styles have to be repeated for each HTML element they apply to, which results in lots of copy-pasting and code that is hard to read and maintain.
 * Style attributes are limited to a subset of CSS. Most importantly,  rules needed for responsive design do not work so it's impossible to make templates that work well over a wide range of screen sizes. Furthermore, inline styles take precedence over CSS stylesheets so user-, skin- or device-specific customizations become more difficult.

For system  pages:


 * Editing is limited to administrators, which is a major barrier to participation.
 * Editing restrictions cannot be lifted as there is no way to limit what CSS rules can be used, and some of them could be abused to track readers' IP addresses or even execute scripts in some older browsers.
 * Changes are impossible to test without saving first.
 * All stylesheets must be loaded on all pages (whether they actually use the page or not), which wastes bandwidth and makes debugging style rules harder.

TemplateStyles allows editors to associate style rules to specific pages, provides the full power of CSS stylesheets while filtering dangerous constructs, and works with preview/debug tools (such as TemplateSandbox) as expected.

Lowering the access and maintainability barrier will hopefully result in more innovation in the way templates are visually designed, less maintenance overhead, and better adaptability to screen options (especially mobile devices which by now constitute half of Wikipedia pageviews).

這安全嗎？
Yes! TemplateStyles includes a full-fledged CSS parser that reads, re-serializes and escapes all code and removes CSS rules which do not match its whitelist. The parser is sufficiently fine-grained to reject remote resources (such as background images) but allow local ones. CSS selectors are rewritten so that they cannot refer to elements outside article content. (Visually modifying areas outside article content by displacing parts of the article, e.g. via absolute positioning, is not prevented at this time. This is no change from the status quo, as such a thing was already possible with wikitext and inline styles.)

哪些CSS規則是有效的？
Currently, TemplateStyles accepts most CSS3 properties supported by one or more major browser (as of early 2017). Beyond simple rules,,  ,  ,   and  /  at-rules are also supported (with font-face restricted to fonts whose name starts with  , for security reasons).

Non-standard properties (including vendor prefixes) are not currently supported. See T162379 for plans.

提供了哪些反濫用工具？
The design choice to store CSS in separate pages was made in part to make integration with the standard anti-abuse toolset easy. TemplateStyles CSS pages have their own content model so changes to them can be tracked or controlled with AbuseFilter, using the   variable.

CSS inclusion is tracked the same way as template transclusion, so you can see where a stylesheet is used via the "What links here" option, see what stylesheets are used on a page under "Page information" (and possibly on the edit screen, depending on what editor you use), and see what recent changes might be affecting a page using "Related changes".

TemplateStyles also leaves identifying information in the HTML code; to find out where a specific rule comes from, look at the page source, and the enclosing  tag will have an attribute like , where 123456 is the revision ID of the stylesheet (viewable with Special:Diff, for example).

有關模板樣式的決定是如何做出的？
The idea of including CSS with templates was proposed and accepted in a request for comments. Technical details were pinned down in a second RfC and workflow details in a user consultation.

誰在維護模板樣式？
TemplateStyles was originally a project of the Wikimedia Reading Infrastructure team (preceded by exploratory work Coren did as a volunteer), then people moved around. It is now maintained by an ad hoc WMF team consisting of Brad Jorsch (developer), Chris Koerner (community liaison), Dan Garry (product manager), Gergő Tisza (developer) and Grace Gellerman (project manager).

哪裡可以報告錯誤或請求功能？
Please file tasks under the TemplateStyles component in Phabricator.

在哪裡可以看到實際效果？
You can look at some curated examples.

The feature is currently (as of March 2018) enabled on the following Wikimedia sites:


 * here on mediawiki.org (all stylesheets)
 * German Wikipedia (all stylesheets)
 * Swedish Wikipedia (all stylesheets)
 * Wikitech (all stylesheets)
 * testwiki (all stylesheets)

參見

 * Extension:TemplateStyles, especially the #Caveats section.