Come Try Out The New Community Guides

View the Guides Check Out The Gear Sets

MediaWiki:Gadget-nullEdit.js

From Walkscape Walkthrough

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Copied from Terraria wiki */

mw.loader.using(['site', 'mediawiki.util']).done(function() {
    if (mw.config.get("wgArticleId") !== 0) {
        
        var l10n = (function(){
            var $text = {
                'buttonlabel': {
                    'en': 'Null edit',
                    'de': 'Nulledit',
                    'fr': 'Modification nulle',
                    'pt-br': 'Edição nula',
                    'ru': 'Нулевая правка',
                },
                'hovertext': {
                    'en': 'Null edit this page',
                    'de': 'Einen Nulledit dieser Seite durchführen',
                    'fr': 'Effectuer une modification nulle sur cette page',
                    'pt-br': 'Editar nulo esta página',
                    'ru': 'Совершить нулевую правку на этой странице',
                },
                'failtext': {
                    'en': 'Could not perform null edit. Reason: ',
                    'de': 'Konnte keinen Nulledit durchführen. Grund: ',
                    'fr': 'N\'a pas pû effectuer une modification nulle. Raison : ',
                    'pt-br': 'Não foi possível realizar a edição nula. Motivo: ',
                    'ru': 'Невозможно совершить нулевую правку. Причина: ',
                }
            }
            var $lang = mw.config.get( 'wgUserLanguage' ) || 'en';
            return function(key){
                return $text[key] && ($text[key][$lang] || $text[key]['en']) || '';
            }
        })();
        
        $(mw.util.addPortletLink('p-cactions', 'javascript:;', l10n('buttonlabel'), 'ca-null-edit', l10n('hovertext'), '2')).click(function() {
            // Uncomment the following block to enable a confirmation dialog before performing the null edit
            /*
            if (!confirm(l10n('confirmtext'))) return;
            */
            new mw.Api().postWithToken('csrf', {action: "edit", title: mw.config.get("wgPageName"), appendtext: ""}).done(function(data) {
                location.reload(); // Reload the page to reflect any changes
                window.close();   // Close the tab
            }).fail(function(code, data) {
                alert(l10n('failtext') + code);
            });
        });
    }
});