User:NhacNy2412/nháp

From Meta, a Wikimedia project coordination wiki

Một số lệnh[edit]

  • mw.config.get('wgUserLanguage') → lấy id ngôn ngữ (vi, zh, en)
  • mw.config.get('wgDBname') → lấy tên wiki (viwiki, metawiki, wikidatawiki)
  • mw.config.get('wgUserName') → lấy user name
  • mw.config.get('wgNamespaceNumber')
  • mw.config.get('wgContentLanguage')
  • mw.config.get('wgServer') → //meta.wikimedia.org

mw.config [edit]

Site-wide[edit]

Name Type Description
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, false and true were used (phab:T85805).

skin String The internal name of the currently used skin. The "Classic" skin is called "standard".
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 "/".
wgArticlePath String Local path, starting at the root, to reference articles, containing a "$1" placeholder that may be replaced by a page title to get a valid URL to that page. Given a valid page title title, a valid URL may be constructed using wgArticlePath.replace('$1', title). See also $wgArticlePath .
wgCaseSensitiveNamespaces Array The IDs of the namespaces treated as case-sensitive by MediaWiki. Determined by the values of them $wgCapitalLinks and $wgCapitalLinksOverrides configuration variables.
wgContentLanguage String The language code for the default content language of the wiki.
wgContentNamespaces Array of integers The IDs of the namespaces considered "content namespaces" by MediaWiki. Equivalent to the value of the $wgContentNamespaces configuration variable, with 0 included if it is not already.
wgDBname String The name of the wiki's database.
wgEnableAPI Boolean true if the MediaWiki API is enabled at all; false otherwise.
wgEnableWriteAPI Boolean true if the MediaWiki write API is enabled at all; false otherwise. If wgEnableAPI && !wgEnableWriteAPI, only the read operations of the API are enabled.
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.
wgFormattedNamespaces Object Gives a mapping from namespace IDs to localized namespace names. For each namespace, the object has one entry that has the stringified namespace number as the key and the namespace name as its value. Aliases or canonical names are not included.
wgNamespaceIds Object Gives a mapping from namespace names to namespace IDs. For each namespace name, including aliases, the object has one entry that has namespace name as the key and the namespace ID as its integer value. Canonical names are not included. The keys are all lowercase, with spaces replaced by underscores.
wgScript String Full path to the main access point script, starting at the root, including the full script name with extension. On WMF wikis, normally "/w/index.php". See also $wgScript .
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 .
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.
wgSiteName String The name of the site, as defined by $wgSitename .
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 .
wgVersion String Identifies the version of MediaWiki that served the page.

All pages (user/page-specific)[edit]

Name Type Description
wgAction String The action performed, e.g. "edit" for edit pages, or "view" for page views. See Manual:Parameters to index.php#Actions.
wgArticleId Integer The internal ID of the page. For non-existent pages and special pages, it is zero.
wgCanonicalNamespace String The canonical (i.e., not localized or aliased) namespace name of the page.
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 not defined at all (up to and including MW 1.15) or is set to false (since MW 1.16).
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.
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.
wgIsArticle boolean true if the content displayed on the page is related to the source of the corresponding article on the wiki. So it is true when viewing a page (regardless of namespace), and also true when viewing a diff that has a rendered revision appended to the bottom of it. It is false for anything else (edit, history, special pages, most generated pages, etc.). ^ 
wgIsProbablyEditable boolean True if the page is probably editable (based on Template:Phpi) 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.
wgNamespaceNumber Integer The number of the namespace the page is in.
wgPageContentLanguage String Language code of the page content language (according to Template:Phpi)
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).
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.
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.
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
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.
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.
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.
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 [], unless additional protections have been applied specifically to that page.

If the page does not exist, the variable is not set.

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 [], unless additional protections have been applied specifically to that page.

wgRevisionId Integer The revision ID of the currently viewed revision, or the right revision for diff views (But 0 when diffonly=yes,
Tracked in Phabricator:
Task T231744
). Also set on diff pages; zero for special pages, history pages, or anywhere else inapplicable.
wgSearchType String or unset The name of the search backend used to execute search requests.
wgTitle String The page title, without the namespace. May contain spaces – does not contain underscores. To get the title including the namespace, use wgPageName.
Name Type Description
wgUserEditCount Integer The number of edits the current user made (null if not logged in).
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 "*".
wgUserId Integer The numeric ID of the current user (null if not logged in).
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).
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 Template:Phpi on the server).
wgUserRegistration Integer The time and date on which the current user registered, represented as milliseconds since epoch. Null if not logged in.

Some pages[edit]

Name Type Description
Main Page
wgIsMainPage Boolean true if the current page is the main page of the wiki. Omitted entirely otherwise (defaulting to Template:Inline-code in mw.config).
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.:
Template:Inline-code
Template:Inline-code.
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:
  1. On null edits, this is null, not "saved"
  2. When using "undo", this is "saved"
  3. On rollback, this is null
When comparing revisions
wgDiffOldId Integer Revision ID of the "old" revision when viewing a diff. Only available when viewing a revision comparison.
wgDiffNewId Integer Revision ID of the "new" revision when viewing a diff. Only available when viewing a revision comparison.

Actions[edit]

The following is a list of values for the action parameter.

Some of these actions can be enabled/disabled by using a dedicated configuration setting in LocalSettings.php . Where available, these local settings are listed.[1]
Name Function Example
view View is the default action; view is the one action that is used when no action is explicitly given meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=view
watch Adds the page to the user's watchlist meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=watch
unwatch Removes the page from the user's watchlist meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=unwatch
delete Deletes a page By default, delete returns a form for the user to confirm deletion and specify a reason.[2] meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=delete
revert Reverts to a previous version of an image. The following two other parameters are required:
  • oldimage, the id of the version to revert to;
  • wpEditToken, a valid edit token;
rollback Rollbacks the last edits made by the last editor of the page; in other words, it restores the last version of the article whose editor is not the last one. The edit is marked as minor and a default edit summary is used.[3] The following two other parameters are required:
  • from is the username whose edits are to be reverted
  • token is a rollback token; used to prevent users from being tricked into performing an unwanted rollback by following a link or clicking a button in an external website.
meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=rollback&from=John&token=d7aaa6c\
protect Shows or changes the protection levels of a page:
  • By default, this script returns a form showing the current protection levels of the page, allowing the user to change the protection levels of the page.[4]
meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=protect
unprotect Same page as protect (unprotect and protect are the same page, and do the same thing). meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=unprotect
markpatrolled Marks an edit as patrolled; see Help:Patrolled edit on Meta. rcid is the id of an edit in the recentchanges table
render Outputs the HTML rendering of the entire page content; similar to the view action, but only the unstyled article text is output, not any part of the user interface (additional toolboxes, search box, stylesheets, etc.). <cite id="endnote_ For more stable programmatic access or to retrieve the HTML of only a piece of page content, you should use the parse API with page or pageid parameters." style="font-style: normal;">[[#ref_ For more stable programmatic access or to retrieve the HTML of only a piece of page content, you should use the parse API with page or pageid parameters.|^]]  meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=render
purge Clears the page's cache, forcing the page to be redisplayed from its source.
  • This action is performed only if requested via a POST request; otherwise, a form to confirm purging is shown (pressing the OK button posts the purge request, which is then executed).
meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=purge
submit Performs various actions related to changing the page (see below for more details):
  • By default, shows the page in edit form, with edit box.
  • Various other arguments can be used to:
  1. Change a page,
  2. preview a new version of the page, or
  3. show the difference with a new version (see edit and submit section below for details);
  4. If the default editor is set to VisualEditor, action=submit will force showing the source code editor. VisualEditor can be selected with veaction=edit URL parameter.
meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=submit
edit Shows the page in edit form. "edit" does almost the same thing as submit. meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=edit
editredlink Same as edit.[5] meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=editredlink
history Shows the history of the page. (See history, below) meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=history
historysubmit When viewing the difference between revisions, after clicking "compare selected revisions" on the history page. This requires a "diff" and/or "oldid" parameter, otherwise it just shows the page itself. meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=historysubmit&diff=456290&oldid=456270
raw Shows the raw content of the page. (See Raw, below) A pop up window will open up, asking whether you would like to save the page in index.php.[6] meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=raw
ajax Template:Deprecated-inline If enabled, calls a php function registered via $wgAjaxExportList ; see Manual:Ajax .[7]
credits Shows a list of people who contributed to the page in question using the real name specified in the user's preferences. Currently disabled on Wikimedia wikis, but is enabled by default on vanilla MediaWiki. translatewiki.net/w/i.php?title=Translating:MediaWiki&action=credits
info Shows information about the page, such as the number of users having it in their watchlist, the number of edits, the number of authors. See the Reimplement info action RfC for context. meta.wikimedia.org/w/index.php?title=Project:Sandbox&action=info
revisiondelete Set visibility restrictions on revision text, edit summary, and editor's username/IP address (requires deleterevision user right)

Namespace[edit]

Namespace id
Index Name Purpose Talk
0 (Main) "Real" content articles . Talk 1
2 User User pages . User talk 3
4 Meta Information about the wiki. Meta talk 5
6 File Media description pages File talk 7
8 MediaWiki Site interface customization MediaWiki talk 9
10 Template Template pages Template talk 11
12 Help Help pages Help talk 13
14 Category Category description pages Category talk 15
-1 Special Holds special pages N/A
-2 Media Alias for direct links to media files

Configuration values[edit]

You can always access the normal mw.config values provided by MediaWiki, but MoreMenu has some helpers that may offer a cleaner interface. Here is a complete list of the available data MoreMenu provides (through the config variable, as provided by the callback of the moremenu.ready hook):

name type description
config.project
domain string The domain of the wiki, same as mw.config.get('wgServerName')
siteName string The name of the project, e.g. "Wikipedia" or "Meta". Same as mw.config.get('wgSiteName')
dbName string Database name of the project, e.g. enwiki. Same as mw.config.get('wgDBname')
noticeProject string The internal name for the project, such as "wikipedia" or "meta". Same as mw.config.get('wgNoticeProject')
contentLanguage string Language of the project. Same as mw.config.get('wgContentLanguage')
config.page
nsId integer Namespace ID. Same as mw.config.get('wgNamespaceNumber')
id integer The ID of the page. Same as mw.config.get('wgArticleId')
name string Full title of the page, including the namespace. Same as mw.config.get('wgPageName')
escapedName string The full title of the page, with the characters ?!'()* escaped, for use when linking to external tools.

In most cases you should use encodedPageName, but some tools do not accept normal URL-encoded strings.

encodedName string The full title of the page, URL-encoded. Use this when linking to external tools.
protected boolean Whether or not the page is protected, in any form.
movable boolean Whether or not the page can be moved, based on the current user's rights.
config.targetUser
name string The username of the target user (e.g. Foobar when viewing User:Foobar). Same as mw.config.get('wgRelevantUserName')
escapedName string The username of the target user, with the characters ?!'"()* escaped, for use when linking to external tools.

In most cases you should use encodedUserName, but some tools do not accept normal URL-encoded strings.

encodedName string The username for the target user, URL-encoded. Use this when linking to external tools.
groups array An array of the user groups belonging to the target user.
rights array An array of the all the rights the target user holds. See Special:ListGroupRights for the rights each user group has.
blocked boolean Whether the target user is blocked (partially or site-wide).
blockid integer The ID of the target user's block, if applicable.
ipRange boolean Whether the target user is an IP range.
ipv4Range boolean Whether the target user is an IPv4 range. This is used due to bugs in MediaWiki, where certain things work for IPv6 but not IPv4, such as the blocks API.
config.currentUser
skin string Name of the skin the current user is using. Same as mw.config.get('skin')
groups array An array of the user groups belonging to the current user. Same as mw.config.get('wgUserGroups')
groupsData groupsData Keyed by user group name (e.g. "sysop"), values have keys rights (individual permissions for the user group), and canAddRemoveGroups (whether the user group allows adding or removing user groups of other users).
rights array An array of the all the rights the current user holds. See Special:ListGroupRights for the rights each user group has.
  1. Additionally, any action except 'view' may be disabled by using the $wgActions variable. Additionally, $wgActions is available now for all actions. Additionally, if searches are enabled and the search parameter is supplied (and non-blank) then all actions are ignored and the search is performed.
  2. Deletion is performed upon a POST request, if a valid edit token is passed as the value of wpEditToken; this is what happens when the user confirms deletion. The delete reason is passed as the value of argument wpReason; this string is recorded in the deletion log (the log_comment_id field of the logging table) Deletion is also performed when deleting a single version of an image; this requires the version id to be passed in the parameter oldimage and a valid edit token in wpEditToken; in this case, the request can also be passed via GET
  3. :* if the optional summary argument is passed, its value is used as the edit summary in place of the default one
    • if the optional bot argument is passed, the edit will be marked as a bot one (the edit is marked rc_bot=1 in the recentchanges table)
    • the bot argument can also be used on any page a [rollback] link will appear on, to cascade &bot=1 to all rollback links generated
    • if the optional hidediff argument is passed, the success message is shown instead of a diff of the change (this can be forced via user preferences)
  4. These levels are changed to the values of mwProtect-level-edit and mwProtect-level-move if the request is a POST one and a valid edit token is passed as wpEditToken; parameter mwProtect-reason gives the reason for protection or unprotection which will be recorded in the page log; if mwProtect-cascade is also passed, cascading protection is applied (all transcluded pages are set to the same protection levels)
    • more generally, the actions that can be limited are those listed in the $wgRestrictionTypes array; this array is initialized to array('edit','move') and can be changed in LocalSettings.php ; the protection action then accept a parameter mwProtect-level-$action for each action in that array
  5. For security reasons, in some versions of MediaWiki Raw is only allowed when using the "primary script access point", that is, when using the "ugly" URL form with index.php?title=...
  6. * requires $wgUseAjax to be true; the only callable functions are those in the array $wgAjaxExportList
    • additional parameters: rs is the function name (e.g., rs=wfSajaxSearch); the rsargs[] array is the list of arguments of this function (e.g., rsargs[]=abcd passes the abcd string to the function).
    • the JavaScript function sajax_do_call for calling Ajax functions is defined in ajax.js .