Jump to content

User:Ilmari Karonen/edittoolstest.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
TEST OF JAVASCRIPT EDITTOOLS

To try out this feature, add the following lines to your monobook.js:

  importScript("User:Ilmari Karonen/edittoolstest.js");
  window.testJsEdittools = true;

To deploy this feature sitewide, the code below should be copied to [[MediaWiki:Common.js]],
while the code at [[User:Ilmari Karonen/edittools.js]] should be moved to [[MediaWiki:Edittools.js]].
After 30 days have passed (to allow time for browser caches to purge), the #editpage-specialchars
div and everything in it in [[MediaWiki:Edittools]] should be replaced with:

  <div id="editpage-specialchars" class="edittools-version-0001"></div>

During the 30-day interval between initial and full deployment (while the class name still has "test"
in it), the code may be tested simply by setting "window.testJsEdittools = true".  It should be safe
to run this script more than once: it will only work the first time, after that it will have removed
the #editpage-specialchars div and so will no longer do anything.
*/

if (wgAction == 'edit' || wgAction == 'submit') addOnloadHook(function () {
    var placeholder = document.getElementById("editpage-specialchars");
    if (!placeholder || window.noDefaultEdittools) return;
    var match = /(?:^| )edittools-version-(\d+)(?: |$)/.exec(placeholder.className);

    if (!match && window.testJsEdittools)
        match = /(?:^| )edittools-version-(test\d+)(?: |$)/.exec(placeholder.className);

    if (!match) return;
    var url = wgScript + '?title=User:Ilmari_Karonen/edittools.js&action=raw&ctype=text/javascript&nocache=' + match[1];
    // var url = wgScript + '?title=MediaWiki:Edittools.js&action=raw&ctype=text/javascript&nocache=' + match[1];

    if (window.importScriptURI) {
        mw.loader.load(url);
    } else {
        // while waiting for a scap...
        var scriptElem = document.createElement( 'script' );
        scriptElem.setAttribute( 'src' , url );
        scriptElem.setAttribute( 'type' , 'text/javascript' );
        document.getElementsByTagName( 'head' )[0].appendChild( scriptElem );
    }
});