امتداد:أنماط القوالب
TemplateStyles حالة الإصدار مستقر |
|
---|---|
تنفيذ | وسم , ContentHandler , وصلة |
بيان | Load sanitized CSS stylesheets from a template. |
المؤلف/المؤلفون | |
آخر إصدار | Continuous updates |
سياسة التوافق | تصدر اللقطات البرمجية مع ميدياويكي. الإصدار الرئيسي لا يتوافق مع الإصدارات السابقة. |
MediaWiki | 1.30+ |
PHP | 7.3+ |
ترخيص | رخصة جنو العمومية 2.0 أو ما بعدها |
التنزيل | |
|
|
<templatestyles src=... /> |
|
تنزيلات ربع سنوية | 995 (Ranked 1st) |
استخدام مواقع الويكي العمومية | 1,977 (Ranked 199th) |
ترجم الامتداد TemplateStyles لو كان متوفرا على translatewiki.net | |
المسائل | المهام المفتوحة · الإبلاغ عن عطل تقني |
TemplateStyles هو امتداد محلل يسمح للمستخدمين بتخزين كود CSS مخصص على صفحات ويكي وتضمين هذه الأنماط في المقالات عبر علامة <templatestyles>
. يسمح الامتداد فقط بمجموعة فرعية آمنة من قواعد CSS مخزنة في صفحات الأنماط القابلة للتضمين. ويجري ذلك بواسطة مكتبة css-sanitizer.
يجري تشجيع المحررين على تضمين أنماط للقالب عبر TemplateStyles لأن هذا يسمح للمستخدمين أنفسهم بتحرير القالب وأنماطه، وبهذه الطريقة يجري تحميل الأنماط فقط عند الحاجة (مقارنةً بإضافة MediaWiki:Common.css إلى الموقع بالكامل).
للحصول على تعليمات حول كيفية استخدام الامتداد كمحرر على ويكي، راجع مساعدة:أنماط القوالب .
الاستخدام
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 "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 "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, <templatestyles src="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 "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 <div class="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>
.
- To use TemplateStyles to style something like w:MediaWiki:Protectedpagetext, you would need to enclose the message's contents in
- 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 CSS variables, see phab:T320322.
- 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.
- Vendor-prefixed properties (e.g. anything starting with
@font-face
rules must use afont-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 thebody
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+
Installation
- نزّل الملف/الملفات وضعها في دليل يحمل اسم
TemplateStyles
داخل مجلد extensions/
لديك.
يجب على مطوري البرمجيات والمساهمين بالكود البرمجي تثبيت الامتداد من غت بدلا من ذلك، مستخدمين:cd extensions/
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateStyles - حينما تثبته مستخدما غت شغّل Composer كي تثبت اعتمادات بي إتش بي، وذلك عن طريق إصدار
composer install --no-dev
في مجلد الامتداد. (طالع مهمة T173141 لتطلع على التعقيدات المحتملة.) - أضف الكود التالي في الجزء الأسفل من ملف LocalSettings.php :
wfLoadExtension( 'TemplateStyles' );
- Configure as required.
- تم التنفيذ – اذهب إلى Special:Version على موقع الويكي لديك كي تتحقق من أن الامتداد قد ثبت بنجاح.
تنصيب Vagrant:
- لو كنت تستخدم Vagrant ، ثبته مستخدما
vagrant roles enable templatestyles --provision
Configuration
parameter | default | comment |
---|---|---|
$wgTemplateStylesAllowedUrls
|
[
"audio" => [
"<^https://upload\\.wikimedia\\.org/wikipedia/commons/>"
],
"image" => [
"<^https://upload\\.wikimedia\\.org/wikipedia/commons/>"
],
"svg" => [
"<^https://upload\\.wikimedia\\.org/wikipedia/commons/[^?#]*\\.svg(?:[?#]|$)>"
],
"font" => [],
"namespace" => [
"<.>"
],
]
|
PCRE regular expressions to match allowed URLs for various types of external references.
Keys are external reference types, and values are arrays of regular expressions (including delimiters) to match allowed URLs. Current external reference types are:
|
$wgTemplateStylesNamespaces
|
[ NS_TEMPLATE => true ]
|
Namespaces in which to set the "CSS معقم" content model for titles ending in ".css".
Enabling this for 2 (User) or 8 (MediaWiki) is a bad idea, as it will conflict with the normal CSS files in those namespaces. |
$wgTemplateStylesPropertyBlacklist
|
[]
|
Properties to blacklist in CSS style rules.
The TemplateStylesPropertySanitizer hook allows for finer-grained control. |
$wgTemplateStylesAtRuleBlacklist
|
[]
|
At-rules to blacklist in stylesheets.
The TemplateStylesStylesheetSanitizer hook allows for finer-grained control. |
$wgTemplateStylesUseCodeEditor
|
true
|
Whether to enable Extension:CodeEditor for the "CSS معقم" content type. |
$wgTemplateStylesAutoParseContent
|
true
|
If true, the "CSS معقم" content model will be added to $wgTextModelsToParse if the CSS content model is already present in that array.
If false, add |
$wgTemplateStylesMaxStylesheetSize
|
102400
|
Maximum size (in bytes) of a stylesheet. null for no limit.
|
$wgTemplateStylesDefaultNamespace
|
NS_TEMPLATE
|
The default namespace for the src attribute of the <templatestyles> tag.
|
Other dependencies
$wgTidyConfig
should be configured to use no tidying or RemexHtml.
If used with any of the Raggett drivers, a <templatestyles />
tag in the middle of a paragraph (including in an inline template) will cause tidy to break the paragraph at that point.
The other drivers have not been tested for this issue.
Potential errors
It may help to enable $wgShowExceptionDetails in your LocalSettings.php
to determine if you are experiencing any of the errors below.
Class 'Wikimedia\CSS\Parser\Parser' not found
- This means a required library has not been installed. The error may come up when attempting to import a wiki CSS page or when changing the content model of a page to "sanitized-css". This was common in the past due to a bug in the extension distributor; shouldn't happen anymore.
Import failed: The content model 'sanitized-css' is not registered on this wiki.
- Happens when you try to import a wiki page created via TemplateStyles, but TemplateStyles is not installed on your wiki.
See also
- مساعدة:أنماط القوالب
- css-sanitizer - used for the sanitization of the CSS.
- phab:T483 "RfC: Allow styling in templates" (about possibly deploying this extension on Wikimedia wikis)
- phab:T56864 "ResourceLoader: Implement support for LESS in wiki modules (user and site), supporting e.g. MediaWiki:Common.less"
- phab:T155813 "Decide on storage and delivery method for TemplateStyles CSS"
- It’s now easier to craft content for mobile devices: Responsive web design at the Wikipedia scale on the Wikimedia Blog.
- Extension:TemplateStylesExtender
هذا الامتداد يستخدم على واحد من مشاريع ويكيميديا أو أكثر من واحد. يعني هذا الأمر أن الامتداد مستقر ويعمل/تعمل جيدا بما فيه الكفاية ليستخدم/لتستخدم في مواقع تتمتع بمستوى زيارات مرتفع مثل هذه. ابحث عن اسم هذا الامتداد في ملفات الضبط CommonSettings.php وكذلك InitialiseSettings.php كي ترى أين تنصب. توجد قائمة كاملة بالامتدادات المنصبة على موقع ويكي بعينه على صفحة Special:Version الخاصة بموقع الويكي. |
هذا الامتداد مشمول في الحزم أو مزارع الويكي التالية أو كليهما: هذه ليست قائمة كاملة. بعض مزارع الويكي أو الاستضافة أو حزم البرمجيات قد تحتوي على هذا الامتداد حتى لو كانت غير مدرجة هنا. راجع دائمًا مزرعة الويكي أو المستضيف أو حزمة البرمجيات للتأكد من ذلك. |
- Stable extensions/ar
- Tag extensions/ar
- ContentHandler extensions/ar
- Hook extensions/ar
- GPL licensed extensions/ar
- Extensions in Wikimedia version control/ar
- CodeEditorGetPageLanguage extensions/ar
- ContentHandlerDefaultModelFor extensions/ar
- ParserClearState extensions/ar
- ParserFirstCallInit extensions/ar
- All extensions/ar
- Extensions requiring Composer with git/ar
- Extensions used on Wikimedia/ar
- Extensions included in BlueSpice/ar
- Extensions included in Canasta/ar
- Extensions included in Fandom/ar
- Extensions included in Miraheze/ar
- Extensions included in MyWikis/ar
- Extensions included in ShoutWiki/ar
- Extensions included in Telepedia/ar
- Extensions included in wiki.gg/ar
- Extensions included in WikiForge/ar
- Metadata/ar
- CSS/ar