User:Kangaroopower/igloocsd.js

//

/* This is the iglooCSD Module, made by Kangaroopower */

/* To Do:

- savelog page is defined through igloosettings.logpage which I don't have control of- ask to integrate

- Add way for savelog to be turned off

  • /

function iglooCSD () {

// iglooCSD

// timer var

this.timer = null;

this.startInterface = function() {

if (document.getElementById('igloo-buttons-csd') == null) return false;

this.csdTagger = new wa_window ( document.getElementById ( 'igloo-buttons-csd' ) );

this.csdTagger.win_top = 71;

this.csdTagger.win_left = -100;

this.csdTagger.win_width = 170;

this.csdTagger.win_height= 80;

this.csdTagger.win_alpha = 0;

this.csdTagger.win_cursor = 'pointer';

this.csdTagger.win_disp = 'none';

this.csdTagger.applyAll ();

this.csdDisplay = new wa_window ( document.getElementById ( 'igloo-buttons-csd' ) );

this.csdDisplay.win_top = 77;

this.csdDisplay.win_left = -100;

this.csdDisplay.win_width = 170;

this.csdDisplay.win_bg = '#d0d0d0';

this.csdDisplay.win_bd = '#000000';

this.csdDisplay.win_bd_wd = 1;

this.csdDisplay.win_padding = 2;

this.csdDisplay.win_fontsize = 10;

this.csdDisplay.win_cursor = 'pointer';

this.csdDisplay.win_disp = 'none';

this.csdDisplay.win_content = '

loading csd tags - wait...
';

this.csdDisplay.applyAll ();

wa_attach ( document.getElementById ( 'igloo-buttons-csd' ), 'mouseenter', igloo.iglooCSD.mouseOver );

wa_attach ( document.getElementById ( 'igloo-buttons-csd' ), 'mouseleave', igloo.iglooCSD.mouseOut );

};

this.mouseOver = function () {

if ( igloo.iglooDiff.viewingDiff === true ) {

if ( igloo.iglooCSD.timer ) { clearTimeout ( igloo.iglooCSD.timer ); igloo.iglooCSD.timer = false; } else {

igloo.iglooCSD.csdDisplay.show();

igloo.iglooCSD.csdTagger.show();

igloo.iglooCSD.csdList ();

}

}

};

this.mouseOut = function () {

// Keeps same timeout as history

igloo.iglooCSD.timer = setTimeout(function() { igloo.iglooCSD.csdDisplay.hide(); igloo.iglooCSD.csdTagger.hide(); igloo.iglooCSD.timer = false; }, iglooSettings.histWinTimeout * 1000);

};

this.csdLink = function (linktype, linkreason) {

return '

';

};

this.csdList = function () {

var pageCSD = '',

reasons = {

"g1": "Patent Nonsense",

"g2": "Test Page",

"g3": "Vandalism",

"g4": "Recreation of Deleted Content",

"g5": "Created by banned user",

"g6": "Maintenence",

"g7": "Blanked or requested by creator",

"g10": "Attack Page",

"g11": "Advertising",

"g12": "Copyvio",

"a1": "No context",

"a2": "Wrong Project",

"a3": "No Content",

"a5": "Transwikied Article",

"a7": "Importance not asserted",

"a9": "Song/Music Article Lacking Artist's article",

"r3": "Implausible typos in redirect"

};

for(var i in reasons) {

pageCSD += igloo.iglooCSD.csdLink(i, reasons[i])

}

// lists all csd templates- for article namespace only

$('#igloocsdTagger-cont').css({display:'block'});

$('#igloocsdTagger-note').({display:'none')};

pageCSD += '

  • - Learn More -
  • ';

    $('#igloocsdTagger-cont').html(pageCSD);

    };

    this.docsdAction = function (page, csdtype) {

    if(iglooSettings.mesysop === true) {

    var csdsummary = csdtype+': Deleting page according to CSD criteria (GLOO)',

    deletecsdPage = new wa_mediawikiApi ();

    deletecsdPage.deletePage( csdPage, csdsummary );

    deletecsdPage.onCompleteAction = function () { igloo.iglooStatus.addStatus( 'Successfully deleted ' + page + '!' ); };

    } else {

    var csdmessage = '{{subst:Db-'+csdtype+'}}',

    csdsummary = 'Tagging page for CSD (GLOO)';

    $.post(mw.util.wikiScript('api') +'?action=edit&title='+page+'&summary='+csdsummary+'&prependtext='+csdmessage+'&token'+ mw.user.tokens.values.editToken, function () {

    igloo.iglooStatus.addStatus( 'Successfully issued a csd tag on ' + page + '!' );

    this.notifyUser(page, csdtype);

    });

    }

    };

    this.notifyUser = function (page, csdtype) {

    $.getJSON(mw.util.wikiScript('api') + '?action=query&prop=revisions&indexpageids=1&titles='+page+'&rvlimit=1&rvprop=user&rvdir=newer&format=json', function (data) {

    var csduser = data.query.pages[data.query.pageids[0]].revisions[0].user,

    csdmessage = '== CSD Tag on '+ page +' == {{subst:Db-notice|target='+ page +'|text= Hello. This page has been tagged for speedy deletion under the '+ csdtype+' criteria.|after explaining position = Best, --~~~~ }}',

    csdsummary = 'Notifying '+ csduser +' about csd tag on '+page+' (GLOO)';

    $.post(mw.util.wikiScript('api') +'?action=edit&title=User_Talk:'+csduser+'&summary='+csdsummary+'&appendtext='+usercsdmessage+'&format=json&token'+ mw.user.tokens.values.editToken, function () {

    igloo.iglooStatus.addStatus( 'Successfully notified the user about the csd tag on ' + thisRevert.revertPage + '!')

    this.saveLog(page, csdtype, csduser);

    });

    });

    };

    this.saveLog = function(page, csdtype, csduser) {

    /* Credit for pretty much the entire concept of this goes to Twinkle */

    /* Converted to use waLib and to work for igloo by Kangaroopower */

    $.getJSON(mw.util.wikiScript('api') +'?action=query&indexpageids=1&titles='+ page +'&format=json', function (data) {

    var text = '';

    if (data.query.pageids[0] === "-1") text += "This is a log of all speedy deletion nominations made by this user using Igloo's CSD module. If you no longer wish to keep this log, you can turn it off in igloo settings and request it deleted under CSD U1.";

    var date = new Date(),

    headerRe = new RegExp("^==+\\s*" + date.getUTCMonthName() + "\\s+" + date.getUTCFullYear() + "\\s*==+", "m");

    if (!headerRe.exec(text)) text += "\n\n=== " + date.getUTCMonthName() + " " + date.getUTCFullYear() + " ===";

    text += "\n# :" + page + ": CSD " + csdtype.toUpperCase() + " ({{tl|db-" + csdtype + "}}); notified {{user|" + csduser + "}}";

    var csdlogsummary = "Logging speedy deletion nomination of "+page+". (GLOO)"

    $.post(mw.util.wikiScript('api') +'?action=edit&title='+iglooSettings.logpage+'&summary='+csdlogsummary+'&appendtext='+usercsdmessage+'&format=json&token='+ mw.user.tokens.values.editToken, igloo.iglooStatus.addStatus( 'Successfully log csd tagging on ' + thisRevert.revertPage + '!'));

    });

    };

    }

    //