User:MZMcBride/formfiller.js

/* ******************************************************************************************** Form Filler Inner 0.0.1

Work in progress, text-example of a form-filler-inner, for those pesky forms that don't have query-string parameter pre-loads. For example, action=protect (which currently has an annoying "if( $wgRequest->wasPosted" before checking for parameters.

This is a bare-bones script that should be mostly deprecatable by the devs writing in proper preload routines for all form items!

If you copy this, your version may become deprecated. The in-progress version is at http://en.wikipedia.org/wiki/User:Splarka/formfiller.js (but may move to MediaWiki: namespace if it becomes popular, if so, that page will become a redirect, etc etc).

Instructions:

action=protect. Eg: for Special:Movepage: if(wgCanonicalSpecialPageName=='Movepage') addOnloadHook(formFillers) well as submits if enabled), and dropdown lists) to the appropriate arrays
 * Add an onload check for the page or action that has deficient unprefillable form fields like
 * Add the IDs of the inputs (currently supports (text boxes radio and checkboxes, as
 * Profit!

If you want to be able to autosubmit by URL, add to your local monobook.js (warning: dangerous) var submitByJsEnabled=true; This might be good for, say, temporarily doing a bunch of batch protects or even deletes. This trick has been used to delete thousands of images on commons and much spam on Wikia. The parameter then, if enabled, is &submitForm=IDOFSUBMITBUTTON.



if(wgAction=='unblock') addOnloadHook(formFillers) function formFillers { //text inputs, eg &mwProtect-reason=foo var inputs = ['wpUnblockReason',];

for(var i=0;i<inputs.length;i++) { if(queryString(inputs[i]) && document.getElementById(inputs[i])) { document.getElementById(inputs[i]).value = queryString(inputs[i]); }   //if(queryString(inputs[i]) && document.getElementsByName(inputs[i])[0]) { // document.getElementsByName(inputs[i])[0] = queryString(inputs[i]); //} }

for(var i=0;i<checks.length;i++) { if(queryString(checks[i]) && document.getElementById(checks[i])) { var chk = queryString(checks[i]); if(chk=='true'||chk=='on'||chk=='1') { document.getElementById(checks[i]).checked = true; } else { document.getElementById(checks[i]).checked = false; }   }  }

for(var i=0;i<selects.length;i++) { if(queryString(selects[i]) && document.getElementById(selects[i])) { document.getElementById(selects[i]).selectedIndex = queryString(selects[i]); } }

if(queryString('submitForm') && document.getElementById(queryString('submitForm')) && window.submitByJsEnabled) { document.getElementById(queryString('submitForm')).click; } }

function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } }  return null; }