Community Central
Community Central
m (edit made using this script)
Tag: apiedit
m (update)
Tag: sourceedit
Line 14: Line 14:
 
e.preventDefault();
 
e.preventDefault();
 
$('#mw-content-text').html('<div style="text-align: center;"><img src="' + mw.config.get('stylepath') + '/common/images/ajax.gif"/> Loading editor...</div>');
 
$('#mw-content-text').html('<div style="text-align: center;"><img src="' + mw.config.get('stylepath') + '/common/images/ajax.gif"/> Loading editor...</div>');
$.get(mw.util.wikiScript('api'), {
+
$.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> <span id="status" style="display: none"></span>');
action: 'query',
 
titles: mw.config.get('wgPageName'),
+
$('#wpTextbox').val(data)
prop: 'revisions',
 
rvprop: 'content',
 
format: 'json'
 
}, 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;">' + data.query.pages[mw.config.get('wgArticleId')].revisions[0]['*'] + '</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> <span id="status" style="display: none"></span>');
 
 
$('#wpSubmit').on('click', function() {
 
$('#wpSubmit').on('click', function() {
 
$('#status').css('display', 'inline').html('<img src="' + mw.config.get('stylepath') + '/common/images/ajax.gif"> Publishing edit...');
 
$('#status').css('display', 'inline').html('<img src="' + mw.config.get('stylepath') + '/common/images/ajax.gif"> Publishing edit...');

Revision as of 18:23, 8 April 2015

/**
 * 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') {
    $('#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> <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.');
                    }
                });
            });
        });
    });
}