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

添加1,280字节 、​ 2021年2月18日 (四) 02:11
→‎jquery.client:​ //使用页面/文本对比查看器快速编辑
===LLWiki添加的全局變量和方法===
;<code lang="js">window.wgULS(hans, [hant])</code>和<code lang="js">window.wgUCS(hans, [hant])</code><ref name="site-lib">需要加載[[mediawiki:gadget-site-lib.js|site-lib.js]]</ref>
:用于处理繁简文字信息,wgULS()用于界面语言,wgUCS()用于内容语言。为方便维护,在大量使用繁简转换的页面,请将所有繁简文字以mw.messages.set()方法的形式至于代码开头,然后在使用时以mw.msg()方法调用即可。
 
;mw.gadgets
;mw.widget
:这个对象储存了小部件的执行情况,防止Ajax预览造成小部件重复执行。
 
;mw.windowManager
:这个对象储存了一个公用的OO.ui.WindowManager对象。
 
;<code>mw.pagenamee()</code><ref name="site-lib" />
:这个方法用于获取转义后的当前页面名称。需要mediawiki.util。
 
;<code>mw.addMobileLinks(linkslink)</code><ref name="site-lib" />
:这个方法生成手机版菜单需要的列表构成的数组,可以随后使用jQuery加入DOM中。linkslink一个对象或对象数组,每一项包含链接地址hrefhref(可选)、FontAwesome图标icon和icon(默认为[https://fontawesome.com/icons/arrow-circle-right 圆圈包裹的一个向右箭头])、文字信息text(需要手动设置繁简转换,优先级低于msg)或mw.messages的键值msg和<code>&lt;li&gt;</code>元素属性attr(可选)
 
;<code>mw.apiFailure(reason, topic)</code><ref name="site-lib" />
 
;<code>mw.timedParse(api, params, topic)</code><ref name="site-lib" />
:Ajax使用POST而非GET,因此适合预览大段Wikitext。params的默认设置为<code lang="js">{action: 'parse', prop: 'text', title: mw.config.get( 'wgPageName' ), disablelimitreport: 1, disableeditsection: 1, pst: 1, formatversion: 2}</code>,可以覆盖。需要填入page、pageid或oldid参数时请勿使用此方法,应当选用包含<code lang="js">{action: 'parse'}</code>参数的mw.timedQuery()。topic同样需要手动设置繁简转换。需要mediawiki.api。
 
;<code>mw.standardQuery(api)</code><ref name="site-lib" />
:使用mw.timedQuery()方法提交一个API请求以获取当前版本的全文Wikitext并保存至mw.request。需要mediawiki.api。
 
;<code>mw.sectionQuery(api, section, [force])</code><ref name="site-lib" />
:使用mw.timedQuery()方法提交一个API请求以获取段落Wikitext并保存至mw.sections。section为段落编号,默认为序言;为降低错误编辑历史版本的风险,想要获取历史版本的段落Wikitext时,必须手动添加为真的force参数。需要mediawiki.api。
 
;<code>mw.safeEdit(api, curRevid, params, [flag])</code><ref name="site-lib" />
:检查有无编辑冲突后提交编辑。api为mw.Api对象;curRevid为当前最新版本的编号,默认保险起见未赋初始值,但一般填<code lang="js">mw.config.get( 'wgCurRevisionId' )</code>即可;parmas为API参数,默认为<code lang="js">{action: 'edit'}</code>,可以覆盖,但原则上请勿使用这一方法执行其他操作;flag参数对应是否开启自动备份小工具,这会改变检测到编辑冲突时的应对错误通知。检测到编辑冲突抛出错误<code lang="js">'editConflict'</code>,API请求失败抛出错误<code lang="js">'editFailure'</code>或<code lang="js">'revisionQueryFailure'</code>。需要mediawiki.api。
 
;<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。
 
;<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-windows。
 
;<code>mw.prompt(text, [flags], [config])</code><ref name="site-lib" />
:借助OO.ui.prompt()方法生成一个prompt对话框。text为文字提示;flags为确认键的样式数组,可选元素包括<code lang="js">'primary'</code>、<code lang="js">'progressive'</code>和<code lang="js">'destructive'</code>,其中<code lang="js">'primary'</code>不能单独生效;config为可选的文本框设置。返回值为一个状态为resolve的Promise对象,值为<code lang="js">null</code>表示取消。需要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-windows。
 
;<code>mw.tipsy($container, [target], [params], [$content])</code><ref name="site-lib" />
:借助OO.ui.PopupWidget对象生成一个手机版也有效的tooltip。$container为外部容器的jQuery对象,target(不能是body);target为目标元素的选择器,params;params为建立OO.ui.PopupWidget对象时的参数,默认为<code lang="js">{padded: true, width: null, classes: ['mw-tipsy']}</code>,可以覆盖;$content为自定义的tooltip内容,默认为title或data-title属性。需要oojs-ui-core。
 
;<code>mw.convertTimezone(then, timezone)</code><ref name="site-lib" />
:改变moment对象的时区。then为待处理的moment对象,默认为现在;timezone为时区的IANA名称或数值表示的UTC偏移量,需要提前检查合法性,默认为本地时区。注意这个方法的返回值不是一个真实存在的时间点,只能用于输出而不能用于进一步运算。需要moment。
 
;mw.resizeLyrics()<ref>需要加載[[user:bhsd/widget/lyrics.js|Widget:Lyrics]]</ref>
16,874

个编辑