User:QwerpQwertus/contenteditable.js

function qqInit{ alert("Be aware that any edits you make using this editor will be made by your account and that you are responsible for them!"); alert("READ THIS! \n DO NOT USE UNLESS YOU ARE IN THE SANDBOX! \n"); document.getElementById('bodyContent').contentEditable='true'; document.getElementById('siteSub').innerHTML +=' | Save This Edit'; } function qqsave{ window.open("http://en.wikipedia.org/w/index.php?title=" + wgPageName + "&action=edit","my_window"); var e=document.getElementById('bodyContent').innerHTML; qqEdit(wgPageName, e); }

function edit_page(_token, title, text) { var parameters = 'action=edit&title=' + title + '&text=' + text + encodeURIComponent(_token); api.open('POST', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', true); // just reuse the same query object api.onreadystatechange = alert_result; api.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); api.setRequestHeader('Connection', 'keep-alive'); api.setRequestHeader('Content-length', parameters.length); api.send(parameters); // process response function alert_result { if(api.readyState==4) { if(api.status==200) { alert('Page edited!'); }			else { alert('The query returned an error.'); }		}	} }

function extract_token { if(api.readyState==4) { if(api.status==200) { var response = eval('(' + api.responseText + ')'); var token = response['query']['pages'][response['query']['pageids'][0]]['edittoken']; edit_page(token, title, text); }		else { alert('The token query returned an error.'); }	} }

// edit page (must be done through POST)

/************ ajax_edit_token('edit', edit_page); function edit_page(_token) { var parameters = 'action=edit&title=User:Pathoschild/Sandbox&text=AJAX_test!&token=' + encodeURIComponent(_token); ajax_post(mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', parameters, alert_result); } function alert_result(_api) { if(_api.ajax_success) { alert('Page edited!'); } else { alert('An error occurred.'); } } }
 * AJAX framework

function qqEdit(title, text){ var api = sajax_init_object; api.open('GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=json&action=query&prop=info&indexpageids=1&intoken=edit&titles=' +title, true); api.onreadystatechange = extract_token; api.send(null); }

$( function {   document.getElementById('siteSub').innerHTML='Launch QwerpEditor | Thanks to Wikipedia (the best encyclopedia)'; } );