“LLWiki:管理员技术手册”的版本间差异

添加110字节 、​ 2021年1月27日 (三) 11:12
 
====mediawiki.util====
mediawiki.util提供了很多非常方便的方法,可以用于满足形形色色的需要。这个模块会在加载很多其他模块时加载,如mediawiki.api、mediawiki.Title和mediawiki.Uri等
*mw.util.addCSS(),相比mw.loader.addStyleTag()方法,因为返回值是一个StyleSheet对象而更便于后续动态操作。
*mw.util.addPortletLink(),实际上并不如直接使用jQuery自由度更大,但这个方法可能会出现在一些从其他维基导入的小工具里,不推荐使用。
 
====jquery.client====
用於查詢用戶設備和瀏覽器的相關信息,相比直接使用navigator,這個模塊使用起來更加簡便和友好。这个模块会在加载mediawiki.util时加载
*<code lang="js">const profile = $.client.profile();</code>,以對象的形式輸出設備和瀏覽器信息。
*profile.platform,可識別的設備類型:ipad、iphone、linux、mac、win。
 
;<code>mw.safeRedirect(api, title, target, [summary])</code><ref name="site-lib" />
:检查繁简转换后的页面是否已经存在后创建新重定向。api为mw.Api对象;title为重定向页标题;target为重定向目标页标题;summary为可选摘要。页面已存在时抛出<code lang="js">'pageExists'</code>,API请求失败时抛出<code lang="js">'createFailure'</code>或<code lang="js">'queryFailure'</code>。需要mediawiki.api和mediawiki.util
 
;<code>mw.confirm(text, flags)</code><ref name="site-lib" />
:借助OO.ui.confirm()方法生成一个确认对话框。text为确认提示;flags为确认键的样式数组,可选元素包括<code lang="js">'primary'</code>、<code lang="js">'progressive'</code>和<code lang="js">'destructive'</code>,其中<code lang="js">'primary'</code>不能单独生效。返回值为一个状态为resolve的Promise对象,值为真表示确认。需要oojs-ui-core和oojs-ui-windows。
 
;<code>mw.dialog(dialog, actions, $message, [$title])</code><ref name="site-lib" />
:借助OO.ui.MessageDialog对象生成一个更复杂的对话框。dialog为预先准备的OO.ui.MessageDialog对象;actions为OO.ui.ActionWidget对象构成的数组;$message为提示信息,相比mw.confirm()方法的进步之处在于可以使用jQuery或htmlString;$title为对话框标题。返回值为点击按钮时的Promise对象。需要oojs-ui-core和oojs-ui-windows。
 
;<code>mw.tipsy($container, target, [params])</code><ref name="site-lib" />
===JSHint===
CodeEditor使用JSHint标注可能存在的语法问题。LLWiki會在大部分JS页面添加JSHint设置<code lang="js">/* global mw */</code>和<code lang="js">/* jshint jquery: true, bitwise: true, curly: true, latedef: 'nofunc', nonew: true, singleGroups: true, unused: true */</code><ref>[https://jshint.com/docs/options/ 新版JSHint的设置列表],注意可能存在的版本差异。</ref>。但在小部件页面,为了提示小部件JS加载在模块mediawiki和jquery之前,<code lang="js
>/* global mw */</code>和<code lang="js">/* jshint jquery: true */</code>被替换为<code lang="js">/* jshint varstmt: true */</code>。注意JSHint并不会对大多数JS模块不允许使用的ES6语法作出警告(详见[[#ResourceLoader和JS模块]]),因此请勿过度依赖这一功能来除错。另外CodeEditor安装的JSHint版本较老,无法识别ES7以上的语法,因此在代码中使用ES7语法可能会造成除错时的困难。
 
===注意事项===
16,874

个编辑