Użytkownik:Michał56/common.js
Z Nonsensopedii, polskiej encyklopedii humoru
Uwaga: aby zobaczyć zmiany po zapisaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.
- Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5 lub Ctrl+R (⌘-R na komputerze Mac)
- Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
- Internet Explorer: Przytrzymaj Ctrl jednocześnie klikając Odśwież lub naciśnij klawisze Ctrl+F5
- Konqueror: Kliknij polecenie Odśwież lub naciśnij klawisz F5
- Opera: Wyczyść pamięć podręczną w Narzędzia → Preferencje
//szybki link do statów i zadań
//autor - [[User:Michał56]]
$('#p-cactions > .pBody > ul').append('<li id="ca-qs"><a href="/wiki/Nonsensopedia:Statystyki dzień po dniu?action=edit" id="ca-qs-link">Uzupełnij staty</a></li><li id="ca-qc"><a href="/wiki/Nonsensopedia:Lista zadań" id="ca-qc-link">Zadania</a></li>');
//dodatkowe przyciski w edytorze
if (typeof (mwCustomEditButtons) != 'undefined') {
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "http://upload.wikimedia.org/wikipedia/commons/2/26/Button_latinas.png",
"speedTip": "Wstaw polskie cudzysłowy",
"tagOpen": "„",
"tagClose": "”",
"sampleText": ""
};
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "https://upload.wikimedia.org/wikipedia/commons/3/3f/Button_headline_-_2.png",
"speedTip": "Wstaw półpauzę",
"tagOpen": "–",
"tagClose": "",
"sampleText": ""
};
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "https://upload.wikimedia.org/wikipedia/commons/f/f9/BoutonsDefaut10.png",
"speedTip": "Wstaw podpis",
"tagOpen": "{{Michał56}} <nowiki>{{subst:#time:H:i, M d, Y|+1 hours}}</nowiki> (CET)",
"tagClose": "",
"sampleText": ""
};
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "https://upload.wikimedia.org/wikipedia/commons/a/aa/Button_dot1.PNG",
"speedTip": "Wstaw tą dziwną kropkę",
"tagOpen": "•",
"tagClose": "",
"sampleText": ""
};
mwCustomEditButtons[mwCustomEditButtons.length] = {
"imageFile": "https://upload.wikimedia.org/wikipedia/commons/1/13/Button_delete.png",
"speedTip": "Wrzuć na SDU",
"tagOpen": "{{",
"tagClose": "}}",
"sampleText": "subst:SDU"
};
}
//FastDelete buttons
window.fdButtons = [];
window.fdButtons.push(
{
summary: '[[Nonsensopedia:Bo tak|Bo tak]]',
label: 'Bo tak'
},
{
summary: '[[Nonsensopedia:Wandalizm|Wandalizm]]',
label: 'Wandalizm'
},
{
summary: '[[Nonsensopedia:Prywata|Prywata]]',
label: 'Prywata'
}
);
importArticles( {
type: 'script',
articles: [
'u:dev:FastDelete/code.js',
]
} );
//Nuke
;(function($, mw) {
if (mw.config.get('wgUserGroups').indexOf('sysop') + mw.config.get('wgUserGroups').indexOf('vstf') + mw.config.get('wgUserGroups').indexOf('staff') + mw.config.get('wgUserGroups').indexOf('helper') + mw.config.get('wgUserGroups').indexOf('content-moderator') == -4) return;
switch (mw.config.get('wgCanonicalSpecialPageName')) {
case "Contributions":
$('#contentSub a:nth-child(5)').after(' • <a title="Special:Nuke" href="' + mw.config.get('wgArticlePath').slice(0,-2) + 'Special:Blankpage?blankspecial=nuke&nukeuser=' + mw.config.get('wgPageName').split('/')[1] + '">Nuke</a>');
break;
case "Specialpages":
if (!$('a[title="Special:Nuke"]').length)
$('.mw-specialpagerestricted a[title="Special:Undelete"]').after('<li class="mw-specialpagerestricted"><a title="Special:Nuke" href="' + mw.config.get('wgArticlePath').slice(0,-2) + 'Special:Blankpage?blankspecial=nuke">Mass delete</a></li>');
break;
case "Blankpage":
if ($.getUrlVar('blankspecial') == "nuke")
nukeMain();
break;
}
function nukeMain() {
var config = mw.config.get([
'stylepath',
'wgArticlePath',
'wgFormattedNamespaces',
'wgMainpage',
'wgSiteName'
]),
token = mw.user.tokens.get('editToken'),
API = new mw.Api(),
articlePath = config.wgArticlePath.slice(0,-2),
RCTitles,
usercontribs,
recentchanges,
maxLimit,
count,
escapedTitle;
$('.AdminDashboardGeneralHeader h1').text('Nuke');
document.title = "Nuke - " + config.wgSiteName;
wgCanonicalSpecialPageName = "Nuke";
if ($.getUrlVar('nukeuser')) {
var user = $.getUrlVar('nukeuser'),
deleteReason = window.nukeDeleteReason || "Mass removal of pages created by " + user;
$('#mw-content-text p').html('<a href="' + articlePath + 'Special:Blankpage?blankspecial=nuke">Switch to Nuke main form</a><br/>The following pages were created by <a href="' + articlePath + 'Special:Contributions/' + user + '">' + user + '</a>; put in a comment and hit the button to delete them.<br/>Reason for deletion: <input style="width: 400px" type="text" id="nuke-delete-reason" value="' + deleteReason + '"/><br/><a class="wikia-button nuke-submit">Delete</a><div id="nuke-status"/><div id="nuke-query-results"/><a class="wikia-button nuke-submit">Delete</a>');
$('#nuke-status').html('Getting pages... please wait <img src="' + config.stylepath + '/common/progress-wheel.gif"/>');
API.get({
action: 'query',
list: 'usercontribs',
ucnamespace: $.getUrlVar('nukenamespace') || '',
ucuser: user,
uclimit: 5000,
cb: new Date().getTime()
})
.done(function(d) {
if (!d.error) {
usercontribs = d.query.usercontribs;
maxLimit = $.getUrlVar('nukelimit') || 5000;
count = 0;
for (var i in usercontribs) {
if (count >= maxLimit)
break;
if (usercontribs[i].hasOwnProperty('new')) {
escapedTitle = encodeURIComponent(usercontribs[i].title);
if (!$.getUrlVar('nukematch') || new RegExp($.getUrlVar('nukematch')).test(usercontribs[i].title)) {
$('#nuke-query-results').append('<li class="nuke-query-result"><input type="checkbox" class="nuke-title-check" checked="checked"/> <a href="' + articlePath + escapedTitle + '" target="_blank">' + usercontribs[i].title + '</a></li>');
if (usercontribs[i].title.slice(0,5) == "File:")
displayImage(usercontribs[i].title,articlePath,API);
count++;
}
}
}
if (!$('.nuke-query-result').length)
$('#nuke-status').html('<span style="color:red">No user contributions found</span>');
else
$('#nuke-status').empty();
}
else
$('#nuke-status').html('<span style="color:red">Failed to get user contributions: ' + d.error.code + '</span>');
})
.fail(function() {
$('#nuke-status').html('<span style="color:red">Failed to get user contributions</span>');
});
}
else {
$('#mw-content-text p').html('This tool allows for mass deletions of pages recently added by a given user or IP address.<br/>Input the username or IP address to get a list of pages to delete, or leave blank for all users.<br/>Username, IP address or blank: <input type="text" id="nuke-username"/><br/>Pattern for the page name: <input type="text" id="nuke-match"/><br/>Limit to namespace: <select id="nuke-namespace"><option value="All">All</option><option value="Main" ns="0">Main</option><option value="Project" ns="4">Project</option><option value="Project talk" ns="5">Project talk</option><option value="Dyskusja" ns="1">Dyskusja</option><option value="User" ns="2">User</option><option value="User talk" ns="3">User talk</option><option value="File" ns="6">File</option><option value="File talk" ns="7">File talk</option><option value="Template" ns="10">Template</option><option value="Template talk" ns="11">Template talk</option><option value="Help" ns="12">Help</option><option value="Help talk" ns="13">Help talk</option><option value="Category" ns="14">Category</option><option value="Category talk" ns="15">Category talk</option></select><br/>Maximum number of pages: <input type="text" id="nuke-max" value="500"/><br/><a class="wikia-button" id="nuke-rc">Go</a><br/><div id="nuke-status"/><div id="nuke-query-results"/>');
$('#nuke-rc').click(function() {
if ($(this).attr('disabled')) return;
$(this).attr('disabled','disabled');
if ($('#nuke-username').val()) {
var locationStr = articlePath + 'Special:Blankpage?blankspecial=nuke&nukeuser=' + $('#nuke-username').val();
if ($('#nuke-namespace').val() != "All")
locationStr += '&nukenamespace=' + $('#nuke-namespace option:selected').attr('ns');
if ($.isNumeric($('#nuke-max').val()) && $('#nuke-max').val() > 0)
locationStr += '&nukelimit=' + $('#nuke-max').val();
if ($('#nuke-match').val())
locationStr += '&nukematch=' + $('#nuke-match').val();
location.replace(locationStr);
return;
}
$('#nuke-query-results').empty();
if ($('.nuke-submit').length) {
$('.nuke-submit').remove();
$('#mw-content-text > p:nth-child(1) > br:nth-child(14)').remove();
}
$('#nuke-status').html('Getting pages... please wait <img src="' + config.stylepath + '/common/progress-wheel.gif"/>');
API.get({
action: 'query',
list: 'recentchanges',
rcshow: '!bot',
rctype: 'new|log',
rclimit: 5000,
cb: new Date().getTime()
})
.done(function(d) {
if (!d.error) {
recentchanges = d.query.recentchanges;
RCTitles = [];
maxLimit = $('#nuke-max').val() || 5000;
count = 0;
for (var i in recentchanges) {
if (count >= maxLimit)
break;
if ((($('#nuke-namespace').val() == "Main" && recentchanges[i].title.split(':').length === 1) || $('#nuke-namespace').val() == "All" || $('#nuke-namespace').val() == "Project" && new RegExp(config.wgFormattedNamespaces[4] + ':').test(recentchanges[i].title) || $('#nuke-namespace').val() == "Project talk" && new RegExp(config.wgFormattedNamespaces[5] + ':').test(recentchanges[i].title) || new RegExp($('#nuke-namespace').val() + ':').test(recentchanges[i].title)) && (recentchanges[i].type == "new" || (recentchanges[i].type == "log" && recentchanges[i].ns == 6)) && $.inArray(recentchanges[i].title,RCTitles) == -1) {
if (!$('#nuke-match').val() || new RegExp($('#nuke-match').val()).test(recentchanges[i].title)) {
RCTitles.push(recentchanges[i].title);
escapedTitle = encodeURIComponent(recentchanges[i].title);
$('#nuke-query-results').append('<li class="nuke-query-result"><input type="checkbox" class="nuke-title-check" checked="checked"/> <a href="' + articlePath + escapedTitle + '" target="_blank"> ' + recentchanges[i].title + '</a></li>');
if (recentchanges[i].title.slice(0,5) == "File:")
displayImage(recentchanges[i].title,articlePath,API);
count++;
}
}
}
if (!$('.nuke-query-result').length)
$('#nuke-status').html('<span style="color:red">No recent changes found</span>');
else {
$('#nuke-query-results').before('<br/><a class="wikia-button nuke-submit">Delete</a>').after('<a class="wikia-button nuke-submit">Delete</a>');
$('#nuke-status').empty();
}
}
else
$('#nuke-status').html('<span style="color:red">Failed to get recent changes: ' + d.error.code + '</span>');
})
.fail(function() {
$('#nuke-status').html('<span style="color:red">Failed to get recent changes</span>');
});
$(this).removeAttr('disabled');
});
}
$('.nuke-submit').click(function() {
if (!$('.nuke-query-result').length || $(this).attr('disabled')) return;
$('.nuke-submit').attr('disabled','disabled');
$('#nuke-status').html('Deleting pages... please wait <img src="' + config.stylepath + '/common/progress-wheel.gif"/>');
$('.nuke-title-check:checked').each(function(i) {
var title = $(this).parent().find('a').text();
setTimeout(function() {
API.post({
action: 'delete',
title: title,
reason: $('#nuke-delete-reason').val() || '',
bot: true,
token: token
})
.done(function(d) {
if (!d.error) {
console.log('Deletion of ' + title + ' successful!');
} else {
console.log('Failed to delete ' + title + ': '+ d.error.code);
}
})
.fail(function() {
console.log('Failed to delete ' + title);
});
if (i === $('.nuke-title-check:checked').length - 1) {
setTimeout(function() {
location.replace(articlePath + config.wgMainpage);
}, 1000);
}
}, i*100);
});
});
}
function displayImage(image,path,api) {
api.get({
action: 'query',
prop: 'imageinfo',
titles: image,
iiprop: 'url'
})
.done(function(d) {
if (!d.error) {
for (var i in d.query.pages) {
if (d.query.pages[i].missing != "")
$('a[href="' + path + encodeURIComponent(image) + '"]').parent().children('.nuke-title-check').after('<img src="' + d.query.pages[i].imageinfo[0].url + '" width="120" height="77">');
}
}
});
}
}) (this.jQuery, this.mediaWiki);