MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针

如果在编辑的过程中遇到了什么问题,可以去讨论板提问。

为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证

MCBBS Wiki GitHub群组已上线!

您可以在回声洞中发表吐槽!

服务器状态监控。点击进入

本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>

帮助:开发者文档:修订间差异

来自MCBBS Wiki
跳到导航 跳到搜索
标签移动版编辑 移动版网页编辑
→‎mw.html.escape:​ // Edit via Wikiplus
 
(未显示3个用户的3个中间版本)
第1行: 第1行:
{{不完整|一晚上就搬完不可能的|只翻译了一半}}
{{施工中|3小时}}
{{不完整|一晚上就搬完不可能的}}
{{帮助文档难度/困难}}
{{帮助文档难度/困难}}
{{浮动帮助菜单}}
{{浮动帮助菜单}}
第23行: 第22行:
其中大部分以 '''wg''' 为前缀。
其中大部分以 '''wg''' 为前缀。


* For legacy reasons these names are exposed as global JavaScript variables 若<code>$wgLegacyJavaScriptGlobals</code>为真,所以需要一个前缀以防变量名冲突。
* 因为历史原因,这些变量是全局的js变量。若<code>$wgLegacyJavaScriptGlobals</code>为真,所以需要一个前缀以防变量名冲突。
* A subset of these names correspond to $wg_variable in PHP, but others are unrelated.
* A subset of these names correspond to $wg_variable in PHP, but others are unrelated.
* 除了本列表中的名字意外,很多扩展还设置了额外的以wg开头的js配置变量。
* Besides the names in this list, many extensions also set additional JavaScript config variables prefixed with 'wg'.


你可以通过<code>mw.config</code>来访问这些值。
你可以通过<code>mw.config</code>来访问这些值。
第53行: 第52行:
|valign="top"|<code>wgArticlePath</code>
|valign="top"|<code>wgArticlePath</code>
|valign="top"|字符串
|valign="top"|字符串
|valign="top"| 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 <code>title</code>, a valid URL may be constructed using <code>wgArticlePath.replace('$1', title)</code>. See also $wgArticlePath.
|valign="top"|从根目录开始的本地路径, 用于引用文章。含有一个“$1”占位符,可以用页面标题替换来获取一个有效的页面URL。给定有效的页面标题<code>title</code>, 可以用<code>wgArticlePath.replace('$1', title)</code>获取有效URL。另见$wgArticlePath
|valign="top"|MW 1.8+
|valign="top"|MW 1.8+
|-
|-
|valign="top"|<code>wgCaseSensitiveNamespaces</code>
|valign="top"|<code>wgCaseSensitiveNamespaces</code>
|valign="top"|数组
|valign="top"|数组
|valign="top"| The IDs of the namespaces treated as case-sensitive by MediaWiki. Determined by the values of them <code>$wgCapitalLinks</code> and <code>$wgCapitalLinksOverrides</code> configuration variables.<!-- I'm assuming; it would be good to have someone confirm this -->
|valign="top"| MediaWiki中对大小写敏感的命名空间的ID。由<code>$wgCapitalLinks</code><code>$wgCapitalLinksOverrides</code> 这两个配置变量的值决定。<!-- I'm assuming; it would be good to have someone confirm this -->
|valign="top"|MW 1.18+ (90234)
|valign="top"|MW 1.18+ (90234)
|-
|-
第68行: 第67行:
|valign="top"|<code>wgContentNamespaces</code>
|valign="top"|<code>wgContentNamespaces</code>
|valign="top"|整数数组
|valign="top"|整数数组
|valign="top"| The IDs of the namespaces considered "content namespaces" by MediaWiki. Equivalent to the value of the <code>$wgContentNamespaces</code> configuration variable, 没有加载好的话就是<code>0</code>。
|valign="top"| MediaWiki看作是“内容名字空间”的名字空间ID。和配置变量<code>$wgContentNamespaces</code>的值等价, 没有加载好的话就是<code>0</code>。
|valign="top"|MW 1.23+ <small>(Git: 3d87e3a86bcb39d444ef916129dd48bf80b5bb31)</small>
|valign="top"|MW 1.23+ <small>(Git: 3d87e3a86bcb39d444ef916129dd48bf80b5bb31)</small>
|-
|-
第83行: 第82行:
|valign="top"|<code>wgEnableWriteAPI</code>
|valign="top"|<code>wgEnableWriteAPI</code>
|valign="top"|布尔型
|valign="top"|布尔型
|valign="top"|如果mw的写入API启用则为<code>true</code>,反之为<code>false</code>。If <code>wgEnableAPI && !wgEnableWriteAPI</code>, only the read operations of the API are enabled.
|valign="top"|如果mw的写入API启用则为<code>true</code>,反之为<code>false</code>。如果<code>wgEnableAPI && !wgEnableWriteAPI</code>, 只有读取API会被启用。
|valign="top"|MW 1.12+
|valign="top"|MW 1.12+
|-
|-
第103行: 第102行:
|valign="top"|<code>wgScript</code>
|valign="top"|<code>wgScript</code>
|valign="top"|字符串
|valign="top"|字符串
|valign="top"| 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.
|valign="top"| 到达主要脚本接入点的完全路径,从根部开始。包括带着扩展名的脚本名。在WMF Wiki上,一般是"/w/index.php"。另见$wgScript
|valign="top"|MW 1.11+
|valign="top"|MW 1.11+
|-
|-
|valign="top"|<code>wgScriptPath</code>
|valign="top"|<code>wgScriptPath</code>
|valign="top"|字符串
|valign="top"|字符串
|valign="top"|<code>wgScript</code>的路径部分,结尾不是"/"。This is the path to use for direct calls to the php access points such as <code>index.php</code> <code>api.php</code>. See also $wgScriptPath.
|valign="top"|<code>wgScript</code>的路径部分,结尾不是"/"。这是用于直接调用php接入点(如<code>index.php</code>或<code>api.php</code>)的路径。另见$wgScriptPath
|valign="top"|MW 1.8+
|valign="top"|MW 1.8+
|-
|-
|valign="top"|<code>wgServer</code>
|valign="top"|<code>wgServer</code>
|valign="top"|字符串
|valign="top"|字符串
|valign="top"|服务器链接,结尾不是"/"。The combination <code>wgServer + wgScriptPath + "/api.php"</code>, for instance, results in a valid URL to the API access point script.
|valign="top"|服务器链接,结尾不是"/"。<code>wgServer + wgScriptPath + "/api.php"</code>。比如说,可以得到API脚本接入点的合法URL
|valign="top"|MW 1.8+
|valign="top"|MW 1.8+
|-
|-
第354行: 第353行:


== mw.html ==
== mw.html ==
=== mw.html.escape ===
HTML转义。
<pre>mw.html.escape( '< > \' & "' ); // Returns: &amp;lt; &amp;gt; &amp;#039; &amp;amp; &amp;quot;</pre>


== mw.msg ==
== mw.msg ==


== mw.loader ==
== mw.loader ==
=== mw.loader.addSource ===


== mw.user ==
== mw.user ==
第364行: 第367行:
* 需要实例化才能使用。
* 需要实例化才能使用。
* 大部分需要导入额外的JS才能使用。
* 大部分需要导入额外的JS才能使用。
=== plugins ===
* 需要导入对应的JS才能正常使用。
* '''混入的是mw.Api。'''
; .category
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/category.html#mw-Api-plugin-category 文件]
: getCategories( title : mw.Title|string ) : jQuery.Promise
:: 获取页面的分类列表
:: 返回 jQuery.Promise
::: done : Function : boolean|mw.Title[]
:: 若没有分类,返回false
: getCategoriesByPrefix( prefix : string ) : jQuery.Promise
:: 获取以此为前缀的分类
:: 返回 jQuery.Promise
::: done : Function : string[]
:: 返回获取到的分类名
: isCategory( title : string ) : jQuery.Promise
:: 检查某个分类是否存在
:: 返回 jQuery.Promise
::: done : Function : boolean
:: 存在返回true,否则返回false

; .edit
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/edit.html#mw-Api-plugin-edit 文件]
: create( title : mw.Title|string , params : Object , content : string ) : jQuery.Promise
:: params : {summary : string}
::: summary: 描述
:: 返回 jQuery.Promise
::: done : Function : void
: edit( title : mw.Title|string , transform : Function ) : jQuery.Promise
::
: getEditToken( ) : jQuery.Promise
::
: newSection( title, header, message, [additionalParams] ) : jQuery.Promise
::
: postWithEditToken( params, [ajaxOptions] ) : jQuery.Promise
::

; .login
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/login.html#mw-Api-plugin-login 文件]
: login( username, password ) : jQuery.Promise

; .messages
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/messages.html#mw-Api-plugin-messages 文件]
: getMessages( messages, [options] ) : jQuery.Promise
::
: loadMessages( messages, [options] ) : jQuery.Promise
::
: loadMessagesIfMissing( messages, [options] ) : jQuery.Promise
::

; .options
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/options.html#mw-Api-plugin-options 文件]
: saveOption( name, value ) : jQuery.Promise
::
: saveOptions( options ) : jQuery.Promise

; .parse
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/parse.html#mw-Api-plugin-parse 文件]
: parse( content, additionalParams ) : jQuery.Promise

; .rollback
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/rollback.html#mw-Api-plugin-rollback 文件]
: rollback( page, user, [params] ) : jQuery.Promise

; .upload
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/upload.html#mw-Api-plugin-upload 文件]
: chunkedUpload( file, data, [chunkSize], [chunkRetries] ) : jQuery.Promise
::
: chunkedUploadToStash( file, [data], [chunkSize], [chunkRetries] ) : jQuery.Promise
::
: processIframeResult( iframe ) : Object
::
: upload( file, data ) : jQuery.Promise
::
: uploadFromStash( filekey, data ) : jQuery.Promise
::
: uploadToStash( file, [data] ) : jQuery.Promise
::

; .user
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/user.html#mw-Api-plugin-user 文件]
: assertCurrentUser( query ) : Object
::
: getUserInfo( ) : jQuery.Promise
::

; .watch
: [https://doc.wikimedia.org/mediawiki-core/master/js/source/watch.html#mw-Api-plugin-watch 文件]
: unwatch( pages, [addParams] ) : jQuery.Promise
::
: watch( pages, [addParams] ) : jQuery.Promise
::


== mw.Debug ==
== mw.Debug ==
第391行: 第486行:
: 创建或修改一个或多个键值。
: 创建或修改一个或多个键值。
=== mw.ui ===
=== mw.ui ===
* MCBBSWiki似乎没这个。
* MCBBSWiki没这个。
** 因为在MediaWiki1.29后mw.ui完全废弃了,改为使用OOUI
** 在MediaWiki1.29后mw.ui完全废弃了,改为使用[[#OOui]]

=== mw.Title ===
=== mw.Title ===
结构页面标题。
结构页面标题。
第405行: 第499行:
* MCBBSWiki似乎没这个。
* MCBBSWiki似乎没这个。
<pre>
<pre>
new mw.Uri() // 当前URI
new mw.Uri(); // 当前URI
new mw.Uri(URL) // 指定URL的URI
new mw.Uri(URL); // 指定URL的URI
</pre>
</pre>
=== mw.notify ===
=== mw.notify ===
第420行: 第514行:
</pre>
</pre>
== jQuery与插件 ==
== jQuery与插件 ==

== OOui ==
使用这些特性之前,需要导入[https://doc.wikimedia.org/oojs-ui/master/js/source/core.html OOui核心]。
; OO.EmitterList
:
; OO.EventEmitter
:
; OO.Factory
:
; OO.Registry
:
; OO.SortedEmitterList
:
=== OO.ui ===
需要导入[https://doc.wikimedia.org/oojs-ui/master/js/source/windows.html#OO-ui Windows扩展]。


== OOui混入 ==
使用这些特性之前,需要导入[https://doc.wikimedia.org/oojs-ui/master/js/source/core.html OOui核心]和[https://doc.wikimedia.org/oojs-ui/master/js/source/windows.html#OO-ui Windows扩展]。

2020年11月10日 (二) 21:43的最新版本

这篇帮助文档的难度为:困难
这篇帮助文档比较复杂,适合资深编辑者阅读。阅读这篇帮助文档前,您需要熟练掌握Wiki知识,对复杂语法有一定的了解。

考虑到MediaWiki翻译不完全以及部分地区难以丝滑顺畅访问的情况,这里搬运MediaWiki核心及常用模块的文档以及示例代码,原文见此

为了方便查阅,本文与原文的格式与内容可能有较大差异。

mediaWiki

MediaWiki会在Wiki的所有页面创建一个名为“mediaWiki”的对象,亦可以使用简称“mw”来访问。

为了查阅与编写方便,本教程一般使用“mw”。

输出此对象,JavaScript代码:

console.log(mediaWiki);
// console.log(mw)

mw.config

为使JS代码编写更加方便,MediaWiki在对象 mw.config 中提供了一些配置值。

其中大部分以 wg 为前缀。

  • 因为历史原因,这些变量是全局的js变量。若$wgLegacyJavaScriptGlobals为真,所以需要一个前缀以防变量名冲突。
  • A subset of these names correspond to $wg_variable in PHP, but others are unrelated.
  • 除了本列表中的名字意外,很多扩展还设置了额外的以wg开头的js配置变量。

你可以通过mw.config来访问这些值。

全站

名称 类型 描述 版本
debug 布尔型 (没啥好说的) MW 1.17+
skin 字符串 显示当前皮肤的内部名称,经典皮肤(自带的皮肤)名称为:"standard"。 MW 1.7 (monobook 皮肤)
MW 1.8+: 所有情况
stylepath 字符串 皮肤根目录的完整链接,包括样式表和配套的脚本。这个链接不包括皮肤的子目录,也不以“/”结尾。 MW 1.7 (monobook 皮肤)
MW 1.8+: 所有情况
wgArticlePath 字符串 从根目录开始的本地路径, 用于引用文章。含有一个“$1”占位符,可以用页面标题替换来获取一个有效的页面URL。给定有效的页面标题title, 可以用wgArticlePath.replace('$1', title)获取有效URL。另见$wgArticlePath。 MW 1.8+
wgCaseSensitiveNamespaces 数组 MediaWiki中对大小写敏感的命名空间的ID。由$wgCapitalLinks$wgCapitalLinksOverrides 这两个配置变量的值决定。 MW 1.18+ (90234)
wgContentLanguage 字符串 整个Wiki的默认语言代码。 MW 1.8+
wgContentNamespaces 整数数组 MediaWiki看作是“内容名字空间”的名字空间ID。和配置变量$wgContentNamespaces的值等价, 没有加载好的话就是0 MW 1.23+ (Git: 3d87e3a86bcb39d444ef916129dd48bf80b5bb31)
wgDBname 字符串 Wiki的数据库名。 MW 1.13+
wgEnableAPI 布尔型 如果mw的API启用则为true,反之为false MW 1.12+
wgEnableWriteAPI 布尔型 如果mw的写入API启用则为true,反之为false。如果wgEnableAPI && !wgEnableWriteAPI, 只有读取API会被启用。 MW 1.12+
wgExtensionAssetsPath 字符串 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. MW 1.18+ (82247)
wgFormattedNamespaces 对象 一个名字空间ID到翻译过的名字空间的查找表。每一个名字空间都有一个字符串表示的数字作为键映射到名字空间的名字。不包含别名或原名。 MW 1.16+
wgNamespaceIds 对象 一个名字空间到名字空间ID的查找表。每一个名字空间(包括别名)都有一个名字空间的名字作为键映射到名字空间的ID。不包含原名。所有键的字母均小写,用下划线代替空格。 MW 1.16+
wgScript 字符串 到达主要脚本接入点的完全路径,从根部开始。包括带着扩展名的脚本名。在WMF Wiki上,一般是"/w/index.php"。另见$wgScript。 MW 1.11+
wgScriptPath 字符串 wgScript的路径部分,结尾不是"/"。这是用于直接调用php接入点(如index.phpapi.php)的路径。另见$wgScriptPath。 MW 1.8+
wgServer 字符串 服务器链接,结尾不是"/"。wgServer + wgScriptPath + "/api.php"。比如说,可以得到API脚本接入点的合法URL。 MW 1.8+
wgSiteName 字符串 网站名,声明于$wgSitename。 MW 1.16+
wgVariantArticlePath 字符串 或 false 如果Wiki自定义了语言变量(比如中文或塞尔维亚的Wikipedias),这个值将设为语言变量的根路径(除wgContentLanguage以外)。这个路径包含了占位符"$1"需要用页面名替换,"$2"需要用语言代码替换(比如"zh-cn")。如果Wiki没有语言变量,这个值将为false。详见$wgVariantArticlePath。 MW 1.13+
wgVersion 字符串 MediaWiki软件版本。 MW 1.12+


所有页面

(根据用户/页面不同,这些值会变动。)

名称 类型 描述 版本
wgAction 字符串 当前操作,如正在编辑页面时为"edit",正在浏览页面时为"view",详见[1] MW 1.10+
wgArticleId 整数 页面的内部ID。不存在的页面和特殊页面的此项是0。 MW 1.8+
wgCanonicalNamespace 字符串 此页面的真实名字空间(未翻译,不是别名)。 MW 1.8+
wgCanonicalSpecialPageName 字符串 或 false 或 未定义 在特殊页面,显示真实页面名(未翻译,不是别名);否则为未定义(MW 1.15及以下)或false(MW 1.16及以上)。 MW 1.9+
wgCategories 字符串数组 当前页面的分类列表。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+
wgCurRevisionId 整数 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+
wgIsArticle 布尔型 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).
  • 这个变量名不太好 – 我们要做的事可能和这个页面是不是"article"无关。
MW 1.8+
wgIsProbablyEditable 布尔型 如果你可以编辑这个页面的话(基于Title::quickUserCan)则为True。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: 0bbc358951e56fbb3e2e121a02cf213e280ffdc1)
wgNamespaceNumber 整数 当前页面的名字空间ID。 MW 1.8+
wgPageContentLanguage 字符串 当前页面的语言代码(获取:$context->getTitle()->getPageLanguage())。 MW 1.19+ (104483)
wgPageContentModel 字符串 标准Wiki页面:'wikitext',JavaScript页面:'javascript',CSS页面:'css',Scribunto(如Lua模块)页面:'Scribunto' MW 1.22+ (gerrit:62178)
wgPageName 字符串 完整的页面名,包括翻译过的名字空间,如果名字空间有名字(主名字空间(0)没有),空格将被替换为下划线。使用wgTitle获取没有名字空间的页面名。 MW 1.8+
wgRedirectedFrom 字符串 显示重定向自的页面。如果页面不是重定向来的,就没有这个值(不在mw.config中)。格式与wgPageName相同。 MW 1.19+ (104668)
wgRelevantPageName 字符串 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+ (113737)
wgRelevantUserName 字符串 或 无 The relevant name of the user to which content actions and some extra navigation links (e.g. link to user rights 或 user contributions) apply. MW 1.23+ (git: 88773)
wgRelevantPageIsProbablyEditable 布尔型 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)
wgRestrictionEdit 字符串数组 或 无 如果页面可以编辑(同时不是特殊页面)同时只有部分用户组用户可以编辑,数组包括了编辑这个页面所需的最低用户组。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).

这个数组只包含明确的保护。名字空间级的保护(比如MediaWiki名字空间,见 $wgNamespaceProtection), 级联保护,或TitleBlacklist扩展的"moveonly"属性带来的"protections",不会显示在这个数组里;这种页面里,数组始终为[],除非给这个页面的额外保护是专门添加的。

如果页面不存在,那么这个变量也不存在。

MW 1.14+
wgRestrictionMove 字符串数组 如果页面可以移动(同时不是特殊页面)同时只有部分用户组用户可以移动,数组包括了移动这个页面所需的最低用户组。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).

这个数组只包含明确的保护。名字空间级的保护(比如MediaWiki名字空间,见 $wgNamespaceProtection), 级联保护,或TitleBlacklist扩展的"moveonly"属性带来的"protections",不会显示在这个数组里;这种页面里,数组始终为[],除非给这个页面的额外保护是专门添加的。

MW 1.14+
wgRevisionId 整数 当前浏览页面的版本的版本ID, 或版本对比页面右侧页面的版本ID(当diffonly=yes时为0, 这是一个bug: T231744)。版本对比页面有,特殊页面和历史页面为 0,其他地方不可用。 MW 1.22+ (git:7fa7b71eb3a5dd24e75865162e4c06a4a6012524)
wgSearchType 字符串 或 无 The name of the search backend used to execute search requests. MW 1.23+ (git: 118655)
wgTitle 字符串 不带名字空间的页面标题。可能包含空格,同时不包含下划线。想要获取包含名字空间的页面名,请使用wgPageName MW 1.8+

这些值来自访问页面的用户:

名称 类型 描述 版本
wgUserEditCount 整数 当前用户的编辑数(未登录则为null)。 MW 1.21+
wgUserGroups 字符串数组 列出当前用户所属用户组的列表(未登录则为null)。用户组以内部名字标识,比如"sysop"和"autoconfirmed"。默认用户组名字是"*"。 MW 1.10+
wgUserId 整数 当前用户的数字ID(未登录则为null)。 MW 1.21+
wgUserLanguage 字符串 用户的语言代码, 在特殊:参数设置中设置(可以被URL中的uselang=参数覆盖)。 MW 1.8+
wgUserName 字符串 当前用户的用户名(未登录则为null)(不是用户IP地址,与服务端PHP的 $wgUser->getName() 不同)。 MW 1.8+
wgUserRegistration 整数 当前用户的注册时间,显示为 1970-01-01 00:00:00 UTC 以来的毫秒数。(未登录则为null)。 MW 1.21+

部分页面

部分附加的变量只在特定名字空间、Wiki设置或用户设置时出现。

名称 类型 描述 版本
主页
wgIsMainPage 布尔型 如果当前页面是主页则为true。否则不存在这项(null)。 MW 1.18+
如果页面语言是个变量
wgUserVariant 字符串 如果Wiki有语言变量,则为用户的配置。如果没有语言变量,则没有这一项,代码说明:
mw.config.exists( 'wgUserVariant' ); // false
mw.config.get( 'wgUserVariant' ); // null.
MW 1.16+
保存编辑之后
wgPostEdit 字符串 如果用户刚刚保存了这个页面,则为"saved";
如果用户刚刚创建了这个页面,则为"created";
如果用户刚刚从历史记录中恢复了(编辑一个旧版本后保存)这个页面,则为"restored"。
其他情况下为null
请注意:
  1. 没有改动的编辑则为null,不是"saved"。
  2. 撤销后,显示为"saved"。
  3. 回退后,显示为null
MW 1.21+ (gerrit:50480)
页面版本比对时
wgDiffOldId 整数 "旧"版本的版本ID。仅在页面版本比对时有。 MW 1.30+ (git: a469795efc5bc1c585c9f84ee289ee099833661d)
wgDiffNewId 整数 "新"版本的版本ID。仅在页面版本比对时有。 MW 1.30+ (git: a469795efc5bc1c585c9f84ee289ee099833661d)


mw.html

mw.html.escape

HTML转义。

mw.html.escape( '< > \' & "' ); // Returns: &lt; &gt; &#039; &amp; &quot;

mw.msg

mw.loader

mw.loader.addSource

mw.user

mw.Api

  • 需要实例化才能使用。
  • 大部分需要导入额外的JS才能使用。

plugins

  • 需要导入对应的JS才能正常使用。
  • 混入的是mw.Api。
.category
文件
getCategories( title : mw.Title|string ) : jQuery.Promise
获取页面的分类列表
返回 jQuery.Promise
done : Function : boolean|mw.Title[]
若没有分类,返回false
getCategoriesByPrefix( prefix : string ) : jQuery.Promise
获取以此为前缀的分类
返回 jQuery.Promise
done : Function : string[]
返回获取到的分类名
isCategory( title : string ) : jQuery.Promise
检查某个分类是否存在
返回 jQuery.Promise
done : Function : boolean
存在返回true,否则返回false
.edit
文件
create( title : mw.Title|string , params : Object , content : string ) : jQuery.Promise
params : {summary : string}
summary: 描述
返回 jQuery.Promise
done : Function : void
edit( title : mw.Title|string , transform : Function ) : jQuery.Promise
getEditToken( ) : jQuery.Promise
newSection( title, header, message, [additionalParams] ) : jQuery.Promise
postWithEditToken( params, [ajaxOptions] ) : jQuery.Promise
.login
文件
login( username, password ) : jQuery.Promise
.messages
文件
getMessages( messages, [options] ) : jQuery.Promise
loadMessages( messages, [options] ) : jQuery.Promise
loadMessagesIfMissing( messages, [options] ) : jQuery.Promise
.options
文件
saveOption( name, value ) : jQuery.Promise
saveOptions( options ) : jQuery.Promise
.parse
文件
parse( content, additionalParams ) : jQuery.Promise
.rollback
文件
rollback( page, user, [params] ) : jQuery.Promise
.upload
文件
chunkedUpload( file, data, [chunkSize], [chunkRetries] ) : jQuery.Promise
chunkedUploadToStash( file, [data], [chunkSize], [chunkRetries] ) : jQuery.Promise
processIframeResult( iframe ) : Object
upload( file, data ) : jQuery.Promise
uploadFromStash( filekey, data ) : jQuery.Promise
uploadToStash( file, [data] ) : jQuery.Promise
.user
文件
assertCurrentUser( query ) : Object
getUserInfo( ) : jQuery.Promise
.watch
文件
unwatch( pages, [addParams] ) : jQuery.Promise
watch( pages, [addParams] ) : jQuery.Promise

mw.Debug

mw.Feedback

mw.util

mw的其他子项

一些不常用的或较为简单的东西。

mw.hook

.add
.fire
.remove

自己看源代码(原文如此)。

mw.log

console.log()的替代品,debug模式下启用。

mw.map

封装过的查找表,需要实例化才能用。

.values
一个包含所有变量的对象。如果初始化的时候'global'设为true,返回的其实是window对象。
.exists(key)
如果存在则返回true,反之返回false。
.get(key, fallback)
返回按键获取的值,没找到的话会返回第二个参数(如果第二个参数也没有,则返回null)。
.set(key, value)
创建或修改一个或多个键值。

mw.ui

  • MCBBSWiki没这个。
    • 在MediaWiki1.29后mw.ui完全废弃了,改为使用#OOui

mw.Title

结构页面标题。

var t = new mw.Title( '文件:盐.png' ); // 实例化
t.getMain(); // "盐.png"
t.getNamespaceId(); // 6
t.getNamespacePrefix(); // "文件:"

mw.Uri

  • MCBBSWiki似乎没这个。
new mw.Uri(); // 当前URI
new mw.Uri(URL); // 指定URL的URI

mw.notify

mw.notify( '这是一个通知' ); // 发送文字通知
mw.notify( mw.message( 'some-message' ) ); // 用i18n消息发送通知
mw.notify( $( '<span>这是一个<u>HTML</u>通知</span>' ) ); // 用jQuery实例发送HTML通知(DOM节点也行)

mw.notify( '通知', { title: '标题' } ); // 给通知加一个标题
mw.notify( '通知', { autoHide: false } ); // 通知不会自行隐藏
mw.notify( '通知', { tag: 'asd' } ); // 给通知加一个标签
mw.notify( '通知:另一个', { tag: 'asd' } ); // 这个通知将会覆盖前一个相同标签的通知

jQuery与插件

OOui

使用这些特性之前,需要导入OOui核心

OO.EmitterList
OO.EventEmitter
OO.Factory
OO.Registry
OO.SortedEmitterList

OO.ui

需要导入Windows扩展


OOui混入

使用这些特性之前,需要导入OOui核心Windows扩展