查看“︁使用方法/页面工具/工具扩展”︁的源代码
来自康健生活
←
使用方法/页面工具/工具扩展
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 工具扩展 == === Basic setup === === Extension JavaScript === 在配置文件里面添加'''$wgAllowUserJs''',之后在特殊页面(e.g.:[http://kangkk.cn/index.php/用户:Kangkk/common.js Kangkk/common.js])添加JS代码。 <syntaxhighlight lang="php"> $wgAllowUserJs = true; </syntaxhighlight> 缺点: * 频繁更改'''common.js''',造成过多页面历史 * JS代码在所有页面都会加载执行 ==== 定义资源加载程序包 ==== 定义资源加载程序包分为三步, <syntaxhighlight lang="php"> $wgResourceModules['ext.MyExtension']['scripts'][] = 'extensions/MyExtension/js/MyExtension.js'; $wgHooks['EditPage::showEditForm:initial'][] = 'addModule'; function addModule(EditPage $editPage, OutputPage $output ) { $output->addModules( 'ext.MyExtension' ); } </syntaxhighlight> 这里需要注意的是在加载JS文件时,会发生JS代码加载延迟,所以尽量将代码放在下列代码中。 <syntaxhighlight lang="javascript"> var customizeToolbar = function () { /* Your code goes here */ }; /* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */ if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) { mw.loader.using( 'user.options' ).then( function () { // This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]]) if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) { $.when( mw.loader.using( 'ext.wikiEditor' ), $.ready ).then( customizeToolbar ); } } ); } </syntaxhighlight> == 参考 == * [https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization Toolbar customization] * [https://www.mediawiki.org/wiki/Manual:Custom_edit_buttons Custom edit buttons] * [https://commons.wikimedia.org/wiki/MediaWiki_edit_toolbar 工具图标] * [https://en.wikisource.org/wiki/Wikisource:Tools_and_scripts/More_editing_buttons 工具扩展方法(已过时)]
返回
使用方法/页面工具/工具扩展
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。