User:Oxymoron83/twinklewarnauto.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.

importScript('User:AzaToth/twinklewarn.js');
 
addOnloadHook(twinklewarnauto);
 
//originally from [[User:DerHexer/rollback.js]]   
function twinklewarnauto() {
 
   if ( ( wgNamespaceNumber == 3 ) && ( QueryString.exists( 'vanarticle' )) ) {
      if ( !isIPAddress (wgTitle) ) {
          document.getElementById("siteSub").firstChild.nodeValue = "- - - No automatic warning - No IP - - -";
          return;
      }
 
       document.editform.wpMinoredit.checked=true;
       if (document.getElementById( 'wpTextbox1' ).value == "" ) {
               if ( QueryString.get( 'vanarticle' ).slice(0, 5) == "User:" ) {
                    if ( QueryString.get( 'type' ) == "vand" ) { 
                         spam("3", "Warning" , 23 , 0);
                    } else if ( QueryString.get( 'type' ) == "blank" ) {
                         spam("2", "Caution" , 22 , 0);
                    } else {
                         spam("1", "General note" , 21, 0);
                    }
               } else {
                    spam("1", "General note" , 1, 0);
               }
       } else {
         var now = new Date();
         var actual_time = now.getTime();
         var splitted = document.forms["editform"].wpTextbox1.value.split("<!--");
         var last_time = splitted[splitted.length-1].match(/([\:\d]+)\, (\d+) ([^\d]+) (\d+)/);
         var last_timestamp = Date.parse(RegExp.$2 + " " + RegExp.$3 + " " + RegExp.$4 + " " + RegExp.$1 + ":00 GMT");
         var difftime = actual_time - last_timestamp;
 
 
         if (difftime < 69000) {
              document.getElementById("siteSub").firstChild.nodeValue = " - - - No automatic warning - Received a warning in the last minute - - -";
              return;
         }
         if ((difftime > 432000000) || (!last_time)) {           //86400000 = 24 h, 432000000 = 5 d
	        spam("2", "Caution" , 2 , difftime);    
 
         } else {
             if ( (splitted[splitted.length-1].search(/uw\-[^\d]*(\d)/) != -1) || (splitted[splitted.length-1].search(/Template\:Test/) != -1) || (splitted[splitted.length-1].search(/Template\:Blatantvandal/) != -1) || (splitted[splitted.length-1].search(/Uw\-bv/) != -1) ) {
             	var matchedtemplate = splitted[splitted.length-1].match(/uw\-[^\d]*(\d)/);
             	var matchednumber = RegExp.$1;
             	var matchedtemplate2 = splitted[splitted.length-1].match(/Template\:Test(\d)/);
             	var matchednumber2 = RegExp.$1;
                if ( (splitted[splitted.length-1].search(/Template\:Blatantvandal/) != -1) || (splitted[splitted.length-1].search(/Uw\-bv/) != -1) ) {
                      matchednumber = 4;
                }
                if (matchednumber < matchednumber2) { matchednumber = matchednumber2; }
 
                if (difftime > 90000000) {      //90000000 = 25 h
                    if ( (matchednumber == 4) && ( QueryString.get( 'type' ) == "norm" ) ) { matchednumber = 3; }
                    if ( (matchednumber == 2) && ( QueryString.get( 'type' ) == "vand" ) ) { matchednumber = 3; }
                    if (matchednumber == 4) {
                        spam("4im", "Only warning" , 14 , difftime);
	            } else if (matchednumber == 3) {
                        spam("3", "Warning" , 13 , difftime);    
                    } else {
		        spam("2", "Caution" , 12 , difftime);
                    }
 
                 } else {         
              	     if (matchednumber == 4) {
                         if ( difftime > 36000000 ) {     //36000000 = 10 h
                             spam("4im", "Only warning" , 5 , difftime);  
                         } else {
                            //reports only in test status
                            if ((wgUserName != "Oxymoron83") && (wgUserName != "Jauerback") && (wgUserName != "KnowledgeOfSelf")) {
                                document.getElementById("siteSub").firstChild.nodeValue = "- - - No automatic warning - Reached level 4  - - -";
                        	return;
                            } else {
                                if (userIsInGroup( 'sysop' ) ) {
                                   var alerttext = "Vandalism after final warning on " + ( QueryString.exists( 'vanarticle' ) ? QueryString.get( 'vanarticle' ) : '[unknown]');
                                   if ( (wgTitle == "82.148.96.68") || (wgTitle == "82.148.97.69") || (wgTitle == "145.97.39.143") ) { alerttext = "*** SENSITIVE IP ——— " + alerttext + " ***"; }
                                   location.href = wgServer + "/wiki/Special:Contributions/" + wgTitle;
                                   window.alert( alerttext );
                                   return;
                                } else {
                                    var meldenquery = {
		                      'title': 'Wikipedia:Administrator intervention against vandalism',
		                      'action': 'edit',
		                      'section':'1',
		                      'vanarticle': QueryString.exists( 'vanarticle' ) ? QueryString.get( 'vanarticle' ) : '',
		                      'vandal': wgTitle,
		                      'vanarticlerevid': QueryString.exists( 'vanarticlerevid' ) ? QueryString.get( 'vanarticlerevid' ) : '',
		                      'vanarticlegoodrevid': QueryString.exists( 'vanarticlegoodrevid' ) ? QueryString.get( 'vanarticlegoodrevid' ) : '',
		                      //'type': type,
		                      //'count': QueryString.exists( 'count' ) ? QueryString.get( 'count' ) : '',
                                      'aivhelper': true
                                    };
                                    window.open(wgServer + wgScriptPath + '/index.php?' + QueryString.create( meldenquery ),'VM','');
                                } 
                            } 
                         }
             	     } else if (matchednumber == 3) {
	        	spam("4", "Final warning" , 4 , difftime);    
             	     } else {
               		spam("3", "Warning" , 3 , difftime);     
             	     }
                 }
              } else {
             	      spam("2", "Caution", 9 , difftime);
              }
         }
       }
    }
}
 
function spam( Stufe, StufeSum, lognr, difftime2 ) {
      document.getElementById("siteSub").firstChild.nodeValue = "Message-ID: " + lognr;
      var text = document.getElementById( 'wpTextbox1' ).value;
      var date = new Date();  
      var headerRe = new RegExp( "^==+\\s*" + date.getUTCMonthName() + "\\s+" + date.getUTCFullYear() + "\\s*==+", 'm' );
      if( !headerRe.exec( text ) ) {
	  text +=  "\n== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ==\n";
      }
 
 
      switch( QueryString.get( 'type' ) ) {
	case 'vand':
		Art = "Vandalism";
		Tmpl = "uw-vandalism";
              	break;
	case 'blank':
		Art = "Removal of content";
		Tmpl = "uw-delete";
              	break;
	case 'source':
		Art = "Addition of unsourced material";
		Tmpl = "uw-unsourced";
              	break;
	case 'spam':
		Art = "Adding spam links";
		Tmpl = "uw-spam";
              	break;
	default:
		Art = "Editing tests";
		Tmpl = "uw-test";
		break;
      }
 
    document.getElementById( 'wpTextbox1' ).value = text + "\n\{\{subst:" + Tmpl + Stufe + "|"+ QueryString.get( 'vanarticle' ) + "|subst=subst:\}\} --\~\~\~\~\n";
    document.getElementById( 'wpSummary' ).value = StufeSum + ": " + Art + " on [[" + QueryString.get( 'vanarticle' ) + "]]";
    document.editform.wpSave.click();
}