सदस्य:Mayur/spm.js

मुक्त ज्ञानकोश विकिपीडिया से

सूचना: यह पृष्ठ सुरक्षित करने बाद, परिवर्तनों को देखने लिए ब्राउज़र का कैश ख़ाली करने की आवश्यकता हो सकती है।

  • मोज़िला / फ़ायरफ़ॉक्स / सफ़ारी: shift hold करें जब आप reload क्लिक करते है, या Ctrl-Shift-R (अपल मैक में Cmd-Shift-R) दबाएँ;
  • गूगल क्रोम: Ctrl-shift-R (मैक में Cmd-Shift-R) दबाएँ
  • इंटरनेट एक्सप्लोरर: Ctrl hold करें जब आप refresh क्लिक करते हैं, या Ctrl-F5 क्लिक करते हैं;
  • कॉङ्करर: सिर्फ़ Reload बटन पर क्लिक करें, या F5 क्लिक करें;
  • ऑपरा सदस्य को Tools→Preferences में सम्पूर्ण कैश ख़ाली करने की ज़रूरत हो सकती है।
// Note: Requires [[WP:TW]] to work
// Special thanks to the Twinkle project on which this project is based
// This code is released under the GNU General Public License v2

importScript("User:Shirik/spm_whitelist.js");

// Load hook
function spm() 
{
   if (wgNamespaceNumber == 2 || wgNamespaceNumber == 3) 
   {
     mw.util.addPortletLink("p-cactions", "javascript:spm.ltaCallback()", "LTA", "spm-lta", "Report user for long-term abuse", "");
   }
}

var spmWhitelistedUsers = ["Daedalus969", "Shirik", "Bsadowski1"];

// Callback from the WP API
spm.callbacks = 
{
   tagUser: function(self) 
   {
      // Tag as suspected sockpuppet
      form = this.responseXML.getElementById( 'editform' );
      var text = "{{" + (self.params.link != '' ? "blocked" : '') + "sockpuppet|" + self.params.name + (self.params.link != '' ? "|evidence=[[" + self.params.link + "]]" : '') + "}}";
      var postData = {
         'wpStarttime': form.wpStarttime.value,
         'wpEdittime': form.wpEdittime.value,
         'wpAutoSummary': form.wpAutoSummary.value,
         'wpEditToken': form.wpEditToken.value,
         'wpSection': '',
         'wpSummary': 'Tagging as a sockpuppet of ' + self.params.name + (self.params.link == '' ? '' : ' per [[' + self.params.link + ']]') + ' ([[User:Shirik/spm.js|SPM]])',
         'wpTextbox1' : text
      };  
      self.post(postData);

      // Now report to AIV
      var query = {
         'action': 'submit',
         'title': 'Wikipedia:Administrator intervention against vandalism',
         'section': 1
      };
   
      var wikipedia_wiki = new Wikipedia.wiki('Reporting to AIV', query, spm.callbacks.aiv);
      wikipedia_wiki.params = self.params; 
      wikipedia_wiki.followRedirect = false;
      wikipedia_wiki.get(); 
   },
   aiv: function(self) 
   {
      var form = self.responseXML.getElementById('editform');
      var text = form.wpTextbox1.value;

      // check to ensure the user is not yet reported
      var re = new RegExp( "\\{\\{\\s*(?:(?:[Ii][Pp])?[Vv]andal|[Uu]serlinks)\\s*\\|\\s*(?:1=)?\\s*" + RegExp.escape( self.params.user, true ) + "\\s*\\}\\}" );
      if (re.exec(text)) 
      {
         self.statelem.error("The user has already been reported to AIV; will not add another report");
      }
      else 
      {
         self.statelem.info("Adding new report...");
         var postData = {
            'wpStarttime': form.wpStarttime.value,
            'wpEdittime': form.wpEdittime.value,
            'wpAutoSummary': form.wpAutoSummary.value,
            'wpEditToken': form.wpEditToken.value,
            'wpSection': form.wpSection.value,
            'wpSummary': "Reporting [[WP:LTA|LTA]] sock " + (self.params.link == '' ? "[[Special:Contributions/" : "[[" + self.params.link) + "|" + self.params.user + "]] ([[User:Shirik/spm.js|SPM]])",
            'wpTextbox1': text + '*\{\{vandal|1=' + self.params.user + '\}\} - [[WP:LTA|Long-term abuse]] [[WP:SOCK|sockpuppet]] of [[User:' + self.params.name + ']] ' + (self.params.link == '' ? '' : '(see [[' + self.params.link + ']]) ') + '~~' + '~~'
         }  
         self.post(postData);
      }
     
      
   }
}

if (spmWhitelistedUsers.indexOf(wgUserName) != -1) {
   addOnloadHook(spm);
}

// Callback for the form
spm.ltaExecute = function spmLtaExecute(e)
{
   var value = e.target.value;
   var split = value.split("|");
   var name = split[0];
   var link = (split.length == 1) ? '' : split[1];
   
   var params = {
     'name': name,
     'link': link,
     'user': wgPageName.substring(5)
   };

   Status.init(e.target.form);
   Wikipedia.actionCompleted.redirect = "WP:AIV";
   Wikipedia.actionCompleted.notice = "Report complete";
   
   var query = {
      'action': 'submit',
      'title': wgPageName
   };

   var wikipedia_wiki = new Wikipedia.wiki('Tagging user page', query, spm.callbacks.tagUser);
   wikipedia_wiki.params = params; 
   wikipedia_wiki.followRedirect = false;
   wikipedia_wiki.get();   
}

// Callback for clicking the option
spm.ltaCallback = function spmLtaCallback()
{
   var Window = new SimpleWindow( TwinkleConfig.speedyWindowWidth, TwinkleConfig.speedyWindowHeight );
   Window.setTitle("Choose sockpuppet information");
   var form = new QuickForm(spm.ltaExecute, 'change');
   form.append({type: 'header', label: 'Sockmaster'});   

   // Fill in the options
   form.append({
     type: 'radio',
     name: 'lta',
     list: [
         {
            label: 'Wallflowers98',
            value: 'Wallflowers98|WP:LTA/WF98',
            tooltip: 'Prolific vandal engaging in repetitive bad faith copyright violations, primarily 4shared.com'
         },
         {
            label: 'JI Hawkins',
            value: 'JI Hawkins|WP:LTA#Sanders_conspiracy_vandal',
            tooltip: 'Prolific sockmaster inserting content regarding government conspiracies into articles, especially regarding Adam Sandler, Colonel Sanders, and the Men in Black'
         },
         {
            label: 'Andreisme',
            value: 'Andreisme',
            tooltip: 'Prolific sockmaster asking disruptive questions pertaining to Nikola Tesla and areas around Southern California'
         }
     ]
   });

   var result = form.render();
   Window.setContent(result);
   Window.display();
}