MediaWiki:Gadget-LazyAdminTools-core.js: Difference between revisions

no edit summary
(Created page with "// LazyAdminTools: easy delete, rollback, and block buttons for admins // @author Jr Mime // @author Iiii_I_I_I $(function () { if (mw.config.get("wgCanonicalSpecialPageName") != "Contributions") return; var username = mw.config.get("wgPageName").split("/")[1], lazyAdminTools = {}; // Fieldset maker lazyAdminTools.init = function () { var blockSection = new OO.ui.ActionFieldLayout( new OO.ui.ComboBoxInputWidget({...")
 
No edit summary
 
Line 1:
"use strict";
 
// LazyAdminTools: easy delete, rollback, and block buttons for admins
// @author Jr Mime
Line 4 ⟶ 6:
 
$(function () {
if (mw.config.get("wgCanonicalSpecialPageName") != "Contributions") return;
var username = mw.config.get("wgPageName").split("/")[1],
lazyAdminTools = {};
 
// Fieldset maker
var username = mw.config.get("wgPageName").split("/")[1],
lazyAdminTools.init = function () {
lazyAdminTools = {};
var blockSection = new OO.ui.ActionFieldLayout(new OO.ui.ComboBoxInputWidget({
options: [{
data: '1 day'
}, {
data: '3 days'
}, {
data: '1 week'
}, {
data: '2 weeks'
}, {
data: '1 month'
}, {
data: '3 months'
}, {
data: 'infinite'
}],
value: '3 days',
placeholder: 'Block duration'
}), new OO.ui.ButtonWidget({
classes: ['LAT-button-block'],
label: 'Block'
}), {
align: 'top',
classes: ['LAT-section-block'],
label: 'Block with reason "Spam/vandalism" for:'
});
var deleteSection = new OO.ui.ActionFieldLayout(new OO.ui.TextInputWidget({
value: 'Removing spam/vandalism',
placeholder: 'Reason for deletion'
}), new OO.ui.ButtonWidget({
classes: ['LAT-button-delete'],
label: 'Delete'
}), {
align: 'top',
classes: ['LAT-section-delete'],
label: 'Delete page creations with reason:'
});
var rollbackSection = new OO.ui.FieldLayout(new OO.ui.ButtonWidget({
classes: ['LAT-button-rollback'],
label: 'Rollback'
}), {
align: 'top',
classes: ['LAT-section-rollback'],
label: 'Revert current revisions:'
});
var everythingSection = new OO.ui.FieldLayout(new OO.ui.ButtonWidget({
classes: ['LAT-button-everything'],
label: 'You\'re a big guy',
title: 'For you',
flags: ['primary', 'destructive']
}), {
align: 'top',
classes: ['LAT-section-everything'],
label: 'Perform all three actions:'
});
$('<fieldset/>', {
"class": 'gadget-LAT'
}).append($('<legend/>', {
text: 'LazyAdminTools'
}), $('<div/>', {
"class": 'LAT-container'
}).append(blockSection.$element, deleteSection.$element, rollbackSection.$element, everythingSection.$element)).prependTo('#mw-content-text');
 
// On click of any of the buttons, call the functions
// Fieldset maker
lazyAdminTools$(".init =LAT-button-rollback").on("click", function () {
lazyAdminTools.rollback();
var blockSection = new OO.ui.ActionFieldLayout(
});
new OO.ui.ComboBoxInputWidget({
$(".LAT-button-block").on("click", function () {
options: [
lazyAdminTools.block();
{ data: '1 day' },
});
{ data: '3 days' },
$(".LAT-button-delete").on("click", function () {
{ data: '1 week' },
lazyAdminTools.del();
{ data: '2 weeks' },
});
{ data: '1 month' },
$(".LAT-button-everything").on("click", function () {
{ data: '3 months' },
// Poor way of doing all
{ data: 'infinite' }
lazyAdminTools.rollback();
],
lazyAdminTools.block();
value: '3 days',
lazyAdminTools.del();
placeholder: 'Block duration'
}),;
};
new OO.ui.ButtonWidget({
classes: ['LAT-button-block'],
label: 'Block'
}),
{
align: 'top',
classes: ['LAT-section-block'],
label: 'Block with reason "Spam/vandalism" for:',
}
);
var deleteSection = new OO.ui.ActionFieldLayout(
new OO.ui.TextInputWidget({
value: 'Removing spam/vandalism',
placeholder: 'Reason for deletion'
}),
new OO.ui.ButtonWidget({
classes: ['LAT-button-delete'],
label: 'Delete'
}),
{
align: 'top',
classes: ['LAT-section-delete'],
label: 'Delete page creations with reason:'
}
);
var rollbackSection = new OO.ui.FieldLayout(
new OO.ui.ButtonWidget({
classes: ['LAT-button-rollback'],
label: 'Rollback'
}),
{
align: 'top',
classes: ['LAT-section-rollback'],
label: 'Revert current revisions:'
}
);
var everythingSection = new OO.ui.FieldLayout(
new OO.ui.ButtonWidget({
classes: ['LAT-button-everything'],
label: 'You\'re a big guy',
title: 'For you',
flags: [ 'primary', 'destructive' ]
}),
{
align: 'top',
classes: ['LAT-section-everything'],
label: 'Perform all three actions:'
}
);
 
// Rollback function: get all rollback links in browser, then strike the edit
$('<fieldset/>', { class: 'gadget-LAT' }).append(
lazyAdminTools.rollback = function () {
$('<legend/>', { text: 'LazyAdminTools' }),
$(".mw-rollback-link a").each(function (i) {
$('<div/>', { class: 'LAT-container' }).append(
var obj = blockSection.$element(this),
href = deleteSectionobj.$element,attr("href");
setTimeout(function () {
rollbackSection.$element,
$.get(href);
everythingSection.$element
obj.text("gone!").css({
color: "grey",
).prependTo('#mw-content-text');
"text-decoration": "line-through"
 
}).removeAttr("href").parents().eq(1).css({
// On click of any of the buttons, call the functions
color: "grey",
$(".LAT-button-rollback").on("click", function () {
"text-decoration": "line-through"
lazyAdminTools.rollback();
}).children().removeAttr("href").css({
color: "grey",
"text-decoration": "line-through"
});
}, i * 500);
});
};
 
// Block function, simple API call
$(".LAT-button-block").on("click", function () {
lazyAdminTools.block = function () {
lazyAdminTools.block();
new mw.Api().postWithEditToken({
});
format: "json",
action: "block",
user: username,
expiry: $('.LAT-section-block .oo-ui-inputWidget-input').val(),
nocreate: 0,
autoblock: 0,
reason: "Spam/vandalism",
bot: 1
}).done(function (d) {
if (!d.error) {
alert("User has been blocked!");
} else {
alert("Failed to block " + username + ": " + d.error.code);
}
}).fail(function () {
alert("Failed to block " + username + "!");
});
};
 
// Delete function, get all titles if the line has a "newpage" attribute, delete
$(".LAT-button-delete").on("click", function () {
lazyAdminTools.del = function () {
lazyAdminTools.del();
function apiDelete(page, reason) {
});
new mw.Api().postWithEditToken({
 
format: "json",
$(".LAT-button-everything").on("click", function () {
action: // Poor way of doing all"delete",
title: lazyAdminTools.rollback();page,
reason: lazyAdminTools.block();reason,
bot: lazyAdminTools.del();1
});.done(function (d) {
if (!d.error) {
};
// console.log('Deletion of ' + page + ' successful!');
 
} else {
// Rollback function: get all rollback links in browser, then strike the edit
console.log("Failed to delete " + page + ": " + d.error.code);
lazyAdminTools.rollback = function () {
$(".mw-rollback-link a").each(function (i) {
var obj = $(this),
href = obj.attr("href");
 
setTimeout(function () {
$.get(href);
obj.text("gone!")
.css({
color: "grey",
"text-decoration": "line-through",
})
.removeAttr("href")
.parents()
.eq(1)
.css({
color: "grey",
"text-decoration": "line-through",
})
.children()
.removeAttr("href")
.css({
color: "grey",
"text-decoration": "line-through",
});
}, i * 500);
});
};
 
// Block function, simple API call
lazyAdminTools.block = function () {
new mw.Api()
.postWithEditToken({
format: "json",
action: "block",
user: username,
expiry: $('.LAT-section-block .oo-ui-inputWidget-input').val(),
nocreate: 0,
autoblock: 0,
reason: "Spam/vandalism",
bot: 1
})
.done(function (d) {
if (!d.error) {
alert("User has been blocked!");
} else {
alert("Failed to block " + username + ": " + d.error.code);
}
})
.fail(function () {
alert("Failed to block " + username + "!");
});
};
 
// Delete function, get all titles if the line has a "newpage" attribute, delete
lazyAdminTools.del = function () {
function apiDelete(page, reason) {
new mw.Api()
.postWithEditToken({
format: "json",
action: "delete",
title: page,
reason: reason,
bot: 1
})
.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 + "!");
});
}
}).fail(function () {
console.log("Failed to delete " + page + "!");
});
}
$("li .newpage ~ a").each(function () {
var title = $(this).attr("title");
apiDelete(title, $('.LAT-section-delete .oo-ui-inputWidget-input').val());
$(this).parent().css({
color: "grey",
"text-decoration": "line-through"
}).children().removeAttr("href").css({
color: "grey",
"text-decoration": "line-through"
});
});
};
 
// Launch the damn thing
$("li .newpage ~ a").each(function () {
lazyAdminTools.init();
var title = $(this).attr("title");
});
 
apiDelete(title, $('.LAT-section-delete .oo-ui-inputWidget-input').val());
$(this)
.parent()
.css({
color: "grey",
"text-decoration": "line-through",
})
.children()
.removeAttr("href")
.css({
color: "grey",
"text-decoration": "line-through",
});
});
};
 
// Launch the damn thing
lazyAdminTools.init();
})