User:K6ka/RedirectManagement/code.js
Jump to navigation
Jump to search
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Edge: Press Ctrl-Shift-Del, select Cached data and files, and click Clear
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
//<syntaxhighlight lang="javascript">
/*
* Redirect Management
* @description Delete broken redirects and fix double redirects automatically.
* @author Ozuzanna
*/
;(function($, mw) {
if ($('#btn-resolve-broken').length || $('#btn-resolve-double').length)
return;
var ug = mw.config.get("wgUserGroups").join(' ');
if (mw.config.get('wgCanonicalSpecialPageName') == "BrokenRedirects" && (ug.indexOf('sysop') + ug.indexOf('vstf') + ug.indexOf('staff') + ug.indexOf('helper') > -4)) {
$('.mw-spcontent').find('p').first().append('<br/><a class="button" style="cursor:pointer" id="btn-resolve-broken">Resolve Redirects</a>');
$('#btn-resolve-broken').click(function() {
$('.special > li').each(function() {
var page = $(this).find('a').first().text(),
len = $(this).children('a').length;
if (len != 4) //already resolved
return;
new mw.Api().post({
format: 'json',
action: 'delete',
watchlist: 'nochange',
title: page,
reason: '[[Special:BrokenRedirects|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") {
$('.mw-spcontent').find('p').first().append('<br/><a class="button" style="cursor:pointer" id="btn-resolve-double">Resolve Redirects</a>');
$('#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) //already resolved
return;
new mw.Api().post({
action: 'edit',
watchlist: 'nochange',
title: page,
text: '#REDIRECT [['+dest+']]',
summary: '[[Special:DoubleRedirects|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);
//</syntaxhighlight>