MediaWiki:Redirect-management.js

/*
 * Redirect Management
 * @description Delete broken redirects and fix double redirects automatically.
 * @author Ozuzanna
 * migrated to MediaWiki 1.33.1 by Spooky

if ($('#btn-resolve-broken').length || $('#btn-resolve-double').length) return;
 * (function($, mw) {

var ug = mw.config.get("wgUserGroups").join(' '); if (mw.config.get('wgCanonicalSpecialPageName') == "BrokenRedirects" && (ug.indexOf('AW-Staff') + ug.indexOf('CVU') + ug.indexOf('Administrator') + ug.indexOf('ContentModerator') > -4)) { $('.mw-spcontent').find('p').first.append(' Resolve Redirects'); $('#btn-resolve-broken').click(function {			$('.special > li').each(function { var page = $(this).find('a').first.text, len = $(this).children('a').length; if (len != 4) return; //already resolved

new mw.Api.post({					format: 'json',					action: 'delete',					watchlist: 'nochange',					title: page,					reason: 'Resolving Broken Redirect (automatic)',					token: mw.user.tokens.get('editToken')				}) .done(function(d){					if (!d.error){						console.log('Deletion of '+page+' successful!');					}					else {						console.log('Failed to delete '+page+': '+ d.error.code);					}						}) .fail(function{					console.log('Failed to delete '+page+'!');				}); });				setTimeout(function{ location.reload; }, 15000);		});	}

if (mw.config.get('wgCanonicalSpecialPageName') == "DoubleRedirects" && (ug.indexOf('AW-Staff') + ug.indexOf('CVU') + ug.indexOf('Administrator') + ug.indexOf('ContentModerator') > -4)) { $('.mw-spcontent').find('p').first.append(' Resolve Redirects'); $('#btn-resolve-double').click(function {			$('.special > li').each(function { var page = $(this).find('a').first.text, dest = $(this).find('a').last.text, len = $(this).children('a').length; if (len != 4) return; //already resolved

new mw.Api.post({					action: 'edit',					watchlist: 'nochange',					title: page,					text: '#REDIRECT '+dest+'',					summary: 'Resolving Double Redirect (automatic)',					token: mw.user.tokens.get('editToken')				}) .done(function(d) { 					if (!d.error) {						console.log('Resolving double redirect for '+page+' successful!');					}					else {						console.log('Failed to resolve double redirect for '+page+': '+ d.error.code);					}						}) .fail(function {					console.log('Failed to resolve double redirect for '+page+'!');				}); });			setTimeout(function { location.reload; }, 15000);		});	} }) (this.jQuery, this.mediaWiki);