MediaWiki:Gadget-Adiutor-RPP.js
Eʼtibor bering: Oʻzgartirishlaringizni koʻrish uchun, yangi moslamalaringizning saqlashdan keyin, brauzer keshini tozalash kerak:
Mozilla / Firefox: Ctrl+Shift+R, IE: Ctrl+F5, Safari: Cmd+Shift+R, Konqueror: F5, Opera: Tools → Preferences orqali keshni tozalang.
/*
* Adiutor: A gadget to assist various user actions
* Author: User:Vikipolimer
* Licencing and attribution: [[:tr:VP:Adiutor#Lisanslama ve atıf]]
* Module: Requests for page protection
/* <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 RPPText, RPPSummary, RPPData, RPPDuration;
function PageProtectionDialog(config) {
PageProtectionDialog.super.call(this, config);
}
OO.inheritClass(PageProtectionDialog, OO.ui.ProcessDialog);
PageProtectionDialog.static.name = 'PageProtectionDialog';
PageProtectionDialog.static.title = 'Adiutor — SHS';
PageProtectionDialog.static.actions = [{
action: 'save',
label: 'Bajarish',
flags: ['primary', 'progressive']
}, {
label: 'Yopish',
flags: 'safe'
}];
PageProtectionDialog.prototype.initialize = function() {
PageProtectionDialog.super.prototype.initialize.apply(this, arguments);
var headerTitle = new OO.ui.MessageWidget({
type: 'notice',
inline: true,
label: new OO.ui.HtmlSnippet('<strong>Sahifani himoyalashga soʻrov</strong><br><small>Quyida sahifani qancha muddatga va nima sababdan himoyalash kerakligini bayon eting.</small>')
});
TypeOfAction = new OO.ui.FieldsetLayout({
label: 'Opsiyalar'
});
TypeOfAction.addItems([
DurationOfProtection = new OO.ui.DropdownWidget({
menu: {
items: [
new OO.ui.MenuOptionWidget({
data: 'Vaqtinchalik muddatga',
label: 'Vaqtinchalik'
}),
new OO.ui.MenuOptionWidget({
data: 'Cheksiz muddatga',
label: 'Cheksiz'
}),
]
},
label: "Muddat"
}),
TypeOfProtection = new OO.ui.DropdownWidget({
menu: {
items: [
new OO.ui.MenuOptionWidget({
data: "toʻliq himoya",
label: 'Toʻliq himoya'
}),
new OO.ui.MenuOptionWidget({
data: "yarim himoya",
label: 'Yarim himoya'
}),
]
},
label: "Himoya turi"
}),
rationaleField = new OO.ui.FieldLayout(rationaleInput = new OO.ui.MultilineTextInputWidget({
placeholder: 'Bu yerda sahifani nima uchun himoyalash kerakligi sabab(lar)ini bayon eting.',
indicator: 'required',
value: '',
}), {
label: 'Sababi',
align: 'inline',
}),
]);
rationaleInput.on('change', function() {
if (rationaleInput.value != "") {
InputFilled = false;
} else {
InputFilled = true;
}
});
TypeOfProtection.getMenu().on('choose', function(menuOption) {
RPPData = menuOption.getData();
});
DurationOfProtection.getMenu().on('choose', function(duration) {
RPPDuration = duration.getData();
});
this.content = new OO.ui.PanelLayout({
padded: true,
expanded: false
});
this.content.$element.append(headerTitle.$element, '<br><hr><br>', TypeOfAction.$element);
this.$body.append(this.content.$element);
};
PageProtectionDialog.prototype.getActionProcess = function(action) {
var dialog = this;
if (action) {
return new OO.ui.Process(function() {
RPPText = '\n{{subst:SHS|sahifa_nomi=' + mwConfig.wgPageName.replace(/_/g, " ") + '|turi= ' + RPPDuration + ' ' + RPPData + '|sababi= ' + rationaleInput.value + '~~~~' + '}}';
RPPSummary = '[[' + mwConfig.wgPageName.replace(/_/g, " ") + ']] sahifasini himoyalashga soʻrov qoldirildi';
console.log(RPPText);
addProtectionRequests(RPPText);
dialog.close({
action: action
});
});
}
return PageProtectionDialog.super.prototype.getActionProcess.call(this, action);
};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
var dialog = new PageProtectionDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
function addProtectionRequests(RPPText) {
api.postWithToken('csrf', {
action: 'edit',
title: 'Vikipediya:Sahifani himoyalashga soʻrovlar',
section: 1,
appendtext: RPPText + "\n",
summary: RPPSummary,
tags: 'Adiutor',
format: 'json'
}).done(function() {
window.location = '/wiki/Vikipediya:Sahifani himoyalashga soʻrovlar';
});
}
});
/* </nowiki> */