User:Doğu/Adiutor-CSD.js

/* * Adiutor: A gadget to assist various user actions * Author: Vikipolimer * Translation: Kadı * Licencing and attribution: WP:Adiutor * Module: Creating speedy deletion requests /* */ $.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 revDelCount = 0;    var CopVioURL;    var api = new mw.Api;    api.get({ action: 'query', list: 'logevents', leaction: 'delete/delete', letprop: 'delete', letitle: mwConfig.wgPageName }).done(function(data) { if (data.query.logevents) { revDelCount = data.query.logevents.length; } else { revDelCount = 0; }       var csdSendMessageToCreator = localStorage.getItem("csdSendMessageToCreator") == "true"; // Example: A process dialog that uses an action set with modes. // Subclass ProcessDialog. function ProcessDialog(config) { ProcessDialog.super.call(this, config); }       OO.inheritClass(ProcessDialog, OO.ui.ProcessDialog); // Specify a name for .addWindows ProcessDialog.static.name = 'myDialog'; // Specify a title and an action set that uses modes ('edit' and 'help' mode, in this example). ProcessDialog.static.title = 'Adiutor (Beta) - Create Speedy Deletion'; ProcessDialog.static.actions = [{ action: 'continue', modes: 'edit', label: 'Mark', flags: ['primary', 'progressive'] }, {           action: 'help', modes: 'edit', label: 'Help' }, {           modes: 'edit', label: 'Cancel', flags: ['safe', 'close'] }, {           action: 'back', modes: 'help', label: 'Back', flags: ['safe', 'back'] }];       // Customize the initialize method to add content and set up event handlers. // This example uses a stack layout with two panels: one displayed for // edit mode and one for help mode. ProcessDialog.prototype.initialize = function { ProcessDialog.super.prototype.initialize.apply(this, arguments); switch (mwConfig.wgNamespaceNumber) { case 0: NameSpaceDeletionReasons = new OO.ui.FieldsetLayout({                       label: 'Article'                    }); NameSpaceDeletionReasons.addItems([                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'A1',                            data: 'A1: No context',                            selected: false                        }), { label: 'A1 - No context.', align: 'inline', }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'A2',                            data: 'A2: Article in a foreign language that exists on another project',                            selected: false                        }), { label: 'A2 - Foreign language articles that exist on another Wikimedia project', align: 'inline', }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'A3',                            data: 'WP:CSD: No content',                            selected: false                        }), { label: 'A3 - No content', align: 'inline', }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'A5',                            data: 'WP:CSD: Transwikied articles',                            selected: false                        }), { label: 'A5 - Transwikied articles', align: 'inline', }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'A7',                            data: 'WP:CSD: No indication of importance (people, animals, organizations, web content, events)',                            selected: false                        }), { label: 'A7 - No indication of importance (people, animals, organizations, web content, events)', align: 'inline', }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'A9',                            data: 'WP:CSD: No indication of importance (musical recordings)',                            selected: false                        }), { label: 'A9 - No indication of importance (musical recordings)', align: 'inline', }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'A10',                            data: 'WP:CSD: Recently created article that duplicates an existing topic',                            selected: false                        }), { label: 'A10 - Recently created article that duplicates an existing topic', align: 'inline', }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'A11',                            data: 'WP:CSD: Obviously invented',                            selected: false                        }), { label: 'A11 - Obviously invented', align: 'inline' }),                   ]);                    break; case 6: NameSpaceDeletionReasons = new OO.ui.FieldsetLayout({                       label: 'Files'                    }); NameSpaceDeletionReasons.addItems([                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F1',                            data: 'F1: Redundant',                            selected: false                        }), { label: 'F1 - Redundant', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F2',                            data: 'F2: Corrupt, missing or empty file',                            selected: false                        }), { label: 'F2 - Corrupt, missing or empty file', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F3',                            data: 'File 3: Improper license',                            selected: false                        }), { label: 'F3 - Improper license', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F4',                            data: 'File 4: Lack of licensing information',                            selected: false                        }), { label: 'F4 - Lack of licensing information', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F5',                            data: 'File 5: Orphaned non-free use images',                            selected: false                        }), { label: 'F5 - Orphaned non-free use images', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F6',                            data: 'File 6: Missing non-free use rationale',                            selected: false                        }), { label: 'F6 - Missing non-free use rationale', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F7',                            data: 'File 7: Invalid fair-use claim',                            selected: false                        }), { label: 'F7 - Invalid fair-use claim', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F8',                            data: 'File 8: Images available as identical copies on Wikimedia Commons',                            selected: false                        }), { label: 'F8 - Images available as identical copies on Wikimedia Commons', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F9',                            data: 'File 9: Unambiguous copyright infringement',                            selected: false                        }), { label: 'F9 - Unambiguous copyright infringement', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F10',                            data: 'File 10: Useless non-media files',                            selected: false                        }), { label: 'F10 - Useless non-media files', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'F11',                            data: 'File 11: No evidence of permission',                            selected: false                        }), { label: 'F11 - No evidence of permission', align: 'inline' }),                   ]);                    break; case 14: NameSpaceDeletionReasons = new OO.ui.FieldsetLayout({                       label: 'Categories'                    }); NameSpaceDeletionReasons.addItems([                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'C1',                            data: 'C1: Empty category',                            selected: false                        }), { label: 'C1 - Empty category', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'C2',                            data: 'C2: Speedy renaming',                            selected: false                        }), { label: 'C2 - Speedy renaming', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'G8',                            data: 'G8: Populated by deleted or retargeted template',                            selected: false                        }), { label: 'G8 - Populated by deleted or retargeted template', align: 'inline' }),                   ]);                    break; case 2: case 3: NameSpaceDeletionReasons = new OO.ui.FieldsetLayout({                       label: 'User Pages'                    }); NameSpaceDeletionReasons.addItems([                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'U1',                            data: 'U1: User request to delete page in own userspace',                            selected: false                        }), { label: 'U1 - User request to delete page in own userspace', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'U2',                            data: 'U2: Userpage or subpage of a nonexistent user',                            selected: false                        }), { label: 'U2 - Userpage or subpage of a nonexistent user', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'U3',                            data: 'U3: Non-free gallery',                            selected: false                        }), { label: 'U3 - Non-free gallery', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'U5',                            data: 'U5: Misuse of Wikipedia as a web host',                            selected: false                        }), { label: 'U5 - Misuse of Wikipedia as a web host', align: 'inline' }),                   ]);                    break; case 10: NameSpaceDeletionReasons = new OO.ui.FieldsetLayout({                       label: 'Templates'                    }); NameSpaceDeletionReasons.addItems([                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'T1',                            data: 'Template 1: Divisive and inflammatory templates',                            selected: false                        }), { label: 'T1 - BDivisive and inflammatory templates', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'T2',                            data: 'Template 2: Misrepresentation of policy',                            selected: false                        }), { label: 'T2 - Misrepresentation of policy', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'T3',                            data: 'Template 3: Duplication and hardcoded instances',                            selected: false                        }), { label: 'T3 - Duplication and hardcoded instances', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'T4',                            data: 'Template 4: Subpages of non-existent pages',                            selected: false                        }), { label: 'T4 - Subpages of non-existent pages', align: 'inline' }),                   ]);                    break; case 100: NameSpaceDeletionReasons = new OO.ui.FieldsetLayout({                       label: 'Portals'                    }); NameSpaceDeletionReasons.addItems([                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'P1',                            data: 'WP:CSD: Any portal that would be subject to speedy deletion as an article',                            selected: false                        }), { label: 'P1 - Portal page that does not meet the article criteria', align: 'inline' }),                       new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                            value: 'P2',                            data: 'WP:CSD: Underpopulated portal',                            selected: false                        }), { label: 'P2 - Underpopulated portal', align: 'inline' }),                   ]);                    break; default: NameSpaceDeletionReasons = new OO.ui.FieldsetLayout({}); NameSpaceDeletionReasons.addItems([                       new OO.ui.FieldLayout(new OO.ui.MessageWidget({                            type: 'warning',                            inline: true,                            label: new OO.ui.HtmlSnippet(' There is no speedy delete rationale for this namespace. please select one of the general rationales on the right. ')                       })),                    ]);                    break; }           GeneralReasons = new OO.ui.FieldsetLayout({                label: 'General reasons'            }); GeneralReasons.addItems([               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G1',                    data: 'G1: Patent nonsense, meaningless, or incomprehensible',                    selected: false                }), { label: 'G1 - Patent nonsense', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G2',                    data: 'G2: Test page',                    selected: false                }), { label: 'G2 - Test page', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G3',                    data: 'G3: Vandalism',                    selected: false                }), { label: 'G3 - Pure vandalism', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G3',                    data: 'G3: Blatant hoax',                    selected: false                }), { label: 'G3 - Blatant hoax', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G4',                    data: 'G4: Recreation of a page that was deleted per a deletion discussion',                    selected: false                }), { label: 'G4 - Recreation of material deleted via a deletion discussion', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G5',                    data: 'G5: Creation by a blocked or banned user in violation of block or ban',                    selected: false                }), { label: 'G5 - Created by a banned or blocked user', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G6',                    data: 'G6: Housekeeping and routine (non-controversial) cleanup',                    selected: false                }), { label: 'G6 - Cleanup', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G7',                    data: 'G7: One author who has requested deletion',                    selected: false                }), { label: 'G7 - Author requests deletion, or author blanked', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G8',                    data: 'G8: Page dependent on a deleted or nonexistent page',                    selected: false                }), { label: 'G8 - Pages dependent on a non-existent or deleted page', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'attack',                    data: 'G10: Attack page or negative unsourced BLP',                    selected: false                }), { label: 'G10 - Attack page', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'negublp',                    data: 'G10: Attack page or negative unsourced BLP',                    selected: false                }), { label: 'G10 - Wholly negative, unsourced BLP', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G11',                    data: 'G11: Unambiguous advertising or promotion',                    selected: false                }), { label: 'G11 - Unambiguous advertising or promotion', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G12',                    data: 'G12: Unambiguous copyright infringement',                    selected: false                }), { label: 'G12 - Unambiguous copyright infringement', align: 'inline', }),               copyVioField = new OO.ui.FieldLayout(copyVioInput = new OO.ui.TextInputWidget({                    placeholder: 'Violated URL',                    value: '',                    data: 'COV',                    classes: ['adiutor-copvio-input'],                }), { label: 'URL', align: 'inline', classes: ['adiutor-copvio-container'], }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G13',                    data: 'G13: Abandoned draft or Articles for Creation submission – to retrieve it, see WP:REFUND/G13',                    selected: false                }), { label: 'G13 - Abandoned draft', align: 'inline', }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    value: 'G14',                    data: 'G14: Unnecessary disambiguation page',                    selected: false                }), { label: 'G14 - Unnecessary disambiguation page', align: 'inline', }),           ]);            copyVioField.$element.hide; copyVioInput.$element.hide; isCopyVio = false; GeneralReasons.$element.on('click', function(item) {               if (item.target.value === 'G12') {                    copyVioField.$element.show;                    copyVioInput.$element.show;                }            }); //copyVioInput.on('change', function {           //    console.log(copyVioInput.value);            //}); DeletionOptions = new OO.ui.FieldsetLayout({               label: 'Other Options'            }); DeletionOptions.addItems([               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    selected: false,                    value: 'recreationProrection'                }), { label: 'Add Protection for Re-creation', align: 'inline' }),               new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({                    selected: csdSendMessageToCreator,                    value: 'informCreator'                }), { label: 'Notify Initial Contributor', align: 'inline' })           ]);            HeaderBar = new OO.ui.MessageWidget({                type: 'notice',                inline: true,                label: new OO.ui.HtmlSnippet(' Choose criteria for speedy deletion Please choose one of the criteria below as a reason for deleting this page. ')           });            var left_panel = new OO.ui.PanelLayout({                $content: [NameSpaceDeletionReasons.$element, DeletionOptions.$element],                classes: ['one'],                scrollable: false,            }); var right_panel = new OO.ui.PanelLayout({               $content: GeneralReasons.$element,                classes: ['two'],                scrollable: false,            }); var stack = new OO.ui.StackLayout({               items: [left_panel, right_panel],                continuous: true,                classes: ['adiutor-csd-modal-container']            }); this.panel1 = new OO.ui.PanelLayout({               padded: true,                expanded: false            }); if (revDelCount >= "1") { HeaderBarRevDel = new OO.ui.MessageWidget({                   type: 'warning',                    label: new OO.ui.HtmlSnippet('This page has been deleted ' + revDelCount + ' times before! (Log)')               }); this.panel1.$element.append(HeaderBar.$element, ' ', HeaderBarRevDel.$element, ' ', stack.$element); } else { this.panel1.$element.append(HeaderBar.$element, ' ', stack.$element); }           this.panel2 = new OO.ui.PanelLayout({                padded: true,                expanded: false            }); this.panel2.$element.append(' Adiutor, It is a gadget developed to provide convenience to users in various operations. You can provide all your feedback, including bug reports and feature suggestions, on its talk page. Licensing and attribution Firstly published at,\ https://tr.wikipedia.org/wiki/MediaWiki:Gadget-Adiutor.js Licensed under Creative Commons Attribution-ShareAlike 3.0 Unported License (CC BY-SA 3.0) https://creativecommons.org/licenses/by-sa/3.0/ and GNU Free Documentation License (GFDL) http://www.gnu.org/copyleft/fdl.html. '); this.stackLayout = new OO.ui.StackLayout({               items: [this.panel1, this.panel2]            }); this.$body.append(this.stackLayout.$element); };       // Set up the initial mode of the window ('edit', in this example.) ProcessDialog.prototype.getSetupProcess = function(data) { return ProcessDialog.super.prototype.getSetupProcess.call(this, data).next(function {               this.actions.setMode('edit');            }, this); };       // Use the getActionProcess method to set the modes and displayed item. ProcessDialog.prototype.getActionProcess = function(action) { if (action === 'help') { // Set the mode to help. this.actions.setMode('help'); // Show the help panel. this.stackLayout.setItem(this.panel2); } else if (action === 'back') { // Set the mode to edit. this.actions.setMode('edit'); // Show the edit panel. this.stackLayout.setItem(this.panel1); } else if (action === 'continue') { var dialog = this; return new OO.ui.Process(function {                   var CSDReason;                    var CSDSummary;                    var CSDReasons = [];                    var CSDOptions = [];                    NameSpaceDeletionReasons.items.forEach(function(Reason) { if (Reason.fieldWidget.selected) { CSDReasons.push({                               value: Reason.fieldWidget.value,                                data: Reason.fieldWidget.data,                                selected: Reason.fieldWidget.selected                            }); }                   });                    GeneralReasons.items.forEach(function(Reason) { if (Reason.fieldWidget.selected) { CSDReasons.push({                               value: Reason.fieldWidget.value,                                data: Reason.fieldWidget.data,                                selected: Reason.fieldWidget.selected                            }); }                   });                    var SaltCSDSummary = ;                    if (copyVioInput.value != "") {                        CopVioURL = '|url=' + copyVioInput.value;                    } else {                        CopVioURL = "";                    }                    if (CSDReasons.length > 1) {                        var SaltCSDReason = ;                        CSDSummary = 'XXXX ' + SaltCSDSummary + ' YYYY Multiple.';                    } else {                        CSDReason = '';                        CSDSummary = 'Speedy deletion requested for page, the reason: ' + CSDReasons[0].data + '.';                        SaltCSDSummary = CSDReasons[0].data;                    }                    //Invoke the adding template function                    DeletionOptions.items.forEach(function(Option) { if (Option.fieldWidget.selected) { CSDOptions.push({                               value: Option.fieldWidget.value,                                selected: Option.fieldWidget.selected                            }); }                   });                    CSDOptions.forEach(function(Option) { if (Option.value === "recreationProrection") { CSDReason = CSDReason + "\n" + ''; }                       if (Option.value === "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);                                }                            }); }                   });                    putCSDTemplate(CSDReason, CSDSummary);                    showProgress;                    dialog.close;                }); }           return ProcessDialog.super.prototype.getActionProcess.call(this, action); };       // Get dialog height. ProcessDialog.prototype.getBodyHeight = function { return this.panel1.$element.outerHeight(true); };       // Create and append the window manager. var windowManager = new OO.ui.WindowManager; $(document.body).append(windowManager.$element); // Create a new dialog window. var processDialog = new ProcessDialog({           size: 'larger'        }); // Add windows to window manager using the addWindows method. windowManager.addWindows([processDialog]); // Open the window. windowManager.openWindow(processDialog);

function putCSDTemplate(CSDReason, CSDSummary) { api.postWithToken('csrf', {               action: 'edit',                title: mwConfig.wgPageName,                prependtext: CSDReason + "\n",                summary: CSDSummary,                //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: 'Speedy deletion requested for page ' +  + mwConfig.wgPageName.replace(/_/g, " ") + ,                //tags: 'Adiutor',                format: 'json'            }).done(function {}); }

function showProgress { var processStartedDialog = new OO.ui.MessageDialog; var progressBar = new OO.ui.ProgressBarWidget; var windowManager = new OO.ui.WindowManager; $(document.body).append(windowManager.$element); windowManager.addWindows([processStartedDialog]); windowManager.openWindow(processStartedDialog, {               title: 'The request is in progress',                message: progressBar.$element            }); }   }); }); /* */