User:Quarl/wikiedit.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Quarl/wikiedit. |
// 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>