User:Iluvatar/GAH.js
Note: After publishing, 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 / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/*
* GLOBAL ACTIONS HELPER
* Script adds global sysop / steward delete, block, protect and nuke reasons.
* Script adds limit of chars (255) for reason input fields.
* Script translating to English typical block and protect expiration time.
* Script adds to userinfo panel (contribs page) links to CentralAuth (for registered users) and GUC.
* Script adds to left side panel links to [[Special:ListUsers&group=sysop]] ('Tools' section).
* Script adds to 'More' menu direct link to Google Translate.
* Script adds indicator under site logo when page is protected (semi / full; edit / move).
* In your https://meta.wikimedia.org/wiki/Special:MyPage/global.js:
mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Iluvatar/GAH.js&action=raw&ctype=text/javascript');
* Author: [[User:Iluvatar]].
* Reasons by: [[m:User:WhitePhosphorus/js/GS_Rationale.js]].
*/
/*jshint esversion: 6 */
(function () {
mw.loader.using('oojs-ui').then(function() {
$( document ).ready( function() {
if ( mw.config.get( 'wgUserGroups' ).indexOf( 'sysop' ) == -1 && mw.config.get( 'wgUserGroups' ).indexOf( 'closer' ) == -1) {
const role = (mw.config.get( 'wgGlobalGroups' ).includes("steward")) ? "S" : "GS";
const role_name = (role === "GS") ? "global sysop" : "steward";
getProtectLvl(mw.config.get('wgRestrictionEdit'), mw.config.get('wgRestrictionMove'));
getUserlinks(mw.config.get('wgCanonicalSpecialPageName'), mw.config.get('wgRelevantUserName'));
if ( mw.config.get( 'wgAction' ) === 'delete' ) {
var selectDelete = new OO.ui.DropdownInputWidget({
options: [
{
data: `Spam ([[m:${role}|${role_name}]] action)`,
label: 'Spam'
},
{
data: `Vandalism ([[m:${role}|${role_name}]] action)`,
label: 'Vandalism'
},
{
data: `No useful content ([[m:${role}|${role_name}]] action)`,
label: 'No useful content'
},
{
data: `Test page ([[m:${role}|${role_name}]] action)`,
label: 'Test page'
},
{
data: `Not written in this project\'s language ([[m:${role}|${role_name}]] action)`,
label: 'Foreign language'
},
{
data: `Requested by the author ([[m:${role}|${role_name}]] action)`,
label: 'Requested by the author'
},
{
data: `Outside the project\'s scope ([[m:${role}|${role_name}]] action)`,
label: 'Out of scope'
}
]
});
$(".oo-ui-fieldLayout-field > #wpDeleteReasonList")[0].style.display = "none";
$(".oo-ui-fieldLayout-field").first().append( selectDelete.$element );
let reason = $('#ooui-php-2');
reason.attr("maxlength", 255);
selectDelete.on( 'change', function (change) {
reason.val( change );
});
reason.val(selectDelete.getValue());
}
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Block' ) {
var selectBlock = new OO.ui.DropdownInputWidget({
options: [
{
data: `Spambot ([[m:${role}|${role_name}]] action)`,
label: 'Spambot'
},
{
data: `Vandalism ([[m:${role}|${role_name}]] action)`,
label: 'Vandalism'
},
{
data: `Spam ([[m:${role}|${role_name}]] action)`,
label: 'Spam'
},
{
data: `Cross-wiki vandalism ([[m:${role}|${role_name}]] action)`,
label: 'Cross-wiki vandalism'
},
{
data: `Open proxy ([[m:${role}|${role_name}]] action)`,
label: 'Open proxy'
}
]
});
$("#mw-input-wpReason > .oo-ui-dropdownInputWidget").first()[0].style.display = "none";
$(".mw-htmlform-select-and-other-field").prepend( selectBlock.$element );
translatingOptionInWidgets(OO.ui.InputWidget.static.infuse($("#mw-input-wpExpiry")).relativeField.dropdowninput, $("#ooui-5"));
let reason = $('input[name="wpReason-other"]');
reason.attr("maxlength", 255);
selectBlock.on( 'change', function (change) {
reason.val( change );
});
reason.val(selectBlock.getValue());
}
if ( mw.config.get( 'wgAction' ) === 'protect' || mw.config.get( 'wgAction' ) === 'unprotect') {
var selectProtect = new OO.ui.DropdownInputWidget({
options: [
{
data: `Persistent spamming ([[m:${role}|${role_name}]] action)`,
label: 'Persistent spamming'
},
{
data: `Persistent vandalism ([[m:${role}|${role_name}]] action)`,
label: 'Persistent vandalism'
},
{
data: `Protection against re-creation ([[m:${role}|${role_name}]] action)`,
label: 'Protection against re-creation'
},
{
data: `Page-move vandalism ([[m:${role}|${role_name}]] action)`,
label: 'Page-move vandalism'
},
{
data: `Protection no longer required ([[m:${role}|${role_name}]] action)`,
label: 'Protection no longer required'
}
]
});
$("#wpProtectReasonSelection >.oo-ui-widget:nth-child(2)")[0].style.display = "none";
$("#wpProtectReasonSelection").append( selectProtect.$element );
if ($("#mwProtectExpirySelection-create").length)
translatingOptionInWidgets(OO.ui.InputWidget.static.infuse($("#mwProtectExpirySelection-create")[0]), $("#ooui-2"));
else {
translatingOptionInWidgets(OO.ui.InputWidget.static.infuse($("#mwProtectExpirySelection-edit")[0]), $("#ooui-3"));
translatingOptionInWidgets(OO.ui.InputWidget.static.infuse($("#mwProtectExpirySelection-move")[0]), $("#ooui-4"));
}
let reason = $("#ooui-php-15");
reason.attr("maxlength", 255);
selectProtect.on( 'change', function (change) {
reason.val( change );
});
reason.val(selectProtect.getValue());
}
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Nuke' ) {
var selectNuke = new OO.ui.DropdownInputWidget({
options: [
{
data: `Spam ([[m:${role}|${role_name}]] action)`,
label: 'Spam'
},
{
data: `Vandalism ([[m:${role}|${role_name}]] action)`,
label: 'Vandalism'
},
{
data: `No useful content ([[m:${role}|${role_name}]] action)`,
label: 'No useful content'
},
{
data: `Test page ([[m:${role}|${role_name}]] action)`,
label: 'Test page'
},
{
data: `Not written in this project\'s language ([[m:${role}|${role_name}]] action)`,
label: 'Foreign language'
},
{
data: `Outside the project\'s scope ([[m:${role}|${role_name}]] action)`,
label: 'Out of scope'
}
]
});
$(".oo-ui-fieldLayout-field > .oo-ui-widget").first()[0].style.display = "none";
$(".oo-ui-fieldLayout-field").first().append(selectNuke.$element );
let reason = $("#wpReason");
reason.attr("maxlength", 255);
selectNuke.on( 'change', function (change) {
reason.val( change );
});
reason.val(selectNuke.getValue());
}
}
function getProtectLvl(editLvl, moveLvl) {
editLvl = (typeof editLvl === "undefined" || editLvl === null) ? editLvl = "" : editLvl.toString();
moveLvl = (typeof moveLvl === "undefined" || moveLvl === null) ? moveLvl = "" : moveLvl.toString();
$( '<div>' ).attr( 'id', 'protectMarker' ).css({"margin-top": "0px", "margin-right": "0.6em", "margin-bottom": "0px", "margin-left": "1.2em"}).insertAfter($('#p-logo'));
const cssProtectFull = {"background-color": "#f94848", "color": "white", "font-size": "smaller"};
const cssProtectSemi = {"background-color": "#519e51", "color": "white", "font-size": "smaller"};
let baseEdit = $( '<span>' ).attr( 'id', 'protectMarkerEdit' );
if (editLvl === "sysop")
$('#protectMarker').append($( '<span>' ).attr( 'id', 'protectMarkerEdit' ).css(cssProtectFull).html("Edit"));
if (editLvl === "autoconfirmed")
$('#protectMarker').append($( '<span>' ).attr( 'id', 'protectMarkerEdit' ).css(cssProtectSemi).html("Edit"));
if (moveLvl === "sysop")
$('#protectMarker').append($( '<span>' ).attr( 'id', 'protectMarkerMove' ).css(cssProtectFull).css({"margin-left": "3px"}).html("Move"));
if (moveLvl === "autoconfirmed")
$('#protectMarker').append($( '<span>' ).attr( 'id', 'protectMarkerMove' ).css(cssProtectSemi).css({"margin-left": "3px"}).html("Move"));
}
function getUserlinks(page, user) {
if (typeof page == "undefined" || typeof user == "undefined" || page.toString() !== "Contributions")
return;
let userLinkSpan = document.createElement("span"); let userLinkA = document.createElement("a");
userLinkA.href = "https://guc.toolforge.org/?by=date&user=" + user.toString(); userLinkA.innerHTML = "GUC";
userLinkSpan.appendChild(userLinkA);
let userLinkCASpan = document.createElement("span"); let userLinkCAA = document.createElement("a");
userLinkCAA.href = "https://meta.wikimedia.org/wiki/Special:CentralAuth/" + user.toString(); userLinkCAA.innerHTML = "CA";
userLinkCASpan.appendChild(userLinkCAA);
document.getElementsByClassName("mw-changeslist-links")[0].appendChild(userLinkSpan);
if (!/^\d*?\.\d*?\.\d*?\.\d*?$/.test(user.toString()) && user.toString().indexOf(":") === -1)
document.getElementsByClassName("mw-changeslist-links")[0].appendChild(userLinkCASpan);
}
function translatingOptionInWidgets(select, reasonEl) {
select.dropdownWidget.getMenu().items.forEach(function (item, count) {
let label = item.data;
if (item.data === "other") label = "Other";
if (item.data === "infinity") label = "Infinity";
select.dropdownWidget.getMenu().items[count].setLabel(label);
});
reasonEl.text(select.getValue());
}
if (mw.config.get( 'wgNamespaceNumber' ) !== -1) {
const url_tr = "https://" + mw.config.get( 'wgServerName' ).replace(/\./g, '-') + ".translate.goog/wiki/" + encodeURIComponent(mw.config.get( 'wgPageName' )) + "?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=wapp";
mw.util.addPortletLink( 'p-cactions', url_tr, 'Translate it');
}
mw.util.addPortletLink( 'p-cactions', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=Special:AbuseFilter&uselang=en', "Abuse filter");
mw.util.addPortletLink( 'p-cactions', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=Special:Newpages&uselang=en', "New pages");
mw.util.addPortletLink( 'p-cactions', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=Special:RecentChanges&uselang=en', "Recent changes");
mw.util.addPortletLink ('p-tb', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=Special:ListUsers&group=sysop&uselang=en', 'Sysop list');
});
});
}
) ();