מדריך:ממשק/JavaScript
הדף MediaWiki:Common.js מכיל JavaScript אשר ייטען עבור כל המשתמשים. הזינו "MediaWiki:Common.js" לתוך תיבת החיפוש באתר הוויקי שלכם. הוא יודיע לכם אם הדף לא קיים; אם הדבר קורה ויש לכם את הרשאות המשתמש המתאימות לכך, פשוט צרו אותו עם הקוד שברצונכם להריץ. ישנם דפים דומים שמשפיעים רק על משתמשים שבחרו בערכת עיצוב כלשהי (ראו להלן).
אם $wgAllowUserJs
מוגדר כ-true, משתמשים יכולים להתאים אישית את הממשק עבור עצמם בלבד על ידי יצירה ויבוא של סקריפטים אישיים בדפי משנה מסוימים של משתמשים.
Extension:Gadgets הופך את האפשרות לשיתוף JavaScript מצד מפעילי המערכת והמשתמשים לקלה יותר, ראו Gadget kitchen .
דף זה מכסה את משתני המצב והתצורה הזמינים. ל-JavaScript API הכללי, עיין ב[$url JSDuck documentation].
רשימה של דפי JavaScript
Note that any scripts or gadgets won't load on Special:Preferences itself, or if safemode is used.
סקריפטים גלובליים
- MediaWiki:Common.js - כל הסקינים, אך בהתעלמות מהאתר הנייד שסופק על ידי Extension:MobileFrontend
- MediaWiki:skinname.js - לפי סקין, לדוגמאMediaWiki:Vector.js
- MediaWiki:Group-group.js - לכל קבוצת משתמשים, לדוגמא MediaWiki:Group-sysop.js
- MediaWiki:Mobile.js - ספציפית לאתר הנייד ומסופק על ידי Extension:MobileFrontend
- Special:Gadgets - can be activated by any user in Preferences , or may be enabled by default for all users; provided by Extension:Gadgets
סקריפטים אישיים
הם זמינים רק אם $wgAllowUserJs
מוגדר ל-true
.
- User:Example/common.js - all skins - introduced in MW v1.17
- User:Example/skinname.js - per skin, for example User:Example/vector.js; always lowercase)
- User:Example/global.js - לכל Manual:Wiki family , אם 2$ נמצא בשימוש עבור המשפחה הזו
כדי להקל על תכנות JavaScript, תוכנת MediaWiki מציגה מספר ערכי תצורה באובייקט הנקרא mw.config .
- מסיבות מהדור הקודם, שמות אלו הופכים למשתני JavaScript גלובליים אם 1$ נכון, ולכן הם משתמשים בקידומת כדי למנוע התנגשויות.
- תת-קבוצה של שמות אלו תואמת ל-$משתני wg ב-PHP, אבל אחרים לא קשורים.
- מלבד השמות ברשימה זו, תוספים רבים גם מגדירים משתני תצורה נוספים של JavaScript עם קידומת 'wg'.
ניתן לגשת לערכים אלו דרך mw.config
, המתועד ב-ResourceLoader/Module Core.
כל האתר
שם | סוג | תיאור | זמינות | Example output |
---|---|---|---|---|
debug
|
Integer (MW 1.36+) / Boolean (<= MW 1.35) | Since MediaWiki 1.36+, 0 means debug mode is off, and a positive non-zero number means debug mode is on (e.g. 1 or 2 ).
In MediaWiki 1.35 and earlier, |
MW 1.17+ | 0 |
skin
|
String | The internal name of the currently used skin. | MW 1.8+: all skins and pages |
MW <1.7 (monobook skin)vector |
stylepath
|
String | Full URL to the root directory for skins, containing stylesheets and skin-specific scripts. The path does not contain the skin subdirectory, and is not terminated by a "/". | MW 1.8+: all skins and pages |
MW <1.7 (monobook skin)/w/skins |
wgArticlePath
|
String | נתיב מקומי, החל מהשורש, למאמרי הדרכה, המכיל מראה־מקום "$1" שעשוי להיות מוחלף בכותרת דף כדי לקבל כתובת URL חוקית לדף זה. בהינתן כותרת דף חוקית title , ניתן לבנות כתובת חוקית באמצעות wgArticlePath.replace('$1', title) . ראו גם $wgArticlePath .
|
MW 1.8+ | /wiki/$1 |
wgCaseSensitiveNamespaces
|
Array | The IDs of the namespaces treated as case-sensitive by MediaWiki. Determined by the values of them $wgCapitalLinks and $wgCapitalLinksOverrides configuration variables.
|
r90234) | MW 1.18+ ([] |
wgContentLanguage
|
String | The language code for the default content language of the wiki. | MW 1.8+ | en |
wgContentNamespaces
|
מערך של מספרים שלמים | המזהים של מרחבי השמות הנחשבים מבחינת מדיה־ויקי ל"מרחבי תוכן". Equivalent to the value of the $wgContentNamespaces configuration variable, with 0 included if it is not already.
|
git #3d87e3a8) | MW 1.23+ ([100, 102, 104, 106, 0] |
wgDBname
|
String | שם מסד הנתונים של ויקי. | MW 1.13+ | mediawikiwiki |
wgWikiID
|
String | The wiki identifier. Should be preferred over wgDBname .
|
d45baf7f0734) | MW 1.34+ (mediawikiwiki |
wgExtensionAssetsPath
|
String | Root path used for extension static assets (e.g. images). Append '/' then the name of the extension to get the root path for a given extension. | r82247) | MW 1.18+ (/w/extensions |
wgFormattedNamespaces
|
Object | נותן מיפוי ממזהי מרחבי־שמות לשמות מרחבים מקומיים. לאובייקט זה יש תכונה לכל מרחב, כך שמספר המרחב הוא התכונה ושמו המילולי הוא הערך שלה. כינויים או canonical names אינם כלולים. | MW 1.16+ | {0: '', 1: 'Talk:', 2: 'User', ... } |
wgNamespaceIds
|
Object | נותן מיפוי משמות מרחבים למזהי מרחבים. לאובייקט זה יש תכונה עבור כל שם של מרחב, כולל שמות מקומיים וקנוניים וכן כינויים, כך ששם המרחב הוא מפתח והמזהה שלו הוא ערך מספרי של המפתח. The keys are all lowercase, with spaces replaced by underscores. | MW 1.16+ | {media: -2, special: -1, "": 0, talk: 1, user: 2, ... } |
wgScript
|
String | נתיב מלא לסקריפט של נקודת הגישה הראשית, החל מהשורש, כולל שם הסקריפט המלא עם סיומת. On WMF wikis, normally "/w/index.php". ראו גם $wgScript . | MW 1.11+ | /w/index.php |
wgScriptPath
|
String | The path part of wgScript , without trailing "/". This is the path to use for direct calls to the php access points such as index.php or api.php . See also $wgScriptPath .
|
MW 1.8+ | /w |
wgServer
|
String | The server URL, not terminated by "/". The combination wgServer + wgScriptPath + "/api.php" , for instance, results in a valid URL to the API access point script.
|
MW 1.8+ | //www.mediawiki.org |
wgServerName
|
String | The name of the server, without the protocol or trailing slash (e.g. "en.wikipedia.org"). | 72c0ce43a854) | MW 1.24+ (www.mediawiki.org |
wgSiteName
|
String | The name of the site, as defined by $wgSitename . | MW 1.16+ | MediaWiki |
wgVariantArticlePath
|
String or false
|
If a wiki has language variants (such as the Chinese and the Serbian Wikipedias), set to a path beginning at the root for language variants other than wgContentLanguage . The path contains two placeholders: "$1" is to be replaced by the page title, and "$2" is to be replaced by the language code of the language variant (e.g. "zh-tw"). If the wiki does not have language variants, set to false . See also $wgVariantArticlePath .
|
MW 1.13+ | false |
wgVersion
|
String | Identifies the version of MediaWiki that served the page. | MW 1.12+ | 1.42.0-wmf.26 |
כל הדפים (ספציפי עבור דף/משתמש)
שם | סוג | תיאור | זמינות | Example output |
---|---|---|---|---|
wgAction
|
String | The action performed, e.g. "edit" for edit pages, or "view" for page views. See Manual:Parameters to index.php#Actions. | MW 1.10+ | view |
wgArticleId
|
Integer | The internal ID (page ID) of the page. For non-existent pages and special pages, it is zero. | MW 1.8+ | 17317 |
wgCanonicalNamespace
|
String | The canonical (i.e., not localized or aliased) namespace name of the page. | MW 1.8+ | Manual |
wgCanonicalSpecialPageName
|
String or false or not defined
|
On special pages, the canonical (i.e., not localized or aliased) name of the special page; otherwise it is set to false (since MW 1.16; previously not defined at all in that case).
|
MW 1.9+ | false |
wgCategories
|
Array of strings | The list of all the categories a page belongs to. This is essentially a JavaScript version of the category box shown on the page (grey box at bottom of page, in Monobook/Vector). If the category box is not shown on the current page (as is the case when editing/viewing history), wgCategories will be an empty array.
|
MW 1.16+ | ['JavaScript'] |
wgCurRevisionId
|
Integer | The top revision ID of the currently viewed page at the time the page was served. Also set on diff and history pages; zero for special pages. | MW 1.9+ | 6400980 |
wgIsArticle
|
boolean | true if the page displays the content of a wiki page, e.g. when viewing a page (regardless of namespace), or when viewing an old revision or diff with rendered content below it. It is false for anything else (edit form, history page, special pages, most generated pages, etc.).
This variable is badly named – it is not related to a page being a main namespace "article".
|
MW 1.8+ | true |
wgIsProbablyEditable
|
boolean | True if the page is probably editable (based on Title::quickUserCan ) by the current user. The 'probably' is necessary for performance reasons. An exact editability check is too costly here, due to cascading protection and hook-based extensions like TitleBlacklist that may be enabled. If this is true, it is likely to be editable. If it is false, it is definitely not editable.
|
(git #0bbc3589) | true |
wgIsRedirect
|
boolean | true if the page is a redirect to a wiki page using #REDIRECT [[Target page name]] . It is false for anything else (normal pages, special pages, most generated pages, etc.).
|
MW 1.22+ (gerrit:75478) | false |
wgNamespaceNumber
|
Integer | The number of the namespace the page is in. | MW 1.8+ | 100 |
wgPageContentLanguage
|
String | Language code of the page content language (according to $context->getTitle()->getPageLanguage() )
|
MW 1.19+ (r104483) | en |
wgPageContentModel
|
String | 'wikitext' on typical wiki pages, 'javascript' on pages interpreted as JavaScript, 'css' on pages interpreted as CSS, 'Scribunto' on pages interpreted as Scribunto (Lua).
|
gerrit:62178) | MW 1.22+ (wikitext |
wgPageName
|
String | The full name of the page, including the localized namespace name, if the namespace has a name (the main namespace (number 0) doesn't), and with spaces replaced by underscores. To get only the title without the namespace, use wgTitle .
|
MW 1.8+ | Manual:Interface/JavasScript |
wgPageParseReport
|
Object | Parser limit report for the page when parser data is available. Includes data about parset limits, Lua statistics when Scribunto extension is enabled and parser cache information. | MW 1.28+ (git #316207) | {limitreport: {...}, scribunto: {...}, cachereport: {...}} |
wgRedirectedFrom
|
String | When redirected contains the title of the page we were redirected from. If the page was not redirected, the value is omitted entirely (absent in mw.config ). Uses the same format as wgPageName
|
MW 1.19+ (r104668) | null |
wgRelevantPageName
|
String | The full name of the page to which content actions and navigation links (e.g. a skin's tabs) apply. The AJAX watch function uses this to work correctly on special pages such as Special:MovePage and Special:WhatLinksHere. | MW 1.19+ (r113737) | Manual:Interface/JavaScript |
wgRelevantUserName
|
String or unset | The relevant name of the user to which content actions and some extra navigation links (e.g. link to user rights or user contributions) apply. | MW 1.23+ (git #88773) | null |
wgRelevantPageIsProbablyEditable
|
boolean | Like wgIsProbablyEditable , but applied to the contextually relevant page name from wgRelevantPageName instead of strictly the current page being viewed. For example, when viewing a page "Special:MovePage/Example " this will indicate whether the subject page is editable.
|
MW 1.30+ (git #dbfe9c99) | true |
wgRestrictionEdit
|
Array of strings or unset | If the page is editable at all (and is not a special page) and editing of the page is restricted to some user groups, the array contains the minimum user group a user must be in in order to edit the page. For semi-protected pages, it'd contain ["autoconfirmed"] ; for fully protected pages ["sysop"] . If there are no explicit restrictions, the value is [] (an array with no elements).
This array contains only explicit protections. Namespace-wide protections (e.g. MediaWiki namespace, $wgNamespaceProtection ), cascading protections, or "protections" brought about by the TitleBlacklist extension's "noedit" attribute, are ignored by this array. On such pages, the value is normally If the page does not exist, the variable is not set. |
MW 1.14+ | [] |
wgRestrictionMove
|
Array of strings | If the page is movable at all (and is not a special page) and moving of the page is restricted to some user groups, the array contains the minimum user group a user must be in in order to move the page. For semi-moveprotected pages, it'd contain ["autoconfirmed"] ; for fully moveprotected pages ["sysop"] . If there are no explicit restrictions, the value is [] (an array with no elements).
This array contains only explicit protections. Namespace-wide protections (e.g. MediaWiki namespace, $wgNamespaceProtection ), cascading protections, or "protections" brought about by the TitleBlacklist extension's "moveonly" attribute, are ignored by this array. On such pages, the value is normally |
MW 1.14+ | [] |
wgRevisionId
|
Integer | The revision ID of the currently viewed revision, or the right revision for diff views (But 0 when diffonly=yes, משימה T231744). Also set on diff pages; zero for special pages, history pages, or anywhere else inapplicable. | MW 1.22+ git #7fa7b71e | 6400980 |
wgSearchType
|
String or unset | The name of the search backend used to execute search requests. | MW 1.23+ (git #118655) | CirrusSearch |
wgTitle
|
String | The page title, without the namespace. May contain spaces – does not contain underscores. To get the title including the namespace, use wgPageName .
|
MW 1.8+ | Interface/JavaScript |
Related to the user currently viewing the page:
שם | סוג | תיאור | זמינות | Example output |
---|---|---|---|---|
wgUserEditCount
|
Integer | The number of edits the current user made (null if not logged in). | MW 1.21+ | 556 |
wgUserGroups
|
Array of strings | An array containing all the (local) user groups the current user is a member of, or null for non-logged-in users. User groups are identified by the internal user group names, e.g. "sysop", "autoconfirmed", "bureaucrat", and so on. The default user group is named "*".
|
MW 1.10+ | ['autopatrolled', '*', 'user', 'autoconfirmed'] |
wgUserId
|
Integer | The numeric ID of the current user (null if not logged in). | MW 1.21+ | 12311063 |
wgUserLanguage
|
String | The language code for the user's interface language, as set in Special→Preferences (which may be overridden by a uselang= parameter in the URL).
|
MW 1.8+ | en |
wgUserName
|
String | The user name of the user currently viewing the page, if it's a logged-in user. For non-logged-in users, it is null (not the user's IP address, unlike PHP $wgUser->getName() on the server).
|
MW 1.8+ | Your Username |
wgUserRegistration
|
Integer | The time and date on which the current user registered, represented as milliseconds since epoch. Null if not logged in. | MW 1.21+ | 1514273653000 |
דפים מסוימים
Some additional variables are present only depending on the page namespace, wiki configuration and/or user preferences.
שם | סוג | תיאור | זמינות |
---|---|---|---|
Main Page | |||
wgIsMainPage
|
Boolean | true if the current page is the main page of the wiki. Omitted entirely otherwise (defaulting to null in mw.config ).
|
MW 1.18+ |
If the content language has variants: | |||
wgUserVariant
|
String | If the wiki has language variants, the language code of the user's preferred variant. If the wiki does not have variants, the variable is not configured (does not exist), i.e.: mw.config.exists( 'wgUserVariant' ); // false mw.config.get( 'wgUserVariant' ); // null .
|
MW 1.16+ |
After saving an edit | |||
wgPostEdit
|
String | "saved" if the user just saved this page. "created" if the user just created this page. "restored" if the user just restored this page by going to the history page, clicked on a timestamp link for an old revision, clicked on edit and then saved. null otherwise. Note that:
|
MW 1.21+ (gerrit:50480) |
When comparing revisions | |||
wgDiffOldId
|
Integer | Revision ID of the "old" revision when viewing a diff. Only available when viewing a revision comparison. | MW 1.30+ (git #a469795e) |
wgDiffNewId
|
Integer | Revision ID of the "new" revision when viewing a diff. Only available when viewing a revision comparison. | MW 1.30+ (git #a469795e) |
ספציפי עבור דף (הרחבת Wikibase)
Some additional information will be available when the site supports ויקיבייס :
שם | סוג | תיאור | זמינות |
---|---|---|---|
wgWikibaseItemId
|
String | The Wikibase item ID of the current page. Currently, in the edit mode, this variable is not set. See phab:T185437. | ? |
Hooks for extensions
- ResourceLoaderGetConfigVars - Since MediaWiki 1.17 extensions can add their own site-wide variables through this hook.
- MakeGlobalVariablesScript - Since MediaWiki 1.14 extensions can add their own variables to the OutputPage. If the variable is not dependent on the page being viewed, use the ResourceLoaderGetConfigVars hook instead.
See also
- How to enhance wiki content with JavaScript
- TypeScript definitions for the JavaScript interface (work in JavaScript projects as well in popular IDEs)