User:Max/NotifyBotOP.js

//<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>

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.