【问题标题】:Add Custom Button in User JavaScript for MediaWiki在 MediaWiki 的用户 JavaScript 中添加自定义按钮
【发布时间】:2016-01-05 21:31:32
【问题描述】:

我想创建一个类似于插入您签名的按钮。如何做到这一点?

在做了一些研究之后,我发现我可以在 User:MYUSERNAME/common.js 页面中插入自定义按钮。

我看到了几个例子。但是 wiki 参考资料和信息通常分散在多个页面上并且已经过时。因此,如果幸运的话,我会在这里尝试并找到尝试过类似事情的人。

谁能帮我解决这个问题:

var customizeToolbar = function() {
    $('#wpTextbox1').wikiEditor('addToToolbar', {
        section: 'advanced',
        group: 'format',
        tools: {
            "comment": {
                label: 'Comment',
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/3/37/Btn_toolbar_commentaire.png',
                action: {
                    type: 'encapsulate',
                    options: {
                        pre: "<!-- ",
                        post: " -->"
                    }
                }
            }
        }
    });
};

当我这样做时,什么都不会发生,因为 customizeTooblar 很可能永远不会被调用。当我删除它时,它说未定义 wikiEditor。

我已经在 LocalSettings.php 中启用了$wgAllowUserJs = true;

我看到了这个问题:Creating custom edit buttons for MediaWiki 这仍然是我们应该做这种事情的方式吗?这可能不是一个重复的问题,因为我已经在这里询问了我的特定问题。

【问题讨论】:

    标签: javascript php mediawiki


    【解决方案1】:

    问题是缺少启动代码。 此代码应直接将笑脸标签添加到您的高级工具栏:

    var customizeToolbar = function() {
        /* Your code goes here */
    
    
    $( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'advanced',
        'group': 'insert',
        'tools': {
            'SimpleComment': {
                label: 'Comment', 
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png',
                action: {
                    type: 'encapsulate',
                    options: {
                        pre: "preText", 
                                            post: "postText"
                    }
                }
            }
        }
    } );
    
    
    
    
    
    
    
    
    };
    
    /* 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', 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.toolbar' ), $.ready
                ).then( customizeToolbar );
            }
        } );
    }
    // Add the customizations to LiquidThreads' edit toolbar, if available
    mw.hook( 'ext.lqt.textareaCreated' ).add( customizeToolbar );
    

    可以添加到wiki/User:YOUR_USRNAME/common.js

    LocalSettings.php 中必须启用此选项$wgAllowUserJs = true;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-29
      • 2020-11-29
      • 2017-11-01
      • 1970-01-01
      相关资源
      最近更新 更多