ส่วนขยาย:อุปกรณ์เสริม
![]() Release status: stable |
|
---|---|
![]() |
|
Implementation | MyWiki , Special page , API |
Description | อนุญาตให้ผู้ใช้เปิดใช้งานอุปกรณ์เสริมที่ผู้ใช้จัดเตรียมโดย JS จากหน้าการตั้งค่า |
Author(s) | Daniel Kinzler (Duesentriebคุย) |
Compatibility policy | Snapshots releases along with MediaWiki. Master is not backward compatible. |
MediaWiki | 1.19+ |
License | GNU General Public License 2.0 or later |
Download | README |
Example | Wikimedia Commons: ภาพรวมอุปกรณ์เสริม, การตั้งค่าผู้ใช้ (คลิก อุปกรณ์เสริม" โดยคุณต้องลงชื่อเข้าใช้ก่อน) |
|
|
Quarterly downloads | 209 (Ranked 53rd) |
Public wikis using | 4,529 (Ranked 177th) |
Translate the Gadgets extension if it is available at translatewiki.net | |
Issues | Open tasks · Report a bug |
ส่วนขยาย อุปกรณ์เสริม ช่วยให้ผู้ใช้สามารถเลือก อุปกรณ์เสริม ที่ใช้ JavaScript หรือ CSS ที่ผู้ใช้ Wiki รายอื่นจัดเตรียมไว้
อุปกรณ์เสริม ประกอบด้วย JavaScript และ/หรือ CSS snippets ที่อยู่บนหน้าเว็บในเนมสเปซมีเดียวิกิ แต่ละอุปกรณ์เสริมถูกกำหนดโดยบรรทัดใน MediaWiki:Gadgets-definition โดยระบุชื่อและคำอธิบายสำหรับอุปกรณ์เสริม และรายการของข้อมูลโค้ด JS และ CSS ที่ใช้ (ดูส่วน การใช้งาน ด้านล่าง)
เนื่องจากอุปกรณ์เสริมอยู่ในเนมสเปซ MediaWiki (รายการที่กำหนดอุปกรณ์เสริมรวมถึงข้อมูลโค้ดจริง) มีเพียง sysops (ผู้ดูแลระบบส่วนต่อประสานจาก 1.32) เท่านั้นที่สามารถแก้ไขโค้ดได้ นี่เป็นอย่างที่ควรจะเป็น: เฉพาะผู้ใช้ที่ได้รับความเชื่อถือโดยเฉพาะอย่างยิ่งจากชุมชน Wiki เท่านั้นที่จะสามารถแก้ไขโค้ด JavaScript ที่ผู้ใช้รายอื่นใช้ เนื่องจาก JavaScript สามารถใช้เพื่อติดตามสอดส่องบัญชีหรือสอดแนมบุคคลอื่นได้อย่างง่ายดาย
การติดตั้ง
- ดาวน์โหลดและวางไฟล์ลงในไดเร็กทอรีที่ชื่อ
Gadgets
ในโฟลเดอร์extensions/
ของคุณ - เพิ่มโค้ดต่อไปนี้ไว้ที่ด้านล่างของ
LocalSettings.php
ของคุณ:wfLoadExtension( 'Gadgets' );
สำเร็จ – ตรวจสอบที่ Special:Version บนวิกิของคุณเพื่อตรวจการติดตั้งส่วนขยาย
การใช้งาน

เมื่อสร้าง MediaWiki:Gadgets-definition ด้วยอุปกรณ์เสริมที่ถูกต้องอย่างน้อยหนึ่งรายการ ส่วน อุปกรณ์เสริม ใหม่จะแสดงเป็น Special:Preferences สำหรับผู้ใช้ทั้งหมด ผู้ใช้สามารถเปิดใช้งานอุปกรณ์เสริมที่พวกเขาต้องการใช้ที่นั่น ภาพรวมของอุปกรณ์เสริมที่กำหนดโดย MediaWiki:Gadgets-definition ในปัจจุบันยังแสดงเป็น Special:Gadgets พร้อมกับลิงก์ที่เป็นประโยชน์ไปยังหน้าการแปลภาษาและ script/style ที่เกี่ยวข้องสำหรับการสร้างหรือแก้ไขที่ง่ายดาย สถิติการใช้งานอุปกรณ์เสริมในค่าเริ่มต้นสามารถดูได้ที่ Special:GadgetUsage
คำจำกัดความรูปแบบ
แต่ละบรรทัดในหน้า MediaWiki:Gadgets-definition ควรขึ้นต้นด้วยอักขระ "*" (ดอกจัน) เพื่อกำหนดอุปกรณ์เสริม บรรทัดใช้รูปแบบต่อไปนี้:
* mygadget [ตัวเลือก] | ชื่อเพจ
ฟิลด์แรก ("mygadget" ในตัวอย่าง) คือ ชื่อภายใน ของอุปกรณ์เสริม ป้ายกำกับสำหรับหน้าการกำหนดลักษณะมาจากหน้าข้อความอินเทอร์เฟซ (MediaWiki:Gadget-mygadget) ซึ่งสามารถเขียนชื่อที่เหมาะสมและคำอธิบายสั้น ๆ ได้ ซึ่งอนุญาตให้ใช้มาร์กอัปข้อความวิกิได้
[A-Za-z]
) และอาจตามด้วยตัวอักษรจำนวนเท่าใดก็ได้ ตัวเลข ([0-9]
) ยัติภังค์ (-
) ขีดล่าง (_
) และจุด (.
) เหตุผลสำหรับข้อจำกัดนี้คือชื่อภายในต้องถูกต้องเป็นชื่อของ [ชื่อฟอร์ม HTML https://www.w3.org/TR/html4/types.html#type-id] เป็นคีย์ข้อความอินเตอร์เฟส MediaWiki และเป็นชื่อโมดูล ResourceLoaderรูปแบบตัวเลือก:
[ResourceLoader | ตัวเลือกที่ 1 | ตัวเลือกที่ 2 | ... ตัวเลือก...]
The ResourceLoader flag is required unless the gadget contains only styles. Options that are "flags" only need to have their name written to be turned on. Options that need a value are followed by an equals sign and a comma-separated list of values. All whitespace is optional and may be omitted.
[ResourceLoader | myflag | mykey = value1, value2, value3 ]
ตัวอย่าง:
* mygadget[ResourceLoader]|mygadget.js|mygadget.css
หรือ
* mygadget[ResourceLoader|package]| mygadget.js | mygadget-Foo.js | mygadget-data.json | mygadget.css
หรือ
* mygadget[ ResourceLoader | rights=foo, bar ] | mygadget.js | mygadget.css
Using Gadget Definition Namespace
มีสองวิธีในการกำหนดแกดเจ็ตโดยขึ้นอยู่กับ $wgGadgetsRepoClass
หากเป็น 'MediaWikiGadgetsDefinitionRepo'
(ค่าเริ่มต้น) รายการอุปกรณ์ที่ใช้ได้จะถูกกำหนดไว้ที่ MediaWiki:Gadgets-definition
ในอีกทางหนึ่ง คำจำกัดความของ Gadget ถูกกำหนดไว้บนเพจในเนมสเปซ Gadget definition เมื่อ $wgGadgetsRepoClass
ถูกตั้งค่าเป็น 'GadgetDefinitionNamespaceRepo'
การสร้างเพจ Gadget definition:mygadget
และใส่โค้ดด้านล่าง JSON มีผลเช่นเดียวกับ mygadget[ ResourceLoader | rights=foo, bar ] | mygadget.js | mygadget.css
{
"settings": {
"rights": [ "foo", "bar" ],
"default": false,
"package": false,
"hidden": false,
"skins": [],
"actions": [],
"category": ""
},
"module": {
"scripts": [ "mygadget.js" ],
"styles": [ "mygadget.css" ],
"datas": [],
"peers": [],
"dependencies": [],
"messages": [],
"type": ""
}
}
ในตัวอย่างข้างต้น จะใช้ Gadget:Mygadget.js
และ Gadget:mygadget.css
ตัวเลือก
ชื่อ | พารามิเตอร์ | รายละเอียด | ตั้งแต่ |
---|---|---|---|
ResourceLoader |
ไม่มี | 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
|
ไม่มี | 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, task T199478). |
? |
actions |
Comma-separated action names | Make the gadget available only on the specified page actions. E.g. actions = edit, history to load a gadget only while editing and on history pages. Specifying edit action will also load it on action=submit . Invalid actions effectively disable the gadget since it can't be run anywhere. |
1.38 |
default
|
ไม่มี | Enable the gadget by default for everyone (including IPs). Registered users can still disable it in their preferences. | 1.18 |
package
|
ไม่มี | Mark this gadget as packaged. In this mode, only the first JavaScript page will be executed. Other pages can be imported by using the require() function. This mode also enables use of JSON pages, which cannot be included otherwise. | 1.38 |
targets
|
desktop (ค่าเริ่มต้น), mobile หรือ desktop,mobile
|
Set the ResourceLoader target(s) for the gadget. | 1.21 (gerrit:60954) |
type
|
styles (default for CSS-only gadgets) หรือ general (default otherwise)
|
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.
Using
styles will not load in any specified JavaScript files. For gadgets that modify styling for elements through both JavaScript and CSS, two individual gadget definitions are required. |
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 |
supportsUrlLoad
|
ไม่มี | true | false | Make the gadget available to be loaded with the ?withgadget URL query parameter.
|
1.38 |
requiresES6
|
None | Allow use of ES6 syntax (ES2015) in the gadget. Enabling this means server-side syntax validation is skipped for the gadget. Any ES6-requiring gadgets are loaded together in a single web request, which isolates failures due to invalid or unsupported syntax to those gadgets only, without affecting other gadgets and MediaWiki software features. It is recommended to use a tool like ESLint to ensure only valid ES6 syntax is used. | 1.40.0-wmf.7 (gerrit:758086) |
|
ไม่มี | (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. | 1.22 (gerrit:75506) |
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
User rights
gadgets-edit
and gadgets-definition-edit
, which by default aren't given to any group.
You can add the following in your LocalSettings.php to provide the appropriate permissions for users who are within the interface-admin group.
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;
หน้า
The remaining fields on the definition line refer to the JavaScript, CSS or JSON source pages that makes up the gadget module. These are stored in the MediaWiki namespace as interfafce messages (MediaWiki:Gadget-mygadget.js and MediaWiki:Gadget-mygadget.css in the example). The page names must end with ".css", ".js", or ".json" respectively.
A gadget can use any number of source pages, e.g:
* frobinator[ResourceLoader]|frob.js|frob.css|pretty.css * l33t[ResourceLoader]|l33t.js * foobar[ResourceLoader|package]|foo.js|bar.js|foobar-data.json
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>...</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 ==
สิ่งนี้จะกำหนดส่วนใหม่โดยกำหนดชื่อเรื่องไว้ที่หน้า MediaWiki:Gadget-section-interface-gadgets
Popular gadgets
See meta:Gadgets for gadgets which are popular in Wikimedia communities.
ดูเพิ่ม
![]() | ส่วนขยายมีเดียวิกินี้ถูกใช้ในหนึ่งหรือหลายที่ในโครงการของวิกิมีเดีย นั่นควรจะหมายถึงว่าส่วนขยายนี้มีความเสถียรสูงและทำงานได้ดีพอในเว็ปไซต์ที่มีการเยี่ยมชมมาก ลองดูที่ชื่อของส่วนขยายนี้ในไฟล์การตั้งค่า CommonSettings.php และ InitialiseSettings.php เพื่อดูการติดตั้งว่าอยู่ที่ใด รายการฉบับสมบูรณ์ของส่วนขยายที่ติดตั้งแล้วได้ที่หน้า Special:Version ของวิกิ |
![]() | This extension is included in the following packages and/or wiki farms: This is not an authoritative list. Some wiki farms/hosts may contain this extension even if they are not listed here. Always check with your wiki farms/hosts or bundle to confirm. |
- Extensions bundled with MediaWiki 1.18/th
- Stable extensions/th
- Personalization extensions/th
- Special page extensions/th
- API extensions/th
- GPL licensed extensions/th
- Extensions in Wikimedia version control/th
- BeforePageDisplay extensions/th
- CodeEditorGetPageLanguage extensions/th
- ContentHandlerDefaultModelFor extensions/th
- DeleteUnknownPreferences extensions/th
- EditFilterMergedContent extensions/th
- GetPreferences extensions/th
- PageDeleteComplete extensions/th
- PageSaveComplete extensions/th
- PreferencesGetIcon extensions/th
- PreferencesGetLegend extensions/th
- ResourceLoaderRegisterModules extensions/th
- UserGetDefaultOptions extensions/th
- WgQueryPages extensions/th
- All extensions/th
- Extensions used on Wikimedia/th
- Extensions included in BlueSpice/th
- Extensions included in Canasta/th
- Extensions available as Debian packages/th
- Extensions included in Fandom/th
- Extensions included in Miraheze/th
- Extensions included in MyWikis/th
- Extensions included in ProWiki/th
- Extensions included in semantic::core/th
- Extensions included in wiki.gg/th
- Extensions included in WikiForge/th
- Extensions included in Telepedia/th
- Gadgets/th
- JavaScript/th