Медијавики:Gadget-Adiutor-WRN.js — разлика између измена
Изглед
Садржај обрисан Садржај додат
Fixed |
Нема описа измене ознака: враћена измена |
||
Ред 80: | Ред 80: | ||
switch(menuOption.getData()) { |
switch(menuOption.getData()) { |
||
case 1: |
case 1: |
||
warningTemplate = " |
warningTemplate = "{{Упозорење1}}"; |
||
break; |
break; |
||
case 2: |
case 2: |
||
warningTemplate = " |
warningTemplate = "{{Упозорење2}}"; |
||
break; |
break; |
||
} |
} |
Верзија на датум 3. септембар 2023. у 19:48
/*
* Adiutor: Adiutor enables versatile editing options and modules to assist a variety of user actions to enhance the Wikipedia editing experience.
* Author: Vikipolimer
* Learn more at: https://meta.wikimedia.org/wiki/Adiutor
* Licensing and Attribution: Licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
* Module: User warning
*/
/* <nowiki> */
// Get essential configuration from MediaWiki
var mwConfig = mw.config.get(["skin", "wgAction", "wgArticleId", "wgPageName", "wgNamespaceNumber", "wgTitle", "wgUserGroups", "wgUserName", "wgUserEditCount", "wgUserRegistration", "wgCanonicalNamespace"]);
var api = new mw.Api();
var adiutorUserOptions = JSON.parse(mw.user.options.get('userjs-adiutor'));
var RequestRationale, warningTemplate;
function UserWarningDialog(config) {
UserWarningDialog.super.call(this, config);
}
OO.inheritClass(UserWarningDialog, OO.ui.ProcessDialog);
UserWarningDialog.static.name = 'UserWarningDialog';
UserWarningDialog.static.title = new OO.ui.deferMsg('wrn-module-title');
UserWarningDialog.static.actions = [{
action: 'save',
label: new OO.ui.deferMsg('warn'),
flags: ['primary', 'progressive']
}, {
label: new OO.ui.deferMsg('cancel'),
flags: 'safe'
}];
UserWarningDialog.prototype.initialize = function() {
UserWarningDialog.super.prototype.initialize.apply(this, arguments);
var headerTitle = new OO.ui.MessageWidget({
type: 'notice',
inline: true,
label: new OO.ui.deferMsg('wrn-dialog-description')
});
headerTitle.$element.css('margin-top', '20px');
var RationaleSelector = new OO.ui.DropdownWidget({
menu: {
items: [
new OO.ui.MenuOptionWidget({
data: 1,
label: 'Vandalism'
}),
new OO.ui.MenuOptionWidget({
data: 2,
label: '...'
})
]
},
label: new OO.ui.deferMsg('warning-type'),
});
RationaleSelector.$element.css('margin-top', '20px');
relatedPageField = new OO.ui.FieldLayout(relatedPage = new OO.ui.TextInputWidget({
value: ''
}), {
label: new OO.ui.deferMsg('related-page'),
help: new OO.ui.deferMsg('wrn-related-page-help')
}),
this.content = new OO.ui.PanelLayout({
padded: true,
expanded: false
});
warningLevel = new OO.ui.RadioSelectInputWidget({
options: [{
data: 1,
label: new OO.ui.deferMsg('wrn-user-mildly'),
}, {
data: 2,
label: new OO.ui.deferMsg('wrn-user-seriously'),
}, {
data: 3,
label: new OO.ui.deferMsg('wrn-user-sternly'),
}, ]
});
relatedPageField.$element.css({
'margin-top': '20px',
'margin-bottom': '20px'
});
RationaleSelector.getMenu().on('choose', function(menuOption) {
switch(menuOption.getData()) {
case 1:
warningTemplate = "{{Упозорење1}}";
break;
case 2:
warningTemplate = "{{Упозорење2}}";
break;
}
});
this.content.$element.append(headerTitle.$element, RationaleSelector.$element, relatedPageField.$element, warningLevel.$element);
this.$body.append(this.content.$element);
};
UserWarningDialog.prototype.getActionProcess = function(action) {
var dialog = this;
if(action) {
return new OO.ui.Process(function() {
warnUser(warningTemplate);
dialog.close({
action: action
});
});
}
return UserWarningDialog.super.prototype.getActionProcess.call(this, action);
};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
var dialog = new UserWarningDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
function warnUser(warningTemplate) {
api.postWithEditToken({
action: 'edit',
title: 'Разговор_с_корисником:' + mwConfig.wgPageName.replace(/_/g, " ").replace('Корисник:', '').replace('Посебно:Доприноси/', '').replace('Разговор с корисником:', ''),
appendtext: "\n{{subst:"+warningTemplate+warningLevel.getValue()+"|"+relatedPage.value+"}}" + "\n",
summary: 'Korisnik je upozoren.',
tags: 'Adiutor',
watchlist: 'unwatch',
format: 'json'
}).done(function() {
window.location = '/wiki/' + 'Разговор с корисником:' + mwConfig.wgPageName.replace(/_/g, " ").replace('Корисник:', '').replace('Посебно:Доприноси/', '').replace('Разговор с корисником:', '');
adiutorUserOptions.stats.userWarnings++;
api.postWithEditToken({
action: 'globalpreferences',
format: 'json',
optionname: 'userjs-adiutor',
optionvalue: JSON.stringify(adiutorUserOptions),
formatversion: 2,
}).done(function() {});
});
}
/* </nowiki> */