Jump to content

User:Maxim/rmuaa.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// test stuff for usernames
// derived from [[User:Legoktm/rescaled.js]]

if ( mw.config.get('wgNamespaceNumber') > 0 ) {  
	mw.loader.using( ['mediawiki.util', 'mediawiki.api'], function() {
		var rmuaa_tab = mw.util.addPortletLink( 'p-cactions', '#',
			'rmuaa', 'ca-rmuaa', 'rmuaa');
		$( rmuaa_tab ).click( rm_uaa );
	});
}

// rm_uaa function


function rm_uaa() {
	var api = new mw.Api();
	api.get( {
		action: 'query',
		prop: 'imageinfo|revisions',
		titles: mw.config.get('wgPageName'),
		iiprop: 'archivename',
		iilimit: 'max',
		rvprop: 'content',
		rvlimit: '1'
	}).done( function ( data ) {
		var pgdata = data.query.pages[mw.config.get('wgArticleId')];
	

		// Also edit!
		var text = pgdata.revisions[0]['*'];
		// from drilnoth's script
		text = text.replace(/\n*<!-- THE FOLLOWING CATEGORY SHOULD BE REMOVED WHEN THE USER IS BLOCKED, OR IT IS DECIDED THE NAME DOES NOT APPEAR TO VIOLATE POLICY, OR THIS TEMPLATE HAS BEEN IN PLACE FOR A WHILE WITH NO ACTION:  --> {{#ifeq:{{ROOTPAGENAME}}\|.*\|\[\[Category:Wikipedia usernames with possible policy issues\|{{PAGENAME}}]]}}/ig,'');
		text = text.trim();
		api.postWithToken( 'edit', {
			action: 'edit',
			title: mw.config.get('wgPageName'),
			summary: 'Remove [[:Category:Wikipedia usernames with possible policy issues]] for inactive account',
			text: text
		}).done( function ( data ) {
			mw.notify("Removed the category.");
		});

		var text2 = pgdata.revisions[0]['*'];
text2 = text2.replace(/\n*<!-- THE FOLLOWING TWO CATEGORIES \(down to \*\*\*\) SHOULD BE REMOVED WHEN THE USER IS BLOCKED, OR IT IS DECIDED THE NAME DOES NOT APPEAR TO VIOLATE POLICY, OR THIS TEMPLATE HAS BEEN IN PLACE FOR A WHILE WITH NO ACTION\. --> {{#ifexpr: \(\{\{CURRENTTIMESTAMP\}\} - \d+\) < \d+ \| \[\[Category:User talk pages with conflict of interest notices\|{{PAGENAME}}]] \|  }} {{#ifeq:{{BASEPAGENAME}}\|.*\|\[\[Category:Wikipedia usernames with possible policy issues\|{{PAGENAME}}]]}} <!-- \*\*\* -->/ig,'');
text = text.trim();
		api.postWithToken( 'edit', {
			action: 'edit',
			title: mw.config.get('wgPageName'),
			summary: 'Remove [[:Category:Wikipedia usernames with possible policy issues]] for inactive account',
			text: text2
		}).done( function ( data ) {
			mw.notify("Removed the category.");
		});
	});
}



// end rm_uaa function