Community Central
Community Central

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.
/**
 * disableCodeEditor.js
 * 
 * Disables code editor on css/js pages introduced with the new syntax highlighting for source editor
 * The editor is overall buggy, slow and annoying
 * This script is the ajax equivalent of the editor that was used before the code editor
 * Looks Monobook-ish
 * 
 * @author: [[w:user:Fubuki風吹]]
 */

if (/\.(css|js)/g.test(mw.config.get('wgPageName')) || mw.config.get('wgCanonicalNamespace') == 'Module') {
    var html = $('#mw-content-text').html();
    $('#ca-edit').on('click', function(e) {
        e.preventDefault();
        $('#mw-content-text').html('<div style="text-align: center;"><img src="' + mw.config.get('stylepath') + '/common/images/ajax.gif"/> Loading editor...</div>');
        $.get('/wiki/' + mw.config.get('wgPageName') + '?action=raw', function(data) {
            $('#mw-content-text').html('<textarea id="wpTextbox" rows="40" style="font-family: monospace; overflow-y: auto; width: 99.2%; font-size: 13px; resize: none;"></textarea>Edit summary: <input type="text" id="wpEditSummary" style="width: 50%;"><div style="float: right; display: inline;"><input type="checkbox" id="wpMinorEdit" checked> Minor edit</div><br><button id="wpSubmit" class="wikia-button">Publish</button> <button id="wpCancel" class="wikia-button secondary">Cancel</button> <span id="status" style="display: none"></span>');
            $('#wpTextbox').val(data || '');
            $('#wpSubmit').on('click', function() {
                $('#status').css('display', 'inline').html('<img src="' + mw.config.get('stylepath') + '/common/images/ajax.gif"> Publishing edit...');
                var data = {
                    action: 'edit',
                    title: mw.config.get('wgPageName'),
                    text: $('#wpTextbox').val(),
                    token: mw.user.tokens.values.editToken,
                    format: 'json'
                };
                if ($('#wpEditSummary').val().length) data.summary = $('#wpEditSummary').val();
                if ($('#wpMinorEdit:checked').length) data.minor = '';
                $.post(mw.util.wikiScript('api'), data, function(data) {
                    if (!data.error) {
                        $('#status').css('color', 'green').html('Edit successfully made!');
                        window.location.reload();
                    } else {
                        $('#status').css('color', 'red').html('Failed to edit page. Try again.');
                    }
                });
            });
            $('#wpCancel').on('click', function() {
                $('#mw-content-text').html(html);
            });
        });
    });
}