MediaWiki:Gadget-Adiutor-AFD-Helper.js
Qiyofa
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: Vikipolimer
* Licencing and attribution: [[:tr:VP:Adiutor#Lisanslama ve atıf]]
* Module: Article for 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"]);
var api = new mw.Api();
// Check if on a non-existent article/file/portal (to unlink backlinks)
var isNonexistentPage = mw.config.get("wgArticleId") === 0;
var isUnlinkableNamespace = [0, 1, 2, 3, 5, 6, 7, 14, 10, 11, 100, 101, 102, 103, 828, 829].indexOf(mw.config.get("wgNamespaceNumber")) !== -1;
var isUnlinkablePage = isNonexistentPage && isUnlinkableNamespace;
var afdNominateOpinionsLog = localStorage.getItem("afdNominateOpinionsLog") == "true";
// Check for edit, history, diff, or oldid mode
if(!isUnlinkablePage && /(?:\?|&)(?:action|diff|oldid)=/.test(window.location.href)) {
return;
}
// Check if on an afd page
var afdpage_regex = /(Oʻchirishga)/;
var isafdPage = afdpage_regex.test(mwConfig.wgPageName);
var subPageRegex = /(Oʻchirishga\/)/;
var isSubPage = subPageRegex.test(mwConfig.wgPageName);
// Load for afd pages as well as unlinkable pages
var shouldLoadScript = isafdPage || isUnlinkablePage;
if(!shouldLoadScript) {
return;
}
var afdButtons, previewWikitext, firstMonthOfDateString, firstDateMatch, opinionTemplate, nominationPage, purePageName, pageName, AfD_page, header_warn;
AfD_page = "Vikipediya:Oʻchirishga/";
if(mwConfig.wgUserGroups.includes("sysop")) {
if(isSubPage) {
afdButtons = new OO.ui.ButtonGroupWidget({
items: [new OO.ui.ButtonWidget({
icon: 'speechBubbleAdd',
label: 'Fikr bildirish',
invisibleLabel: true,
title: 'Fikr bildirish',
classes: ['afd-helper-button']
}), new OO.ui.ButtonWidget({
icon: 'editLock',
invisibleLabel: true,
classes: ['afd-closer-button']
})],
classes: ['afd-helper-button-group']
});
} else {
afdButtons = new OO.ui.ButtonGroupWidget({
items: [new OO.ui.ButtonWidget({
icon: 'eye',
label: 'Nomzod',
invisibleLabel: true,
classes: ['afd-helper-visit-button']
}), new OO.ui.ButtonWidget({
icon: 'speechBubbleAdd',
label: 'Fikr bildirish',
invisibleLabel: true,
title: 'Fikr bildirish',
classes: ['afd-helper-button']
}), new OO.ui.ButtonWidget({
icon: 'editLock',
invisibleLabel: true,
classes: ['afd-closer-button']
})],
classes: ['afd-helper-button-group']
});
}
} else {
if(isSubPage) {
afdButtons = new OO.ui.ButtonGroupWidget({
items: [new OO.ui.ButtonWidget({
icon: 'speechBubbleAdd',
label: 'Fikr bildirish',
invisibleLabel: true,
title: 'Fikr bildirish',
classes: ['afd-helper-button']
})],
classes: ['afd-helper-button-group']
});
} else {
afdButtons = new OO.ui.ButtonGroupWidget({
items: [new OO.ui.ButtonWidget({
icon: 'eye',
label: 'Nomzod',
invisibleLabel: true,
classes: ['afd-helper-visit-button']
}), new OO.ui.ButtonWidget({
icon: 'speechBubbleAdd',
label: 'Fikr bildirish',
invisibleLabel: true,
title: 'Fikr bildirish',
classes: ['afd-helper-button']
}), ],
classes: ['afd-helper-button-group']
});
}
}
$('.afd-helper-button').each(function(index) {
this.id = "opinion" + (index + 1);
});
$('.afd-helper-button').children().each(function(index) {
this.id = "opinion" + (index + 1);
});
$('.afd-helper-visit-button').each(function(index) {
this.id = "opinion" + (index + 1);
});
$('.afd-helper-visit-button').children().each(function(index) {
this.id = "opinion" + (index + 1);
});
$('.mw-headline').append(afdButtons.$element);
$(".afd-helper-button").children().click(function() {
pageName = $(this).parent().parent().parent()[0].innerText.replace('Fikr bildirish', '').replace('Nomzod', '');
purePageName = pageName.replace($(this).parent().parent().parent()[0], '').replace('Fikr bildirish', '');
PageTitleElement = $(this).parent().parent().parent().parent()[0].lastElementChild;
nominationPage = clearURLfromOrigin(PageTitleElement.querySelector(".mw-editsection a").getAttribute('href'));
afdOpinionDialog(purePageName);
});
$(".afd-closer-button").children().click(function() {
pageName = $(this).parent().parent().parent()[0].innerText.replace('Fikr bildirish', '').replace('Nomzod', '');
purePageName = pageName.replace($(this).parent().parent().parent()[0], '').replace('Fikr bildirish', '');
PageTitleElement = $(this).parent().parent().parent().parent()[0].lastElementChild;
nominationPage = clearURLfromOrigin(PageTitleElement.querySelector(".mw-editsection a").getAttribute('href'));
var pageContentWithDate;
if(isSubPage) {
pageContentWithDate = $(this).parent().parent().parent().parent().parent()[0].innerText;
discussionText = $(this).parent().parent().parent().parent().parent()[0].innerText;
firstDateMatch = /\d{1,2} ([a-zA-ZoʻgʻʼOʻGʻ]*) \d{4}/i.exec(discussionText);
firstMonthOfDateString = firstDateMatch && firstDateMatch[1];
} else {
pageContentWithDate = $(this).parent().parent().parent().parent().next()[0].innerText;
discussionText = $(this).parent().parent().parent().parent().next().next()[0].innerText;
firstDateMatch = /\d{1,2} ([a-zA-ZoʻgʻʼOʻGʻ]*) \d{4}/i.exec(discussionText);
firstMonthOfDateString = firstDateMatch && firstDateMatch[1];
}
var timeExpired = pageContentWithDate.includes("Tartışma için öngörülen süre dolmuştur");
afdCloserDialog(purePageName, timeExpired);
});
$(".afd-helper-visit-button").children().click(function() {
PageTitleElement = $(this).parent().parent().parent().parent()[0].lastElementChild;
nominationPage = clearURLfromOrigin(PageTitleElement.querySelector(".mw-editsection a").getAttribute('href'));
window.location = '/wiki/' + nominationPage;
});
//var boxes = document.getElementsByClassName('mw-parser-output');
//var headings = boxes[0].getElementsByTagName('h2');
//len = headings !== null ? headings.length : 0, i = 0;
//for (var i; i < len; i++) {
// headings[i].className += " hide-non-opinion";
//}
//$(".hide-non-opinion .afd-helper-button-group").hide();
$(".ext-discussiontools-init-section .afd-helper-button-group").hide();
$(".xfd-closed .afd-helper-button-group").hide();
function afdOpinionDialog(purePageName) {
var InputFilled = false;
console.log(InputFilled);
var rationaleInput = new OO.ui.MultilineTextInputWidget({
placeholder: 'Iltimos, bu yerda fikringizni bayon eting.',
indicator: 'required',
notices: ['Iltimos, fikringizni qoldiring.'],
classes: ['afd-helper-comment-textarea']
});
rationaleInput.on('change', function() {
console.log(rationaleInput.value);
if(rationaleInput.value != "") {
InputFilled = false;
console.log(InputFilled);
} else {
InputFilled = true;
console.log(InputFilled);
}
});
log_it = new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
selected: localStorage.getItem("afdNominateOpinionsLog") == "true"
}), {
align: 'inline',
label: 'Qoldirgan fikrlarim qaydlari olib borilsin\u200e',
});
var header_warn = new OO.ui.MessageWidget({
type: 'notice',
inline: true,
label: new OO.ui.HtmlSnippet('Oʻchirishga nomzod sahifalar ovoz berish uchun sahifalar emas!<br>Shunday ekan, shunchaki andozani qoldirmay, fikringizni ham bildiring.<br><small>Oʻchirishga nomzod sahifalarda qarorlar fikrlar soniga qarab emas, balki Vikipediya qoida va koʻrsatmalariga binoan chiqariladi.</small>')
});
var page_url = '<a href="'.concat(purePageName.trim(), '" target="_blank">').concat(purePageName.trim(), "</a>");
var page_link = page_url.replace(/<(\/?pre\s?\/?)>/g, " ");
var page_name = new OO.ui.MessageWidget({
type: 'notice',
icon: 'article',
label: '',
classes: ['afd-helper-page-name']
});
function opinionDialog(config, buttonSelect) {
opinionDialog.super.call(this, config, buttonSelect);
}
OO.inheritClass(opinionDialog, OO.ui.ProcessDialog);
opinionDialog.static.title = 'Adiutor —— Oʻchirishga nomzod sahifalarda fikr qoldirish';
opinionDialog.static.name = 'opinionDialog';
opinionDialog.static.actions = [{
action: 'continue',
modes: 'edit,preview',
label: 'Qoʻshilsin',
disabled: InputFilled,
icon: 'add',
flags: ['primary', 'progressive']
}, {
action: 'about',
modes: 'edit,preview',
label: 'Haqida',
icon: 'infoFilled'
}, {
modes: 'edit',
label: 'Yopish',
flags: 'safe',
icon: 'close'
}, {
action: 'back',
modes: 'about,preview',
label: 'Orqaga',
flags: 'safe'
}, {
action: 'preview',
modes: 'edit,preview',
label: 'Oldindan koʻrib chiqish',
icon: 'eye',
align: 'right'
}];
opinionDialog.prototype.initialize = function() {
opinionDialog.super.prototype.initialize.apply(this, arguments);
buttonSelect = new OO.ui.ButtonSelectWidget({
items: [new OO.ui.ButtonOptionWidget({
id: 1,
data: 1,
label: 'Qoldirilsin',
title: 'Qoldirilsin',
classes: ['afd-opinion-select-btn']
}), new OO.ui.ButtonOptionWidget({
id: 3,
data: 3,
label: 'Oʻchirilsin',
title: 'Oʻchirilsin',
classes: ['afd-opinion-select-btn']
}), ],
classes: ['afd-opinion-select-btn-group']
});
buttonSelect.on('select', (function() {
localStorage.setItem("selectedOpinion", buttonSelect.findSelectedItem().data);
switch(buttonSelect.findSelectedItem().data) {
case 1:
opinionTemplate = '*{{Qoldirilsin}}';
break;
case 2:
opinionTemplate = '*{{Tezda qoldirilsin}}';
break;
case 3:
opinionTemplate = '*{{Oʻchirilsin}}';
break;
case 4:
opinionTemplate = '*{{Tezda oʻchirilsin}}';
break;
case 5:
opinionTemplate = '*{{Birlashtirilsin}}';
break;
case 6:
opinionTemplate = '*{{Koʻchirilsin}}';
break;
case 7:
opinionTemplate = '*{{Olib oʻtilsin}}';
break;
}
previewWikitext = opinionTemplate + ' ' + rationaleInput.value + ' ~~~~';
}));
this.panel1 = new OO.ui.PanelLayout({
padded: true,
expanded: false
});
this.panel1.$element.append(header_warn.$element, page_name.$element, '</br>', buttonSelect.$element, '</br>', rationaleInput.$element, log_it.$element);
this.panel2 = new OO.ui.PanelLayout({
padded: true,
expanded: false
});
this.panel2.$element.append('<p><strong>Adiutor</strong></p><h2>Litsenziya</h2><p>Creative Commons Attribution-ShareAlike 3.0 Unported License (CC BY-SA 3.0) https://creativecommons.org/licenses/by-sa/3.0/ va GNU Free Documentation License (GFDL) http://www.gnu.org/copyleft/fdl.html.</p>');
rationaleInput.on('change', function() {
previewWikitext = opinionTemplate + ' ' + rationaleInput.value + ' ~~~~';
console.log(previewWikitext);
});
this.stackLayout = new OO.ui.StackLayout({
items: [this.panel1, this.panel2]
});
this.$body.append(this.stackLayout.$element);
};
opinionDialog.prototype.getSetupProcess = function(data) {
return opinionDialog.super.prototype.getSetupProcess.call(this, data).next(function() {
this.actions.setMode('edit');
}, this);
};
opinionDialog.prototype.getActionProcess = function(action) {
if(action === 'about') {
this.actions.setMode('about');
this.stackLayout.setItem(this.panel2);
} else if(action === 'back') {
this.actions.setMode('edit');
this.stackLayout.setItem(this.panel1);
} else if(action === 'continue') {
var dialog = this;
return new OO.ui.Process(function() {
if(rationaleInput.value != "") {
addOpinion(purePageName, rationaleInput);
dialog.close();
} else {
alertDialog("Fikr bildiring!", "Oʻchirishga nomzod sahifalar ovoz berish uchun sahifalar emas! Oʻchirishga nomzod sahifalarda qarorlar fikrlar soniga qarab emas, balki Vikipediya qoida va koʻrsatmalariga binoan chiqariladi.");
}
});
}
if(action === 'preview') {
api.get({
action: 'parse',
text: previewWikitext,
disablelimitreport: 1,
disabletidy: 1,
prop: 'text',
format: "json"
}).done(function(data) {
function WikiPreviewDialog(config) {
WikiPreviewDialog.super.call(this, config);
}
OO.inheritClass(WikiPreviewDialog, OO.ui.ProcessDialog);
WikiPreviewDialog.static.name = 'WikiPreviewDialog';
WikiPreviewDialog.static.title = 'Önizleme';
WikiPreviewDialog.static.actions = [{
action: 'save',
modes: 'edit,preview',
label: 'Ekle',
disabled: InputFilled,
icon: 'add',
flags: ['primary', 'progressive']
}, {
label: 'Kapat',
flags: 'safe'
}];
WikiPreviewDialog.prototype.initialize = function() {
WikiPreviewDialog.super.prototype.initialize.apply(this, arguments);
this.content = new OO.ui.PanelLayout({
padded: true,
expanded: false
});
this.content.$element.html(data.parse.text['*']);
this.$body.append(this.content.$element);
};
WikiPreviewDialog.prototype.getActionProcess = function(action) {
var dialog = this;
if(action) {
return new OO.ui.Process(function() {
addOpinion(purePageName, rationaleInput);
dialog.close({
action: action
});
});
}
return WikiPreviewDialog.super.prototype.getActionProcess.call(this, action);
};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
var dialog = new WikiPreviewDialog({
size: 'full',
});
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
});
}
return opinionDialog.super.prototype.getActionProcess.call(this, action);
};
opinionDialog.prototype.getBodyHeight = function() {
//return this.panel1.$element.outerHeight(true);
return Math.max(this.panel1.$element.outerHeight(true), 320);
};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
var dialog = new opinionDialog({
size: 'large',
classes: ['afd-helper-window']
});
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
$('.afd-helper-page-name').children().next().append(page_link);
}
function afdCloserDialog(purePageName, timeExpired) {
if(timeExpired) {
header_warn = new OO.ui.MessageWidget({
type: 'notice',
inline: true,
label: new OO.ui.HtmlSnippet('Siz munozarani yopmoqdasiz<br><small>Quyida qarorni bayon eting.</small>')
});
} else {
header_warn = new OO.ui.MessageWidget({
type: 'notice',
inline: true,
label: new OO.ui.HtmlSnippet('Siz munozarani yopmoqdasiz<br><small>Quyida qarorni bayon eting.</small>')
});
}
var page_url = '<a href="wiki/'.concat(purePageName.trim(), '" target="_blank">').concat(purePageName.trim(), "</a>");
var page_link = page_url.replace(/<(\/?pre\s?\/?)>/g, " ");
var page_name = new OO.ui.MessageWidget({
type: 'notice',
icon: 'article',
label: '',
classes: ['afd-helper-page-name']
});
var rationaleInput = new OO.ui.MultilineTextInputWidget({
placeholder: 'Bu yerda nega unday qaror chiqarganingizni bayon eting.',
indicator: 'required',
notices: ['Iltimos, sabab keltiring.'],
classes: ['afd-helper-comment-textarea']
});
rationaleInput.on('change', function() {
console.log(rationaleInput.value);
});
function closerDialog(config) {
closerDialog.super.call(this, config);
}
OO.inheritClass(closerDialog, OO.ui.ProcessDialog);
closerDialog.static.title = 'Adiutor — Oʻchirishga nomzod sahifalarda qaror chiqarish';
closerDialog.static.name = 'closerDialog';
closerDialog.static.actions = [{
action: 'close',
modes: 'edit,preview',
label: 'Qaror chiqarilsin',
icon: 'lock',
flags: ['primary', 'progressive']
}, {
action: 'about',
modes: 'edit,preview',
label: 'Haqida',
icon: 'infoFilled'
}, {
modes: 'edit',
label: 'Yopish',
flags: 'safe',
icon: 'close'
}, {
action: 'back',
modes: 'about,preview',
label: 'Orqaga',
flags: 'safe'
}, ];
closerDialog.prototype.initialize = function() {
closerDialog.super.prototype.initialize.apply(this, arguments);
buttonSelect = new OO.ui.ButtonSelectWidget({
items: [new OO.ui.ButtonOptionWidget({
id: 1,
data: 1,
label: 'Qoldirilsin',
title: 'Qoldirilsin',
classes: ['afd-result-select-btn']
}),
new OO.ui.ButtonOptionWidget({
id: 3,
data: 3,
label: 'Oʻchirilsin',
title: 'Oʻchirilsin',
classes: ['afd-result-select-btn']
}),
],
classes: ['afd-result-select-btn-group']
});
buttonSelect.on('select', (function() {
localStorage.setItem("selectedCloseDesicion", buttonSelect.findSelectedItem().data);
console.log(localStorage.getItem("selectedCloseDesicion"));
}));
var actionOption = new OO.ui.FieldLayout(new OO.ui.CheckboxInputWidget({
selected: true
}), {
align: 'inline',
label: 'Nomzod sahifa ham avtomatik oʻchirilsin\u200e',
help: 'Bunda ushbu sahifa avtomatik oʻchiriladi.\u200e'
});
titleInput = new OO.ui.TextInputWidget({
'showMissing': false,
'align': screenLeft,
'label': 'Maqolani qaysi maqola bilan birlashtirish taklif etildi?',
});
this.panel1 = new OO.ui.PanelLayout({
padded: true,
expanded: false
});
this.panel1.$element.append(header_warn.$element, page_name.$element, '</br>', buttonSelect.$element, '</br>', rationaleInput.$element, actionOption.$element, titleInput.$element);
this.panel2 = new OO.ui.PanelLayout({
padded: true,
expanded: false
});
this.panel2.$element.append('<p><strong>Adiutor</strong> foydalanuvchilarga Vikipediyadagi sahifalarni tezda oʻchirishga/koʻchirishga/oʻchirishga/himoyalashga nomzod sifatida koʻrsatishda koʻmaklashuvchi gadjetdir.</p><h2>Litsenziya</h2><p>Creative Commons Attribution-ShareAlike 3.0 Unported License (CC BY-SA 3.0) https://creativecommons.org/licenses/by-sa/3.0/ va GNU Free Documentation License (GFDL) http://www.gnu.org/copyleft/fdl.html.</p>');
this.stackLayout = new OO.ui.StackLayout({
items: [this.panel1, this.panel2]
});
this.$body.append(this.stackLayout.$element);
};
closerDialog.prototype.getSetupProcess = function(data) {
return closerDialog.super.prototype.getSetupProcess.call(this, data).next(function() {
this.actions.setMode('edit');
}, this);
};
closerDialog.prototype.getActionProcess = function(action) {
if(action === 'preview') {
this.actions.setMode('preview');
this.stackLayout.setItem(this.panel3);
}
if(action === 'about') {
this.actions.setMode('about');
this.stackLayout.setItem(this.panel2);
} else if(action === 'back') {
this.actions.setMode('edit');
this.stackLayout.setItem(this.panel1);
} else if(action === 'close') {
var dialog = this;
return new OO.ui.Process(function() {
closeDiscussion(purePageName, rationaleInput);
dialog.close();
});
}
return closerDialog.super.prototype.getActionProcess.call(this, action);
};
closerDialog.prototype.getBodyHeight = function() {
//return this.panel1.$element.outerHeight(true);
return Math.max(this.panel1.$element.outerHeight(true), 320);
};
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
var dialog = new closerDialog({
size: 'large',
classes: ['afd-helper-window']
});
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
$('.afd-helper-page-name').children().next().append(page_link);
}
// ADD OPINION TO NOMINATION AFD PAGE
function addOpinion(purePageName, rationaleInput) {
var opinion;
var opinionText;
switch(localStorage.getItem("selectedOpinion")) {
case '1':
opinion = "Qoldirilsin";
opinionText = '*{{subst:Qoldirilsin}}' + ' ' + rationaleInput.value + ' ~~~~';
break;
case '3':
opinion = "Oʻchirilsin";
opinionText = '*{{subst:Oʻchirilsin}}' + ' ' + rationaleInput.value + ' ~~~~';
break;
}
api = new mw.Api();
api.postWithToken('csrf', {
action: 'edit',
title: nominationPage,
appendtext: "\n" + opinionText,
summary: 'Fikr-mulohaza qoldirildi',
tags: 'Adiutor',
format: 'json'
}).done(function() {
if(afdNominateOpinionsLog) {
api = new mw.Api();
api.postWithToken('csrf', {
action: 'edit',
title: 'Foydalanuvchi:'.concat(mwConfig.wgUserName, '/' + localStorage.getItem("afdOpinionLogPageName") + '').split(' ').join('_'),
appendtext: "\n" + "* ~~~~~ '''[[" + nominationPage + "|" + purePageName + "]]''' | Fikr: '''" + opinion + "'''",
summary: 'Oʻ qaydlariga qoʻshildi.',
tags: 'Adiutor',
format: 'json'
}).done(function() {});
}
if(isSubPage) {
location.reload();
} else {
var success_notify = new OO.ui.MessageWidget({
type: 'success',
label: 'Fikringizni muvaffaqiyatli qoldirdingiz, uni koʻrish uchun sahifani yangilang.',
classes: ['afd-helper-notification'],
showClose: true
});
$('.mw-page-container-inner').append(success_notify.$element);
setTimeout(function() {
$(".afd-helper-notification").hide('blind', {}, 500);
}, 5000);
}
});
}
// CLOSE DISCUSSION
function closeDiscussion(purePageName, rationaleInput) {
var result;
var closeText;
switch(localStorage.getItem("selectedCloseDesicion")) {
case '1':
result = "Qoldirildi";
closeText = '{{Oʻ usti|qoldirilsin}}' + ' ' + rationaleInput.value + ' ~~~~';
break;
case '3':
result = "Oʻchirildi";
closeText = '{{Oʻ usti|oʻchirilsin}}' + ' ' + rationaleInput.value + ' ~~~~';
break;
case '8':
result = "Qarorsiz";
closeText = '{{Oʻ usti|qarorsiz}}' + ' ' + rationaleInput.value + ' ~~~~';
break;
}
api.postWithToken('csrf', {
action: 'edit',
title: nominationPage,
prependtext: closeText + "\n",
appendtext: "\n{{Oʻ osti}}",
summary: 'Natija',
tags: 'Adiutor',
format: 'json'
}).done(function() {
switch(localStorage.getItem("selectedCloseDesicion")) {
case '1':
removeAfdTemplatesFromnominationPage(purePageName);
break;
case '2':
removeAfdTemplatesFromnominationPage(purePageName);
break;
case '3':
deletenominationPage(purePageName);
break;
case '4':
deletenominationPage(purePageName);
break;
case '5':
removeAfdTemplatesFromnominationPage(purePageName);
break;
case '6':
removeAfdTemplatesFromnominationPage(purePageName);
break;
case '7':
removeAfdTemplatesFromnominationPage(purePageName);
break;
case '8':
removeAfdTemplatesFromnominationPage(purePageName);
break;
case '9':
removeAfdTemplatesFromnominationPage(purePageName);
break;
}
});
}
// REMOVE AFD TEMPLATES FROM NOMINATED PAGE
function removeAfdTemplatesFromnominationPage(purePageName) {
var pageContent;
api.get({
action: 'parse',
page: purePageName.trim(),
prop: 'wikitext',
format: "json"
}).done(function(data) {
pageContent = data.parse.wikitext['*'];
var templatesCleanedPageContent = pageContent.replace(/\{\{\s*?oʻchirishga\s*?(|\|.*?)\}\}\n?/gi, "");
api.postWithToken('csrf', {
action: 'edit',
title: purePageName.trim(),
text: templatesCleanedPageContent,
summary: '[[VP:Oʻchirishga|Oʻchirishga]]: [[' + nominationPage + '|Nomzod sahifasida]] munozara andozasi qoldirildi',
tags: 'Adiutor',
format: 'json'
}).done(function() {
removeNominationFromAfdPage();
});
});
}
// DELETE NOMINATED PAGE
function deletenominationPage(purePageName) {
api.postWithToken('csrf', {
action: 'delete',
title: purePageName.trim(),
reason: '[[VP:Oʻchirishga|OʻCH]]: Sahifa [[' + nominationPage + '|oʻchirishga]] qaror qilindi',
tags: 'Adiutor',
format: 'json'
}).done(function() {
api.postWithToken('csrf', {
action: 'delete',
title: "Munozara:" + purePageName.trim(),
reason: '[[' + nominationPage + '|Mana bu yerdagi]] qarorga binoan',
tags: 'Adiutor',
format: 'json'
}).done(function() {});
removeNominationFromAfdPage();
});
}
// REMOVE NOMINATION FROM AFD PAGE
function removeNominationFromAfdPage() {
api.get({
action: 'parse',
page: "Vikipediya:Oʻchirishga",
prop: 'wikitext',
format: "json"
}).done(function(data) {
api.postWithToken('csrf', {
action: 'edit',
title: "Vikipediya:Oʻchirishga",
text: data.parse.wikitext['*'].replace("{{" + nominationPage.replace(/_/g, " ") + "}}", ""),
summary: '[[VP:Oʻchirishga|OʻCH]]: [[' + nominationPage + '|Arxivlandi]]',
tags: 'Adiutor',
format: 'json'
}).done(function() {
addNominationToAfdLogPage();
});
});
}
// ADD NOMINATION TO AFD LOG PAGE
function addNominationToAfdLogPage() {
var date = new Date();
var date_year = date.getUTCFullYear();
var pageContent;
api.get({
action: 'parse',
page: "Vikipediya:Oʻchirishga/Qaydlar/" + date_year + "-" + firstMonthOfDateString,
prop: 'wikitext',
format: "json"
}).done(function(data) {
pageContent = data.parse.wikitext['*'];
pageNameCleaned = nominationPage.replace(/_/g, " ");
var discusionExistInLog = pageContent.includes("{{" + pageNameCleaned + "}}");
//CHECK IF ALREADY ADDED
if(!discusionExistInLog) {
api.postWithToken('csrf', {
action: 'edit',
title: "Vikipediya:Oʻchirishga/Qaydlar/" + date_year + "-" + firstMonthOfDateString,
appendtext: "\n" + "{{" + pageNameCleaned + "}}",
summary: "Nomzod [[Vikipediya:Oʻchirishga/Qaydlar/" + date_year + "-" + firstMonthOfDateString + "|tegishli qaydlarga]] qoʻshildi.",
tags: 'Adiutor',
format: 'json'
}).done(function() {
if(isSubPage) {
location.reload();
} else {
var success_notify = new OO.ui.MessageWidget({
type: 'success',
label: 'Bajarildi! Oʻzgarishlarni koʻrish uchun sahifani yangilang.',
classes: ['afd-helper-notification'],
showClose: true
});
$('.mw-page-container-inner').append(success_notify.$element);
setTimeout(function() {
$(".afd-helper-notification").hide('blind', {}, 500);
}, 5000);
}
});
} else {
if(isSubPage) {
location.reload();
} else {
var success_notify = new OO.ui.MessageWidget({
type: 'success',
label: 'Bajarildi! Iltimos, sahifani yangilang.',
classes: ['afd-helper-notification'],
showClose: true
});
$('.mw-page-container-inner').append(success_notify.$element);
setTimeout(function() {
$(".afd-helper-notification").hide('blind', {}, 500);
}, 5000);
}
}
switch(localStorage.getItem("selectedCloseDesicion")) {
case '5':
putMergeTemplate(purePageName);
break;
case '7':
putMergeTemplate(purePageName);
break;
}
function putMergeTemplate(purePageName) {
api.postWithToken('csrf', {
action: 'edit',
title: purePageName.trim(),
prependtext: '{{Birlashtirishga|' + nominationPage.replace('Vikipediya:Oʻchirishga/', '') + '|' + titleInput.getValue() + '}}' + "\n",
summary: 'Birlashtirishga andozasi qoʻshildi',
tags: 'Adiutor',
format: 'json'
}).done(function() {});
}
});
}
function clearURLfromOrigin(AfDPageUrl) {
return decodeURIComponent(AfDPageUrl.replace('https://uz.wikipedia.org/w/index.php?title=', '').replace('§ion=1&veaction=editsource', '').replace('/w/index.php?title=', '').replace(/\§ion=T-1&veaction=editsource/g, "").replace(/\&action=edit§ion=1/g, "").replace(/\&action=edit§ion=T-1/g, ""));
}
function alertDialog(title, message) {
var AlertDialog = new OO.ui.MessageDialog();
var windowManager = new OO.ui.WindowManager();
$(document.body).append(windowManager.$element);
windowManager.addWindows([AlertDialog]);
windowManager.openWindow(AlertDialog, {
title: title,
message: message,
});
}
});
/* </nowiki> */