Jump to content

User:Quarl/wikiedit.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Quarl (talk | contribs) at 11:09, 23 January 2006 (new). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
// User:Quarl/wikiedit.js - functions for automatically editing pages

// requires: util.js

// quarl 2006-01-23 initial version

// <pre><nowiki>

function getEditForm(doc) {
    if (!doc) doc = document;
    return doc.getElementById('editform');
}

wpFormFields = [ 'wpSection', 'wpStarttime', 'wpEdittime', 'wpScrolltop', 
                 'wpTextbox1', 'wpSummary', 'wpMinoredit', 'wpWatchthis',
                 'wpEdittoken' ];

function getFormParams(form, button) {
    if (!button) button = 'wpSave';
    d = {};
    for (var i in wpFormFields) {
        var f = wpFormFields[i];
        d[f] = form[f].value;
    }
    d[button] = form[button];
    return d;
}

// creates a new form copying the old form, with all textarea/input entries.
// BUTTON should be 'wpSave', 'wpPreview', or 'wpDiff'; the appropriate button will be copied.
//
function copyFormHidden(form, button) {
    var newform = document.createElement('form');
    addFormHiddenParams(newform, getFormParams(form, button));
    newform.name = form.name;
    newform.method = form.method;
    newform.id = form.id;
    newform.action = form.action;
    return newform;
}

function addFormHiddenParams(newform, d) {
    for (var k in d) {
        var t = document.createElement('input');
        t.type = 'hidden';
        t.name = k;
        t.value = d[k];
        newform.appendChild(t);
    }
    return newform;
}

function WikiEditor(form) {
    if (!(this instanceof WikiEditor)) return new WikiEditor(form);

    this.form = form || getEditForm();

    this.submitHidden = function(button) {
        newform = copyFormHidden(this.form, button);
        document.getElementById('bodyContent').append(newform);
        newform.submit();
    }

    this.submitAsync = function(button, callback) {
        params = getFormParams(this.form, button);
        asyncPostXML(this.form.action, params, callback);
    }

}

// TODO: merge automod.js stuff

// </nowiki></pre>