Difference between revisions of "User:Kynikos.bot"

From ArchWiki
Jump to: navigation, search
(new task)
(new task)
Line 5: Line 5:
  
 
'''Current tasks:'''
 
'''Current tasks:'''
*Migrate [[Template:Filename]] to [[Template:ic]] (custom plugin)
+
*Migrate [[Template:Package Official]] to [[Template:Pkg]] and [[Template:Package AUR]] to [[Template:AUR]] (custom plugin)
{{hc|Filename2Ic.js|<nowiki>
+
{{hc|PkgAUR.js|<nowiki>
WM.Plugins.Filename2Ic = new function () {
+
WM.Plugins.PkgAUR = new function () {
 
     this.mainAuto = function (args, title) {
 
     this.mainAuto = function (args, title) {
 
         var res = WM.MW.callAPIGet({action: "query",
 
         var res = WM.MW.callAPIGet({action: "query",
Line 25: Line 25:
 
         var source = pageid.revisions[0]["*"];
 
         var source = pageid.revisions[0]["*"];
 
          
 
          
         var newtext = source.replace(/\{\{[Ff]ilename\|/g, "{{ic|");
+
         var newtext = source.replace(/\{\{[Pp]ackage Official\|/g, "{{Pkg|");
 +
        newtext = newtext.replace(/\{\{[Pp]ackage AUR\|/g, "{{AUR|");
 
          
 
          
 
         if (newtext != source) {
 
         if (newtext != source) {
             var summary = "[[Template:Filename]] -> [[Template:ic]] (see [[Help:Style]])";
+
             var summary = "use new package templates, see [[Help:Style]]";
 
              
 
              
 
             res = WM.MW.callAPIPost({action: "edit",
 
             res = WM.MW.callAPIPost({action: "edit",

Revision as of 20:45, 13 February 2012

Kynikos' bot

Powered by Wiki Monkey


Current tasks:

PkgAUR.js
WM.Plugins.PkgAUR = new function () {
    this.mainAuto = function (args, title) {
        var res = WM.MW.callAPIGet({action: "query",
                                    prop: "info|revisions",
                                    rvprop: "content|timestamp",
                                    intoken: "edit",
                                    titles: encodeURIComponent(title)});
        var pages = res.query.pages;
        
        var pageid;
        for each (pageid in pages) {
            break;
        }
        
        var edittoken = pageid.edittoken;
        var timestamp = pageid.revisions[0].timestamp;
        var source = pageid.revisions[0]["*"];
        
        var newtext = source.replace(/\{\{[Pp]ackage Official\|/g, "{{Pkg|");
        newtext = newtext.replace(/\{\{[Pp]ackage AUR\|/g, "{{AUR|");
        
        if (newtext != source) {
            var summary = "use new package templates, see [[Help:Style]]";
            
            res = WM.MW.callAPIPost({action: "edit",
                                     bot: "1",
                                     title: encodeURIComponent(title),
                                     summary: encodeURIComponent(summary),
                                     text: encodeURIComponent(newtext),
                                     basetimestamp: timestamp,
                                     token: encodeURIComponent(edittoken)});
        
            return (res.edit && res.edit.result == 'Success') ? true : false;
        }
        else {
            return true;
        }
    };
};