Extension:小工具
Gadgets 发布状态: 稳定版 |
|
---|---|
![]() |
|
实现 | 我的Wiki , 特殊页面 , API |
描述 | Allow users to enable JS-based, user-provided gadgets from their preferences page. |
作者 | Daniel Kinzler (Duesentrieb讨论) |
MediaWiki | 1.19+ |
许可协议 | GNU通用公眾授權條款2.0或更新版本 |
下载 | README |
例子 | Wikimedia Commons: Gadget overview, user preferences (click "Gadgets"; you need to be logged in of course) |
|
|
|
|
翻譯Gadgets擴充功能如在translatewiki.net可用 | |
问题 | 尚未完成的工作 · 回報錯誤 |
小工具擴充功能提供了一種方式,能讓使用者選擇其他wiki使用者提供基於JavaScript和CSS的小工具。
小工具由位於MediaWiki命名空間頁面中的JavaScript和CSSsnippets 組成。 每個小工具由MediaWiki:Gadgets-definition中的一行所定義,並提供了小工具的名稱及描述,以及JS和CSS程式碼片段的列表(參見底下的用法段落)。
由於小工具位於MediaWiki命名空間(定義小工具的列表和實際的程式碼判斷皆是),因此只有管理員(自1.32起為介面管理員)能編輯程式碼。 這是因為:只有受到wiki社群高度信任的使用者才能編輯JavaScript程式碼,因為它被其他使用者所用,且JavaScript能輕鬆地劫持帳號和監視他人。
安装
- 下载文件,并将其放置在您
extensions/
文件夹中的Gadgets
目录内。 - 将下列代码放置在您的LocalSettings.php的底部:
wfLoadExtension( 'Gadgets' );
完成 – 在您的wiki上导航至Special:Version,以验证扩展已成功安装。
致使用MediaWiki 1.24或更早版本的用户:
上面的说明介绍的是安装此扩展的新方法,它使用wfLoadExtension()
。
如果您需要在早期版本(MediaWiki 1.24和更早版本)中安装此扩展,而不是wfLoadExtension( 'Gadgets' );
,您需要使用:
require_once "$IP/extensions/Gadgets/Gadgets.php";
用法
There are two ways to define gadgets depending on the $wgGadgetsRepoClass
.
If It is 'MediaWikiGadgetsDefinitionRepo'
(the default value), the list of available gadgets is defined on MediaWiki:Gadgets-definition.
In an alternative way, Gadget definitions defined on pages in the Gadget definition namespace when $wgGadgetsRepoClass
is set to 'GadgetDefinitionNamespaceRepo'
.
![]() | Migration of the existing gadget definitions is not yet supported, so you will lose previously defined gadgets after changing this option. |
Once created with at least one valid gadget, gadgets defined there show up in the "Gadgets" section of Special:Preferences, so users can pick the gadgets they would like to use. An overview of the gadgets defined by MediaWiki:Gadgets-definition is also shown on Special:Gadgets, along with links to the respective system messages, for easy editing. Statistics for non-default gadget usage can be seen at Special:GadgetUsage.
格式
使用MediaWiki Gadgets Definition
Each line in MediaWiki:Gadgets-definition that starts with one or more "*" (asterisks) characters defines a gadget; it must have the following form:
* gadget_name [options (can be omitted)] | page names
The first field ("gadget_name" in the example) is the gadget's internal name, and references a system message (MediaWiki:Gadget-gadget_name in the example) that contains a short description of the gadget, using wiki syntax.
[A-Za-z]
) and may be followed by any number of letters, digits ([0-9]
), hyphens (-
), underscores (_
), colons (:
), and periods (.
).Options format:
[option1 | option2 | ... optionN]
whitespace can be omitted. A single option can either consist of a single option name (in this case it is a flag option), or contain a comma-separated list of values:
option = value1, value2, value3
Examples:
* mygadget|mygadget.js|mygadget.css
or
* mygadget[ResourceLoader]|mygadget.js|mygadget.css
or
* mygadget[rights=foo,bar]|mygadget.js|mygadget.css
or
* mygadget[ ResourceLoader | rights=foo, bar ] | mygadget.js | mygadget.css
使用小工具定義命名空間
建立Gadget definition:mygadget頁面並放入以下的JSON程式碼與mygadget[ ResourceLoader | rights=foo, bar ] | mygadget.js | mygadget.css
有相同的效果。
{
"settings": {
"rights": [ "foo", "bar" ],
"default": false,
"hidden": false,
"skins": [],
"category": ""
},
"module": {
"scripts": [ "mygadget.js" ],
"styles": [ "mygadget.css" ],
"peers": [],
"dependencies": [],
"messages": [],
"type": ""
}
}
In above example, the Gadget:Mygadget.js and the Gadget:mygadget.css are used.
And remember the ResourceLoader
option is always true in the gadget definition namespace.
Editing pages in the Gadget namespace requires the gadgets-edit
right and editing pages in the Gadget definition namespace requires the gadgets-definition-edit
right.
$wgGroupPermissions['interface-admin']['gadgets-edit'] = true;
$wgGroupPermissions['interface-admin']['gadgets-definition-edit'] = true;
选项
名称 | 參數 | 描述 | 以来 |
---|---|---|---|
ResourceLoader |
None | Marks gadget's scripts as compatible with ResourceLoader. | ? |
dependencies |
Comma-separated module names | See list of default modules. Note that this option has no effect if current gadget has no ResourceLoader-compatible resources (i.e. no styles and scripts not marked as compatible). | ? |
rights |
Comma-separated privilege names | Make the gadget available (and visible in preferences) only to users who have the specified privileges. | ? |
hidden
|
None | Hide the gadget from the Preferences page. This can be used in two ways:
|
1.28 |
skins |
Comma-separated skin names | Make the gadget available (and visible in preferences) only to users who use the specified skins. Before MediaWiki 1.32 it was taking into consideration the skin set in preferences for the user, not the current displayed one (like when adding ?useskin=monobook in the URL, 任务T199478) | ? |
default |
None | Enable the gadget by default for everyone (including IPs). Registered users can still disable it in their preferences. | 1.18 |
targets
|
desktop (default), mobile or desktop,mobile
|
Set the RL target(s) for the gadget. | ? |
type
|
styles or general
|
Use styles for modules that only modify styling for elements already on the page (e.g. when customizing the skin, layout, or article content). It will cause the CSS files of the module to be included from the page HTML instead of being loaded via JavaScript. For details, see ResourceLoader/Migration guide (users)#Gadget type.
Note: Using |
1.28 |
peers
|
Comma-separated module names | Require CSS-only gadgets (which usually would be hidden). These gadgets will be loaded sooner than by dependencies , and will be loaded even if JavaScript is disabled. For details, see ResourceLoader/Migration guide (users)#Gadget peers.
|
1.29.0-wmf.11 (pre-release) |
|
None | (removed in 1.29) Makes the gadget to be top-loaded. This should be used sparingly, but may be needed for some initialization stuff like registering plugins with VisualEditor. | ? |
You can specify extra dependencies for your gadgets, for example:
* mygadget[ResourceLoader|dependencies=jquery.ui, jquery.effects.clip]|mygadget.js|mygadget.css
Here, we ask ResourceLoader to load modules jquery.ui
and jquery.effects.clip
with mygadget.
Note that gadgets can't depend on scripts from pages, static files or external URLs, only on modules already registered in ResourceLoader.
To make a script from a page depend on another script from a page, each should be a gadget which registers itself as a module in ResourceLoader, then they can be made to have dependencies using the following syntax:
* childgadget[ResourceLoader|dependencies=ext.gadget.parentgadget]|childgadget.js
To enable a gadget by default, use "default
":
* mygadget[ResourceLoader|default|dependencies=mediawiki.util]|mygadget.js|mygadget.css
To make the gadget available only to users with appropriate permissions, set the rights
option.
For example,
* ImprovedDeletion [rights=delete] | ImprovedDeletion.js
makes the gadget available only to users who can actually delete pages. Note that restrictions are based on permissions, not user groups like administrators or bureaucrats. Here are some real examples:
* modrollback[ResourceLoader|rights=rollback]|modrollback.js * UTCLiveClock[ResourceLoader|rights=purge]|UTCLiveClock.js * Ajax_sysop[ResourceLoader|rights=patrol,rollback,markbotedits,delete]|Ajax_sysop.js
ResourceLoader support
Each gadget's CSS is always loaded via the ResourceLoader.
However, older JavaScript is often incompatible with RL, so every gadget must be explicitly marked as compatible in order to have its scripts loaded by RL.
Otherwise, plain old <script src="/w/index.php?title=MediaWiki:Gadget-gadget_name.js&action=raw&ctype=text/javascript">
will be used.
Every gadget that at least partially uses ResourceLoader (that is, that has styles or compatible scripts) has its own RL module.
The modules are named ext.gadget.<gadget name>
.
页面
The remaining fields on the line refer to the JavaScript or CSS code that makes up the gadget, contained in system messages (MediaWiki:Gadget-mygadget.js and MediaWiki:Gadget-mygadget.css in the example); the names of those messages must end with ".js" or ".css", respectively. A gadget can use any number of code messages, specifically, common code can be put into a code message used by several gadgets, in addition to their own specific code, e.g:
* frobinator|commonStuff.js|frob.js|frob.css|pretty.css * l33t|commonStuff.js|tools.js|l33t.js
Please note that if your code contains strings that could be interpreted as wiki syntax (e.g.
the signature code ~~~~
), you may want to enclose your code into <nowiki> and </nowiki> and put these tags in JavaScript or CSS comments so they're not interpreted when actually used.
See the first and last lines of MediaWiki:Gadget-externalsearch-bar.js for an example.
章節
The list of gadgets in MediaWiki:Gadgets-definition can be broken into sections using lines that start and end with two or more "=" (equals) characters, enclosing the name of a system message that defines the section's name - for example:
== interface-gadgets ==
This would define a new section, with the title defined on the page MediaWiki:Gadget-section-interface-gadgets.
待办事项
- Fulfill 基礎小工具
List of gadget scripts
Gadgets | Usage | |||||
---|---|---|---|---|---|---|
MediaWiki.org | commons | meta | wikipedia | |||
en | ||||||
installed | i | i | i | |||
UTCLiveClock.js | ![]() |
![]() |
![]() |
![]() | ||
SearchFocus.js | ![]() |
![]() | ||||
Syntax highlighter | ![]() |
|||||
mySandbox | ![]() | |||||
BugStatusUpdate | ![]() |
![]() | ||||
Pages gadgets | ||||||
edittop.js | ![]() |
![]() |
![]() |
![]() | ||
HomeArrow.js | ||||||
Category gadgets | ||||||
HotCat.js | ![]() |
![]() |
![]() |
![]() | ||
Tab gadgets | ||||||
addsection-plus.js | ![]() |
|||||
Sidebar gadgets | ||||||
SubPages.js | ||||||
UserRights.js |
參見
![]() | 此扩展被用于一个或多个维基媒体项目上。 这可能意味着扩展稳定且工作良好,足以用在同等高流量的网站上。 请在维基媒体的CommonSettings.php和InitialiseSettings.php配置文件中寻找此扩展名称以查看安装它的网站。 详细的已安装扩展的完整列表可在wiki的Special:Version页面找到。 |
- Extensions bundled with MediaWiki 1.18/zh
- Stable extensions/zh
- Personalization extensions/zh
- Special page extensions/zh
- API extensions/zh
- GPL licensed extensions/zh
- Extensions in Wikimedia version control/zh
- BeforePageDisplay extensions/zh
- CodeEditorGetPageLanguage extensions/zh
- ContentHandlerDefaultModelFor extensions/zh
- DeleteUnknownPreferences extensions/zh
- EditFilterMergedContent extensions/zh
- GetPreferences extensions/zh
- PageSaveComplete extensions/zh
- ResourceLoaderRegisterModules extensions/zh
- UserGetDefaultOptions extensions/zh
- WgQueryPages extensions/zh
- All extensions/zh
- Extensions used on Wikimedia/zh
- Gadgets/zh
- JavaScript/zh