User:TheFearow/simpleajax.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
function simpleAJAXEdit(page, newtext, summary, minor, watch, startsum, endsum, refresh, callback){ xmlhttp = sajax_init_object(); xmlhttp.query = { 'title': page, 'action': 'submit' } if(startsum){ document.getElementById('contentSub').innerHTML = startsum; } xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( xmlhttp.query ), true); xmlhttp.onload = function() { form = this.responseXML.getElementById( 'editform' ); var text = form.wpTextbox1.value; var postData = { 'wpMinoredit': minor, 'wpWatchthis': watch, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summary, 'wpTextbox1': newtext }; var xmlhttp = sajax_init_object(); xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'POST' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( this.query ), true); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.onload = function() { if(endsum){ document.getElementById('contentSub').innerHTML = endsum; }else{ alert('Edit Complete'); } if(refresh){ window.location.reload(); } if(callback){ setTimeout(callback, 100); } }; xmlhttp.send( QueryString.create( postData ) ); } xmlhttp.send( null ); } function simpleAJAXAppend(page, newsuffix, summary, minor, watch, startsum, endsum, refresh, callback){ xmlhttp = sajax_init_object(); xmlhttp.query = { 'title': page, 'action': 'submit' } if(startsum){ document.getElementById('contentSub').innerHTML = startsum; } xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( xmlhttp.query ), true); xmlhttp.onload = function() { form = this.responseXML.getElementById( 'editform' ); var text = form.wpTextbox1.value; var postData = { 'wpMinoredit': minor, 'wpWatchthis': watch, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summary, 'wpTextbox1': text+"\n"+newsuffix }; var xmlhttp = sajax_init_object(); xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'POST' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( this.query ), true); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.onload = function() { if(endsum){ document.getElementById('contentSub').innerHTML = endsum; }else{ alert('Edit Complete'); } if(refresh){ window.location.reload(); } if(callback){ setTimeout(callback, 100); } }; xmlhttp.send( QueryString.create( postData ) ); } xmlhttp.send( null ); } function simpleAJAXPrepend(page, newprefix, summary, minor, watch, startsum, endsum, refresh, callback){ xmlhttp = sajax_init_object(); xmlhttp.query = { 'title': page, 'action': 'submit' } if(startsum){ document.getElementById('contentSub').innerHTML = startsum; } xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( xmlhttp.query ), true); xmlhttp.onload = function() { form = this.responseXML.getElementById( 'editform' ); var text = form.wpTextbox1.value; var postData = { 'wpMinoredit': minor, 'wpWatchthis': watch, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summary, 'wpTextbox1': newprefix+"\n\n"+text }; var xmlhttp = sajax_init_object(); xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'POST' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( this.query ), true); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.onload = function() { if(endsum){ document.getElementById('contentSub').innerHTML = endsum; }else{ alert('Edit Complete'); } if(refresh){ window.location.reload(); } if(callback){ setTimeout(callback, 100); } }; xmlhttp.send( QueryString.create( postData ) ); } xmlhttp.send( null ); } function simpleAJAXAppendPrepend(page, newprefix, newsuffix, summary, minor, watch, startsum, endsum, refresh, callback){ xmlhttp = sajax_init_object(); xmlhttp.query = { 'title': page, 'action': 'submit' } if(startsum){ document.getElementById('contentSub').innerHTML = startsum; } xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'GET' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( xmlhttp.query ), true); xmlhttp.onload = function() { form = this.responseXML.getElementById( 'editform' ); var text = form.wpTextbox1.value; var postData = { 'wpMinoredit': minor, 'wpWatchthis': watch, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summary, 'wpTextbox1': newprefix+"\n\n"+text+"\n"+newsuffix }; var xmlhttp = sajax_init_object(); xmlhttp.overrideMimeType('text/xml'); xmlhttp.open( 'POST' , wgServer + wgScriptPath + '/index.php?' + QueryString.create( this.query ), true); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); xmlhttp.onload = function() { if(endsum){ document.getElementById('contentSub').innerHTML = endsum; }else{ alert('Edit Complete'); } if(refresh){ window.location.reload(); } if(callback){ setTimeout(callback, 100); } }; xmlhttp.send( QueryString.create( postData ) ); } xmlhttp.send( null ); } // Begin Debugging code addPortletLink( 'p-cactions', "javascript:editsandbox()", "exb", "tw-esb", "Edit my sandbox", ""); function editsandbox(){ simpleAJAXEdit('User:TheFearow/Sandbox', 'This is an AJAX test '+Math.random, 'Testing SimpleAJAX', false, true); } // End Debugging code