User:Doğu/Adiutor-PRD.js

/* * Adiutor: A gadget to assist various user actions * Author: Vikipolimer * Translation: Kadı * Licencing and attribution: WP:Adiutor * Module: Proposed deletion */ /* */ $.when(mw.loader.using(["mediawiki.user", "oojs-ui-core", "oojs-ui-windows", ]), $.ready).then(function {   var mwConfig = mw.config.get(["wgAction", "wgPageName", "wgTitle", "wgUserGroups", "wgUserName", "wgCanonicalNamespace", "wgNamespaceNumber"]);    var api = new mw.Api;    var prdSendMessageToCreator = localStorage.getItem("prdSendMessageToCreator") == "true";    var PRDText, PRDSummary;

function ProposedDeletionDialog(config) { ProposedDeletionDialog.super.call(this, config); }   OO.inheritClass(ProposedDeletionDialog, OO.ui.ProcessDialog); ProposedDeletionDialog.static.name = 'ProposedDeletionDialog'; ProposedDeletionDialog.static.title = 'Adiutor (Beta) - Proposed deletion (PROD)'; ProposedDeletionDialog.static.actions = [{ action: 'save', label: 'Propose', flags: ['primary', 'progressive'] }, {       label: 'Cancel', flags: 'safe' }];   ProposedDeletionDialog.prototype.initialize = function { ProposedDeletionDialog.super.prototype.initialize.apply(this, arguments); var headerTitle = new OO.ui.MessageWidget({           type: 'notice',            inline: true,            label: new OO.ui.HtmlSnippet(' Proposed deletion (PROD) PROD process is to suggest that the item can  be deleted without a nomination page, although it does not meet the stricter criterias required for speedy deletion. ')       });        ProposeOptions = new OO.ui.FieldsetLayout({            label: 'Type of proposed deletion'        }); ProposeOptions.addItems([           new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                selected: false,                value: 'standardPropose'            }), { label: 'PROD (Proposed deletion)', help: 'Proposing deletion in accordance with WP:PROD', align: 'inline' }),           new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                selected: false,                value: 'LivingPersonPropose'            }), { label: 'BLP PROD (unsourced biographies of living people\'s PROD process)', help: 'Proposed deletion of new and completely unsourced living human biographies in accordance with WP:BLP', align: 'inline' }), rationaleField = new OO.ui.FieldLayout(rationaleInput = new OO.ui.MultilineTextInputWidget({               placeholder: 'Rationale for proposed deletion',                indicator: 'required',                value: '',            }), { label: 'Rationale', align: 'inline', }),           new OO.ui.FieldLayout(new OO.ui.ToggleSwitchWidget({                value: prdSendMessageToCreator,                data: 'informCreator'            }), { label: 'Notify the creator', align: 'top', help: 'If selected, a notification template will be placed on the talk page of the user who created the page.', })       ]);        rationaleInput.on('change', function {            if (rationaleInput.value != "") {                InputFilled = false;            } else {                InputFilled = true;            }        }); this.content = new OO.ui.PanelLayout({           padded: true,            expanded: false        }); this.content.$element.append(headerTitle.$element, '  ', ProposeOptions.$element); this.$body.append(this.content.$element); };   ProposedDeletionDialog.prototype.getActionProcess = function(action) { var dialog = this; if (action) { return new OO.ui.Process(function {               var date = new Date;                var Months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];                var PRDoptions = [];                ProposeOptions.items.forEach(function(Option) { if (Option.fieldWidget.selected) { PRDoptions.push({                           value: Option.fieldWidget.value,                            selected: Option.fieldWidget.selected                        }); }                   if (Option.fieldWidget.value === true) { PRDoptions.push({                           value: Option.fieldWidget.value,                            data: Option.fieldWidget.data                        }); }               });                PRDoptions.forEach(function(Option) { if (Option.value === "standardPropose") { PRDText = ''; PRDSummary = 'Proposing article for deletion per WP:PROD'; }                   if (Option.value === "LivingPersonPropose") { PRDText = ''; PRDText = 'Living person biography with no references.'; PRDSummary = 'Proposing article for deletion per WP:BLPPROD'; }                   if (Option.data === "informCreator") { getCreator.then(function(data) {                           var Author = data.query.pages[mw.config.get('wgArticleId')].revisions[0].user;                            if (!mw.util.isIPAddress(Author)) {                                var message =  + mwConfig.wgPageName.replace(/_/g, " ") + ;                                sendMessageToAuthor(Author, message);                            }                        }); }               });                putPRDTemplate(PRDText);                dialog.close({ action: action });           });        }        return ProposedDeletionDialog.super.prototype.getActionProcess.call(this, action); };   var windowManager = new OO.ui.WindowManager; $(document.body).append(windowManager.$element); var dialog = new ProposedDeletionDialog; windowManager.addWindows([dialog]); windowManager.openWindow(dialog);

function putPRDTemplate(PRDText) { api.postWithToken('csrf', {           action: 'edit',            title: mwConfig.wgPageName,            prependtext: PRDText + "\n",            summary: PRDSummary,            //tags: 'Adiutor',            format: 'json'        }).done(function {            location.reload;        }); }

function getCreator { return api.get({           action: 'query',            prop: 'revisions',            rvlimit: 1,            rvprop: ['user'],            rvdir: 'newer',            titles: mwConfig.wgPageName        }); }

function sendMessageToAuthor(Author, message) { api.postWithToken('csrf', {           action: 'edit',            title: 'User_talk:' + Author,            appendtext: '\n' + message,            summary: 'Notification: proposed deletion of ' + mwConfig.wgPageName.replace(/_/g, " ") + '.',            tags: 'Adiutor',            format: 'json'        }); } }); /* */