User:Doğu/Adiutor-PRD.js
Appearance
(Redirected from User:Doǵu/Adiutor-PRD.js)
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. |
Documentation for this user script can be added at User:Doğu/Adiutor-PRD. |
/*
* Adiutor: A gadget to assist various user actions
* Author: Vikipolimer
* Translation: Kadı
* Licencing and attribution: [[WP:Adiutor#Licencing and attribution]]
* Module: Proposed deletion
*/
/* <nowiki> */
$.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('<strong>Proposed deletion (PROD)</strong><br><small>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.</small>')
});
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#Proposed_deletion_of_biographies_of_living_people]]',
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, '<br><hr><br>', 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 = '{{Proposed deletion/dated |concern = ' + rationaleInput.value + ' |timestamp = ' + new Date().valueOf() + ' |nom = ' + mwConfig.wgUserName + ' |help = off }}';
PRDSummary = 'Proposing article for deletion per [[WP:PROD]]';
}
if (Option.value === "LivingPersonPropose") {
PRDText = '{{Prod blp/dated | concern = | user = | timestamp = ' + new Date().valueOf() + ' | help = off }}';
PRDText = '{{subst:Proposed deletion notify|Living person biography with no references.|help=close}}';
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 = '{{subst:Proposed deletion notify|' + mwConfig.wgPageName.replace(/_/g, " ") + '|concern=' + rationaleInput.value + '|nowelcome=yes}}';
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'
});
}
});
/* </nowiki> */