User:DreamRimmer/NotifyBotOP.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:DreamRimmer/NotifyBotOP. |
//<nowiki>
mw.loader.using(['mediawiki.util', 'oojs-ui'], function () {
if (mw.config.get('wgPageName').startsWith('Wikipedia:Bots/Requests_for_approval/')) {
mw.util.addPortletLink('p-cactions', '#', 'Notify bot operator', 'ca-notify-bot-operator', 'Notify bot operator');
var getOp = function () {
return new mw.Api().get({
action: 'query',
prop: 'revisions',
titles: mw.config.get('wgPageName'),
rvprop: 'content',
format: 'json'
}).then(data => {
var content = Object.values(data.query.pages)[0].revisions[0]['*'];
var match = content.match(/\{\{botop\|(.*?)\}\}/);
return match ? match[1].trim() : null;
});
};
$(document).on('click', '#ca-notify-bot-operator', function (e) {
e.preventDefault();
getOp().then(botOp => {
if (!botOp) return alert('Could not find bot operator username.');
function Dialog(config) {
Dialog.super.call(this, config);
}
OO.inheritClass(Dialog, OO.ui.ProcessDialog);
Dialog.static.name = 'notifyBotDialog';
Dialog.static.title = 'Notify Bot Operator';
Dialog.static.actions = [
{ action: 'accept', label: 'Notify', flags: ['primary', 'progressive'] },
{ action: 'cancel', label: 'Cancel', flags: 'safe' }
];
Dialog.prototype.initialize = function () {
Dialog.super.prototype.initialize.apply(this, arguments);
this.options = {
'Trial approved': 'Hello {{subst:BASEPAGENAME}}, your BRFA at [[' + mw.config.get('wgPageName') + ']] is approved for a trial. Thanks!',
'Approved for extended trial': 'Hello {{subst:BASEPAGENAME}}, your BRFA at [[' + mw.config.get('wgPageName') + ']] is approved for an extended trial. Thanks!',
'On hold': 'Hello {{subst:BASEPAGENAME}}, your BRFA at [[' + mw.config.get('wgPageName') + ']] was put on hold. Thanks!',
'Request Expired': 'Hello {{subst:BASEPAGENAME}}, your BRFA at [[' + mw.config.get('wgPageName') + ']] was marked as expired. Thanks!',
'Withdrawn by operator': 'Hello {{subst:BASEPAGENAME}}, your BRFA at [[' + mw.config.get('wgPageName') + ']] was marked as withdrawn. Thanks!',
'Denied': 'Hello {{subst:BASEPAGENAME}}, your BRFA at [[' + mw.config.get('wgPageName') + ']] was denied. Thanks!',
'Revoked': 'Hello {{subst:BASEPAGENAME}}, your BRFA at [[' + mw.config.get('wgPageName') + ']] was revoked. Thanks!',
'Approved': 'Hello {{subst:BASEPAGENAME}}, your BRFA at [[' + mw.config.get('wgPageName') + ']] was approved. Best regards,'
};
this.radioSelect = new OO.ui.RadioSelectWidget({
items: Object.keys(this.options).map(key => new OO.ui.RadioOptionWidget({ data: key, label: key }))
});
var fieldset = new OO.ui.FieldsetLayout({ label: 'Select Notification Status', padded: true });
fieldset.addItems([new OO.ui.FieldLayout(this.radioSelect, { align: 'top' })]);
this.content = new OO.ui.PanelLayout({ padded: true, expanded: false });
this.content.$element.append(fieldset.$element);
this.$body.append(this.content.$element);
this.actions.setMode('edit');
};
Dialog.prototype.getActionProcess = function (action) {
if (action === 'accept') {
return new OO.ui.Process(() => {
var selected = this.radioSelect.findSelectedItem();
if (!selected) return alert('Please select a notification status.'), OO.ui.Process.reject();
var msg = this.options[selected.getData()];
return new mw.Api().postWithEditToken({
action: 'edit',
title: 'User talk:' + botOp,
appendtext: '\n== Your BRFA ==\n' + msg + ' ~~~~',
summary: 'Notifying bot operator (using [[User:DreamRimmer/NotifyBotOP|NotifyBotOP.js]])'
}).then(() => {
return new Promise(resolve => setTimeout(() => {
this.close({ action });
alert('Notification sent successfully!');
window.location.reload();
resolve();
}, 4000));
}).catch(err => { alert('Failed to send notification: ' + err); throw err; });
});
}
if (action === 'cancel') return new OO.ui.Process(() => this.close({ action }));
return Dialog.super.prototype.getActionProcess.call(this, action);
};
var wm = new OO.ui.WindowManager();
$(document.body).append(wm.$element);
var dlg = new Dialog({ size: 'medium' });
wm.addWindows([dlg]);
wm.openWindow(dlg);
});
});
}
});
//</nowiki>