Search code examples
tinymcemediawiki

In Mediawiki's tinymce extension, how to enable/disable buttons?


In https://www.mediawiki.org/wiki/Extension:TinyMCE, there a section with Toolbar buttons including a Citation/reference button which looks like this:

enter image description here

Furthermore, it says: "Depending on configuration, some or all of these buttons may be shown".

It is not clear however how to enable/disable specific buttons in LocalSettings.php.

In the https://www.mediawiki.org/wiki/Extension:TinyMCE/Configuration page, there are instructions on how to add buttons to toolbars, and based on that I have added this to my LocalSettings.php:

wfLoadExtension( "TinyMCE" );
$wgTinyMCEEnabled = true;
$wgTinyMCESettings = [
  ".tox-tinymce" => [
    "toolbar+" => " | citation",
  ],
];

.tox-tinymce being the selector for the text box where TinyMCE applies.

The citation button does not appear currently, and before I debug, I'd like to know (1) if I am on the right track, and (2) how can i know the machine name of a button (I assume it's citation, but maybe it's "footnote" or "cite", it is not clear where to find the mapping of machine names to buttons).


Solution

  • I have gone through the mediawiki-extensions-TinyMCE-master

    Inside custom plugin directory mediawiki/plugins I saw 12 custom plugins.

    I have opened one by one plugin code I observed only 3 plugins wikitext, wikitoggle , wikiupload are loaded in tinymce plugin manager. Ex:-

    tinymce.PluginManager.add('wikitoggle', wikitoggle);
    

    I could enable these buttons directly in load-extensions.php.

    wfLoadExtension( "TinyMCE" );
    $wgTinyMCEEnabled = true;
    
    
    $wgTinyMCESettings = [
      "#wpTextbox1" => [
        "toolbar" => 'wikitext wikitoggle wikiupload',
      ],
    ];
    

    I saw wikireference code at the end it has plugin function defination.

    function Plugin () {
        // only load plugin if the 'cite' extension is enabled
        // in the wiki, eg, if 'ref' tag is in extension tag list
        if ( extensionTagsList.split('|').indexOf('ref') > -1 ) {
            pluginManager.add('wikireference', function (editor) {
                registerCommands( editor );
                registerButtons( editor );
                setup( editor );
            });
        }
    }
    
    Plugin();
    
    
    
    // only load plugin if the 'cite' extension is enabled
    // in the wiki, eg, if 'ref' tag is in extension tag list
    

    from the plugin method comments I could figure it out how to load reference and comment buttons.

    1. first we need to download and install Cite extension plugin

      echo 'Downloading and installing Cite'

      echo 'See https://www.mediawiki.org/wiki/Extension:Cite#Installation'

      curl -O -L https://github.com/wikimedia/mediawiki-extensions-Cite/archive/refs/heads/master.zip

      unzip master.zip

      rm master.zip

      mv mediawiki-extensions-Cite-master extensions/Cite

    2. Enable reference and comment button in load-extensions.php

      [ "toolbar" => 'reference comment', ], ];