// Install this version with:
// <code><nowiki> {{subst:Iusc|User:Eumat114/deCOI.js}} </nowiki></code>
// or with
// <code><nowiki> importScript( 'User:Eumat114/deCOI.js' ); // Backlink: [[User:Eumat114/deCOI.js]] </nowiki></code>
//
// If forking this script, please note my contributions / give me credit
$(function (){
var DS_config = {
name: '[[User:Eumat114/deCOI.js|deCOI.js]]',
version: "1.0.1",
debug: false
};
var DS_summary = 'Remove COI template(s) in draftspace with ' + DS_config.name + ' (version ' + DS_config.version + ')';
var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';
mw.loader.using( 'mediawiki.util', function () {
$(document).ready( function () {
if(mw.config.get("wgCanonicalNamespace") == "Draft")
{ mw.util.addPortletLink ( 'p-cactions', 'javascript:void(0)', 'Remove COI', 'ca-de-coi', 'Remove misplaced COI template(s)');
$('#ca-de-coi').on('click', function() {
deCOI();
} );
}} );
} );
function deCOI(){
var name = mw.config.get( 'wgPageName' );
var page = get_page ( name );
if (DS_config.debug) console.log ( page );
var new_page = page.replace(/\{\{UserboxCOI.*?\}\}/gi, "");
if (DS_config.debug) console.log ( new_page );
set_new ( name, new_page );
}
function get_page( name ){
var page_to_get = {
action: 'query',
titles: name,
prop: 'revisions',
rvprop: 'content',
format: 'json',
formatversion: 2
};
var result = null;
$.ajax({
url: scriptUrl,
type: 'get',
data: page_to_get,
dataType: 'json',
async: false,
success: function(page) {
if (DS_config.debug) console.log( page );
result = page.query.pages["0"].revisions["0"].content;
if (DS_config.debug) console.log( result );
}
});
return result;
}
function set_new ( page, new_content ){
console.log( page, new_content );
var to_send = {
action: 'edit',
title: page,
text: new_content,
summary: DS_summary,
token: mw.user.tokens.get( 'csrfToken' )
};
console.log( to_send );
$.when(
$.post( scriptUrl, to_send, function( response ){ } )
).done( function() {
window.location = '//en.wikipedia.org/w/index.php?title=Draft:' + encodeURIComponent( mw.config.get( 'wgTitle' ) ) + '&diff=cur&oldid=prev'; // show diff for further action
} );
}
});