User:DannyS712/Draft re cat.js: Difference between revisions

Content deleted Content added
caps
a whole bunch of cleanup based on draft no cat, warning: not tested, please let me know if stuff breaks
 
(One intermediate revision by the same user not shown)
Line 5:
//
// If forking this script, please note my contributions / give me credit
$(() => {
 
varconst DRC_configDraftReCat = {};
window.DraftReCat = DraftReCat;
DraftReCat.config = {
name: '[[User:DannyS712/Draft re cat|draft re cat]]',
version: 1.01,
debug: false
};
 
var DRC_summaryDraftReCat.summary = 'Restore categorization (using ' + DRC_configDraftReCat.config.name + " v" + DRC_configDraftReCat.config.version + ").";
if (DRC_config.debug) console.log ( DRC_summary );
DraftReCat.run = function () {
if ( DraftReCat.config.debug ) {
console.log ( DraftReCat.summary );
};
var api = new mw.Api();
api.get( {
action: 'query',
titles: mw.config.get( 'wgPageName' ),
prop: 'revisions',
rvprop: 'content',
rvslots: 'main',
formatversion: 2
} ).done(
function ( response ) {
console.log( response );
var text = response.query.pages[0].revisions[0].slots.main.content;
var textnewText = text
.replace( /\[\[:Category/gi, '\[\[Category' ); // Replace links with categorization
 
api.postWithEditToken( {
action: 'edit',
pageid title: mw.config.get( 'wgArticleIdwgPageName' ),
text: newText,
summary: DraftReCat.summary
} ).done(
).done( function() {
___location.reload();
}
);
}
} );
};
 
});
 
$( document ).ready( () => {
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
mw.loader.using(
[ 'mediawiki.util' ],
function () {
var link = mw.util.addPortletLink( 'p-cactions', '#', 'DRC', 'ca-drc', 'Draft re cats');
$(document).ready( function () {
$( link ).click( function ( event ) {
var link = mw.util.addPortletLink( 'p-cactions', '#', 'DRC', 'ca-drc', 'Draft re cats');
event.preventDefault();
$( link ).click( function ( event ) {
mw.loader.using( 'mediawiki.api', window.DraftReCat.run );
event.preventDefault();
} );
draft_re_cat();
}
} );
} );
}
} );
function draft_re_cat(){
var send_req = {
action: 'query',
titles: mw.config.get( 'wgPageName' ),
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 links with categorization
var submit = {
action: 'edit',
pageid: mw.config.get( 'wgArticleId' ),
text: text,
summary: DRC_summary,
minor: true,
token: mw.user.tokens.get( 'editToken' )
};
$.when(
$.post( mw.config.get( 'wgScriptPath' ) + '/api.php', submit, function( response ){ } )
).done( function() {
___location.reload();
} );
} );