User:DannyS712 test/DNC bot.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:DannyS712 test/DNC bot. |
$(function (){
var DNC_bot_config = {
name: '[[User:DannyS712/DNC bot|DNC bot]]',
version: 1.3,
// testing: false,
// disclaimer: "Bot in trial ([[Wikipedia:Bots/Requests for approval/DannyS712 bot 3|BRFA]])",
debug: true
};
var DNC_bot_advert = "Task 3: Disable the categories on this page while it is still a draft, per [[WP:DRAFTNOCAT]]/[[WP:USERNOCAT]], using " + DNC_bot_config.name + " (v. " + DNC_bot_config.version + ")";
//if (DNC_bot_config.testing){
// DNC_bot_advert = DNC_bot_config.disclaimer + ": " + DNC_bot_advert;
//}
mw.loader.using( 'mediawiki.util', function () {
$(document).ready( function () {
//console.log ( mw.config.get( 'wgPageName' ) );
if ( mw.config.get( 'wgPageName' ) === "Category:AfC_submissions_with_categories") {
var link = mw.util.addPortletLink( 'p-cactions', 'javascript:void(0)', 'DNC bot', 'ca-DNCbot', 'DNC bot');
$( link ).click( function ( event ) {
event.preventDefault();
DNC_bot();
} );
}
} );
} );
function DNC_bot () {
var getAFCdrafts = {
action: 'query',
list: 'categorymembers',
cmlimit: 'max',
//cmtitle: mw.config.get( 'wgPageName' ),
cmtitle: 'Category:AfC submissions with categories',
cmprop: 'title',
format: 'json'
};
$.get( mw.config.get( 'wgScriptPath' ) + '/api.php', getAFCdrafts, function( AFCdrafts ) {
//console.log(AFCdrafts);
var pages = AFCdrafts.query.categorymembers;
//var listed = [];
//var links = "";
for (var i = 0; i < pages.length; i++) {
if (pages[i].ns === 2 || pages[i].ns === 118){
var name = pages[i].title;
draft_no_cat( name );
/***
console.log( name );
if ( name === "User:DannyS712 test/sandbox" || name === "User:DannyS712 test" ){
console.log(true);
draft_no_cat( name );
}***/
//listed.push('* [[' + pages[i].title + ']]\n');
//links = links + listed[i];
}
}
//location.reload();
} );
}
function draft_no_cat( title ){
var send_req = {
action: 'query',
titles: title,
prop: 'revisions',
intoken: 'edit',
rvprop: 'content',
indexpageids: 1,
dataType: 'xml',
format: 'xml'
};
$.get( mw.config.get( 'wgScriptPath' ) + '/api.php', send_req, function( response ) {
var text = $( response ).find( 'rev' ).text();
text = text
.replace( /\[\[Category/gi, '\[\[:Category' ); // Replace categorization with links
var submit = {
action: 'edit',
title: title,
text: text,
summary: DNC_bot_advert,
minor: true,
bot: true,
token: mw.user.tokens.get( 'csrfToken' )
};
$.when(
$.post( mw.config.get( 'wgScriptPath' ) + '/api.php', submit, function( response ){ } )
).done( function() {
location.reload();
} );
} );
}
});