User:Matttest/common.js: Difference between revisions
Content added Content deleted
(Replaced content with "→© CC BY-SA 3.0 Publisher: Matttest: if (mw.config.get('wgNamespaceNumber') % 2 == 1 && (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit")) { $(function () { if (!document.editform || !document.editform.wpSave || !document.editform.wpTextbox1) return; var oldOnclick = document.editform.wpSave.onclick; document.editform.wpSave.onclick = function () { if (oldOnclick && !oldOnclick.apply(this, ar...") Tag: Replaced |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
mw.loader.load('//publictestwiki.com/w/index.php?title=User:Matttest/RemindSign.js&action=raw&ctype=text/javascript');//Reminder of signing talk pages |
|||
/* |
|||
/* The code below is to test for massundeleting pages, don't use this for edit wars! |
|||
© CC BY-SA 3.0 |
|||
Publisher: Matttest |
|||
*/ |
*/ |
||
$(function () { |
|||
if (mw.config.get('wgNamespaceNumber') % 2 == 1 && (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit")) { |
|||
var massUndelete = function (pages, reason, callback) { |
|||
var promises = []; |
|||
if (!document.editform || !document.editform.wpSave || !document.editform.wpTextbox1) return; |
|||
var |
for (var i=0; i<pages.length; i++) { |
||
promises.push($.ajax({ |
|||
document.editform.wpSave.onclick = function () { |
|||
url: mw.util.wikiScript('api'), |
|||
if (oldOnclick && !oldOnclick.apply(this, arguments)) return false; |
|||
data: { |
|||
if (document.editform.wpTextbox1.value.match(/~{3}/)) return true; |
|||
format: 'json', |
|||
action: 'undelete', |
|||
}; |
|||
title: pages[i], |
|||
⚫ | |||
reason: reason, |
|||
} |
|||
token: mw.user.tokens.get('editToken'), |
|||
}, |
|||
dataType: 'json', |
|||
type: 'POST', |
|||
})); |
|||
} |
|||
$.when.apply($, promises).always(function () { |
|||
if (typeof callback === 'function') { |
|||
callback(); |
|||
} |
|||
}); |
|||
⚫ | |||
if (mw.config.get('wgCanonicalNamespace') === 'Special' && mw.config.get('wgCanonicalSpecialPageName') === 'Log') { |
|||
var node = mw.util.addPortletLink('p-cactions', '#', 'MassUndelete'); |
|||
$(node).click(function (e) { |
|||
e.preventDefault(); |
|||
var checked = $('input[type=checkbox]', '.mw-logline-delete').filter(function (index, e) { return e.checked; }); |
|||
if (checked.length === 0) { |
|||
alert('Please select at least one page.'); |
|||
} else { |
|||
var reason = prompt('Restore reason', 'Test done.'); |
|||
if (reason !== null) { |
|||
var pages = []; |
|||
checked.each(function (index, e) { |
|||
var title = $('a.new:last', e.parentElement).text(); |
|||
console.log(title); |
|||
if (title) { |
|||
pages.push(title); |
|||
} |
|||
}); |
|||
massUndelete(pages, reason, function () { |
|||
alert('done'); |
|||
history.go(0); |
|||
}); |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
}); |
Latest revision as of 06:28, 4 May 2022
mw.loader.load('//publictestwiki.com/w/index.php?title=User:Matttest/RemindSign.js&action=raw&ctype=text/javascript');//Reminder of signing talk pages
/* The code below is to test for massundeleting pages, don't use this for edit wars!
*/
$(function () {
var massUndelete = function (pages, reason, callback) {
var promises = [];
for (var i=0; i<pages.length; i++) {
promises.push($.ajax({
url: mw.util.wikiScript('api'),
data: {
format: 'json',
action: 'undelete',
title: pages[i],
reason: reason,
token: mw.user.tokens.get('editToken'),
},
dataType: 'json',
type: 'POST',
}));
}
$.when.apply($, promises).always(function () {
if (typeof callback === 'function') {
callback();
}
});
};
if (mw.config.get('wgCanonicalNamespace') === 'Special' && mw.config.get('wgCanonicalSpecialPageName') === 'Log') {
var node = mw.util.addPortletLink('p-cactions', '#', 'MassUndelete');
$(node).click(function (e) {
e.preventDefault();
var checked = $('input[type=checkbox]', '.mw-logline-delete').filter(function (index, e) { return e.checked; });
if (checked.length === 0) {
alert('Please select at least one page.');
} else {
var reason = prompt('Restore reason', 'Test done.');
if (reason !== null) {
var pages = [];
checked.each(function (index, e) {
var title = $('a.new:last', e.parentElement).text();
console.log(title);
if (title) {
pages.push(title);
}
});
massUndelete(pages, reason, function () {
alert('done');
history.go(0);
});
}
}
});
}
});