因为在表单中使用可视化编辑器的感受不好(尤其是保存问题,详细参见《MediaWiki页面表单保存的小问题》一文),所以就改用WikiEditor(如果不指定编辑器,文本框默认是没有任何工具栏的)。
其实就目前来说,WikiEditor也完全够用了,唯一让我觉得不满意的就是没有居中对齐功能,每次只能手动添加<center></center>
那就尝试着自定义一下工具栏吧,根据官网的教程,代码如下:

// Check if we're editing a page.
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
    // Add a hook handler.
    mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
        // Configure a new toolbar entry on the given $textarea jQuery object.
        $textarea.wikiEditor( 'addToToolbar', {
            section: 'advanced',
            group: 'format',
            tools: {
                AlignCenter: {
                    label: '居中',
                    type: 'button',
                    oouiIcon: 'alignCenter',
                    action: {
                        type: 'encapsulate',
                        options: {
                            pre: "<center>",
                            post: "</center>"
                        }
                    }
                }
            }
        } );
    } );
}

随便打开一个页面,编辑器工具栏中多了一个居中的按钮,选定要居中的文字,点击一下就可以了。
oouiIcon图标请参考https://doc.wikimedia.org/oojs-ui/master/demos/?page=icons&theme=wikimediaui&direction=ltr&platform=desktop,如果没有的话就自己上传一个漂亮的图标好了。
wikiedtor-toolbar.png
但是这样添加的工具栏只能在主命名空间中使用,打开表单中的文本框还是标准的。

参考资料

https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization
https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization/Library

最后修改:2022 年 06 月 16 日
如果觉得我的文章对你有用,请随意赞赏