Jump to content

User:Pxma/simpleajax.js

From Wikipedia, the free encyclopedia
(Redirected from User:PxMa/simpleajax.js)
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.
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' , mw.config.get('wgServer') + mw.config.get('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' , mw.config.get('wgServer') + mw.config.get('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' , mw.config.get('wgServer') + mw.config.get('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' , mw.config.get('wgServer') + mw.config.get('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' , mw.config.get('wgServer') + mw.config.get('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' , mw.config.get('wgServer') + mw.config.get('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' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?' + QueryString.create( xmlhttp.query ), true);
 xmlhttp.onload = function() {
  form = this.responseXML.getElementById( 'editform' );
  var text = form.wpTextbox1.value;
  if (summary == "Closing AfD") { text.replace(/\{\{REMOVE THIS TEMPLATE WHEN CLOSING THIS AfD\|[^\}]*\}\}/, ''); }
  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' , mw.config.get('wgServer') + mw.config.get('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