مدیاویکی:Tofawiki.js: تفاوت میان نسخه‌ها

از ویکی‌پدیا، دانشنامهٔ آزاد
محتوای حذف‌شده محتوای افزوده‌شده
ساده‌سازی محل اعمال عنوان پیشنهادی
تمیزکاری
خط ۱۱۳: خط ۱۱۳:
}
}


// Limiting oojs-ui windowing things to this place is intentional
// so that we can switch to something else easily later.
function createDialog(dialogContent, onCloseAction) {
function TranslationDialog(config) {
TranslationDialog.super.call(this, config);
}
OO.inheritClass(TranslationDialog, OO.ui.ProcessDialog);
TranslationDialog.static.name = 'toFaWikiDialog';
TranslationDialog.static.title = 'ایجاد در ویکی‌پدیای فارسی';
// TODO: This should be done by the caller
TranslationDialog.static.actions = [
{ action: 'cx', label: 'ایجاد به کمک ترجمهٔ محتوا' },
{
action: 'tofawiki',
label: namespaceNumber === 6 ? 'بارگذاری' : 'ایجاد به کمک ابزار توفاویکی'
},
{ label: 'بستن', flags: 'safe' }
];
if (namespaceNumber !== 0) {
// remove CX for namespaces other than the main one
TranslationDialog.static.actions.splice(0, 1);
}
TranslationDialog.prototype.initialize = function () {
TranslationDialog.super.prototype.initialize.apply(this, arguments);
this.content = new OO.ui.PanelLayout({ padded: true, expanded: false });
this.content.$element.append(dialogContent);
this.$body.append(this.content.$element);
};
TranslationDialog.prototype.getActionProcess = function (action) {
var dialog = this;
if (action) {
return new OO.ui.Process(function () {
onCloseAction(action);
dialog.close({ action: action });
})
} else {
return TranslationDialog.super.prototype.getActionProcess.call(this, action);
}
};
var windowManager = new OO.ui.WindowManager();
windowManager.$element.addClass('tofawiki-dialog');
$(document.body).append(windowManager.$element);
var dialog = new TranslationDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
}
$(function () {
$(function () {
if ($('.interlanguage-link.interwiki-fa').length !== 0) { return; }
if ($('.interlanguage-link.interwiki-fa').length !== 0) { return; }
خط ۱۴۴: خط ۱۹۱:
}), ' ');
}), ' ');
return;
return;
}

// Limiting oojs-ui windowing things to this place is intentional
// so that we can switch to something else easily later.
function createDialog(dialogContent, onCloseAction) {
function TranslationDialog(config) {
TranslationDialog.super.call(this, config);
}
OO.inheritClass(TranslationDialog, OO.ui.ProcessDialog);
TranslationDialog.static.name = 'toFaWikiDialog';
TranslationDialog.static.title = 'ایجاد در ویکی‌پدیای فارسی';
TranslationDialog.static.actions = [
{ action: 'cx', label: 'ایجاد به کمک ترجمهٔ محتوا' },
{
action: 'tofawiki',
label: namespaceNumber === 6 ? 'بارگذاری' : 'ایجاد به کمک ابزار توفاویکی'
},
{ label: 'بستن', flags: 'safe' }
];
if (namespaceNumber !== 0) {
// remove CX for namespaces other than the main one
TranslationDialog.static.actions.splice(0, 1);
}
TranslationDialog.prototype.initialize = function () {
TranslationDialog.super.prototype.initialize.apply(this, arguments);
this.content = new OO.ui.PanelLayout({ padded: true, expanded: false });
this.content.$element.append(dialogContent);
this.$body.append(this.content.$element);
};
TranslationDialog.prototype.getActionProcess = function (action) {
var dialog = this;
if (action) {
return new OO.ui.Process(function () {
onCloseAction(action);
dialog.close({ action: action });
})
} else {
return TranslationDialog.super.prototype.getActionProcess.call(this, action);
}
};
var windowManager = new OO.ui.WindowManager();
windowManager.$element.addClass('tofawiki-dialog');
$(document.body).append(windowManager.$element);
var dialog = new TranslationDialog();
windowManager.addWindows([dialog]);
windowManager.openWindow(dialog);
}
}
خط ۲۱۷: خط ۲۱۸:
var dialogContent = $('<div>', { dir: 'rtl' });
var dialogContent = $('<div>', { dir: 'rtl' });


var transliterationButton = namespaceNumber !== 0 ? '' : $('<span>', {
dialogContent.append($('<div>', {
class: 'tofawiki-transliteration-suggestion mw-ui-button mw-ui-progressive',
style: 'font-size: 90%; float: left'
style: 'font-size: 70%; min-height: initial',
}).append($('<a>', {
class: 'tofawiki-consolelink',
text: 'پیشنهاد',
title: 'دریافت عنوان پیشنهادی از طریق نویسه‌گردانی رباتیک'
html: 'ابزار ایجاد انبوه',
}).click(function () {
tabindex: '-1',
var button = $(this).prop('disabled', 'disabled').text('لطفاً منتظر بمانید…');
title: 'ابزار ایجاد انبوه',
$.get('https://rezabot.toolforge.org/TileTransliteration.php', {
target: '_blank',
page: mw.config.get('wgTitle')
href: '//fa.wikipedia.org' + mw.util.getUrl('ویژه:صفحهٔ_خالی/tofawiki-conosle') + '?withJS=MediaWiki:TofawikiConsole.js'
}).then(function (response) {
}).hide()), $('<br>').css('clear', 'both'), $('<div>').append($('<a>', {
button.replaceWith($('<div>', {
text: 'راهنما',
tabindex: '-1',
class: 'tofawiki-transliteration-success',
title: 'راهنمای کار با ابزار',
style: 'font-size: 90%; color: #d33',
text: 'نویسه‌گردانی عنوان با موفقیت وارد شد. احتمال خطا وجود دارد، لطفاً به دقت بازبینی کنید!'
target: '_blank',
}));
style: 'float: left; font-size: smaller;',
$('.tofawiki-name', dialogContent).val(response.result);
href: '//fa.wikipedia.org' + mw.util.getUrl('راهنما:ابزار/به_ویکی‌فا')
}), $('<select>', {
}, function () {
button.remove();
class: 'tofawiki-select',
mw.notify('درخواست نویسه‌گردانی موفق نبود');
style: 'font-family: inherit'
}).append(
});
});
$.map(requestingPages, function (item, description) {

var disabled =
dialogContent.append([
namespaceNumber === 14 && item !== CATEGORIES_BOT ||
$('<div>', {
namespaceNumber === 0 && item === CATEGORIES_BOT ||
style: 'font-size: 90%; float: left'
namespaceNumber === 4 && item !== WIKIPEDIA_TRANSLATOR ||
}).append(
namespaceNumber === 0 && item === WIKIPEDIA_TRANSLATOR ||
$('<a>', {
namespaceNumber === 6 && item !== FAIRUSE_IMAGES ||
class: 'tofawiki-consolelink',
namespaceNumber === 0 && item === FAIRUSE_IMAGES ||
html: 'ابزار ایجاد انبوه',
[10, 102, 828].indexOf(namespaceNumber) !== -1 && item !== TEMPLATE_BOOK_TRANSLATOR ||
tabindex: '-1',
namespaceNumber === 0 && item === TEMPLATE_BOOK_TRANSLATOR;
title: 'ابزار ایجاد انبوه',
return $('<option>', { value: item, text: description, disabled: disabled });
target: '_blank',
href: '//fa.wikipedia.org' + mw.util.getUrl('ویژه:صفحهٔ_خالی/tofawiki-conosle') + '?withJS=MediaWiki:TofawikiConsole.js'
}).hide()
),
$('<br>').css('clear', 'both'),
$('<div>').append([
$('<a>', {
text: 'راهنما',
tabindex: '-1',
title: 'راهنمای کار با ابزار',
target: '_blank',
style: 'float: left; font-size: smaller;',
href: '//fa.wikipedia.org' + mw.util.getUrl('راهنما:ابزار/به_ویکی‌فا')
}),
$('<select>', {
class: 'tofawiki-select',
style: 'font-family: inherit'
}).append(
$.map(requestingPages, function (item, description) {
var disabled =
namespaceNumber === 14 && item !== CATEGORIES_BOT ||
namespaceNumber === 0 && item === CATEGORIES_BOT ||
namespaceNumber === 4 && item !== WIKIPEDIA_TRANSLATOR ||
namespaceNumber === 0 && item === WIKIPEDIA_TRANSLATOR ||
namespaceNumber === 6 && item !== FAIRUSE_IMAGES ||
namespaceNumber === 0 && item === FAIRUSE_IMAGES ||
[10, 102, 828].indexOf(namespaceNumber) !== -1 && item !== TEMPLATE_BOOK_TRANSLATOR ||
namespaceNumber === 0 && item === TEMPLATE_BOOK_TRANSLATOR;
return $('<option>', { value: item, text: description, disabled: disabled });
})
)
]),
$('<div>').css('margin-top', '0.4em').append([
$('<input>', {
dir: 'rtl',
placeholder: 'عنوان',
class: 'tofawiki-name',
style: 'font-family: inherit; width: 50%;'
}).on('input', validityCheck), ' ', $('<img>', {
src: '//upload.wikimedia.org/wikipedia/fa/f/fc/Button_super_tool.png',
click: function () {
$('.tofawiki-name', dialogContent).val(persianWikiTools.superToolMove(
$('.tofawiki-name', dialogContent).val()
));
}
}),
' ',
transliterationButton
]),
$('<div>', {
class: 'tofawiki-status',
html: '<br><br>'
})
})
]);
)), $('<div>').css('margin-top', '0.4em').append($('<input>', {
dir: 'rtl',
placeholder: 'عنوان',
class: 'tofawiki-name',
style: 'font-family: inherit; width: 50%;'
}).on('input', validityCheck), ' ', $('<img>', {
src: '//upload.wikimedia.org/wikipedia/fa/f/fc/Button_super_tool.png',
click: function () {
$('.tofawiki-name', dialogContent).val(persianWikiTools.superToolMove(
$('.tofawiki-name', dialogContent).val()
));
}
}), ' ', namespaceNumber === 0
? $('<span>', {
class: 'tofawiki-transliteration-suggestion mw-ui-button mw-ui-progressive',
style: 'font-size: 70%; min-height: initial',
text: 'پیشنهاد',
title: 'دریافت عنوان پیشنهادی از طریق نویسه‌گردانی رباتیک'
}).click(function () {
var button = $(this).prop('disabled', 'disabled').text('لطفاً منتظر بمانید…');
$.get('https://rezabot.toolforge.org/TileTransliteration.php', {
page: mw.config.get('wgTitle')
}).then(function (response) {
button.replaceWith($('<div>', {
class: 'tofawiki-transliteration-success',
style: 'font-size: 90%; color: #d33',
text: 'نویسه‌گردانی عنوان با موفقیت وارد شد. احتمال خطا وجود دارد، لطفاً به دقت بازبینی کنید!'
}));
$('.tofawiki-name', dialogContent).val(response.result);
}, function () {
button.remove();
mw.notify('درخواست نویسه‌گردانی موفق نبود');
});
})
: ''
), $('<div>', {
class: 'tofawiki-status',
html: '<br><br>'
}));


$('.tofawiki-select', dialogContent).val(suggestRequestPlace());
$('.tofawiki-select', dialogContent).val(suggestRequestPlace());

نسخهٔ ‏۱۵ آوریل ۲۰۲۱، ساعت ۱۱:۳۹

(function () {
	'use strict';

	// افزودن ابزار ترجمه
	importScript('User:Ebrahim/ArticleTranslator.js');

    var namespaceNumber = mw.config.get('wgNamespaceNumber');
	if (mw.config.get('wgAction') !== 'view' ||
			[0, 4, 6, 10, 12, 14, 102, 828].indexOf(namespaceNumber) === -1) {
		return;
	}

	var GENERAL_BOT = 'ویکی‌پدیا:درخواست ایجاد مقاله (رباتیک)';
	var CITIES_BOT = 'ویکی‌پدیا:ویکی‌پروژه ایجاد مقاله‌های شهرها با ربات/درخواست ساخت رباتیک';
	var PEOPLE_BOT = 'ویکی‌پدیا:درخواست ایجاد مقاله (رباتیک)/انسان';
	var OTHER_REQUESTS = 'ویکی‌پدیا:مقاله‌های درخواستی';
	var CATEGORIES_BOT = 'ویکی‌پدیا:درخواست ایجاد رده (رباتیک)';
	var FAIRUSE_IMAGES = 'تصاویر استفادهٔ منصفانه';
	var TEMPLATE_BOOK_TRANSLATOR = 'انتقال‌دهندهٔ الگو، پودمان و کتاب';
	var DISAMBIGUATION_BOT = 'صفحهٔ ابهام‌زدایی';
	var WIKIPEDIA_TRANSLATOR = 'مترجم فضای نام ویکی‌پدیا';

	var requestingPages = {
		'آرایه‌های زیستی، فیلم، موسیقی، رود، ساختمان و بازی‌های ویدئویی': GENERAL_BOT,
		'شهرها و مکان‌های مسکونی': CITIES_BOT,
		'انسان و اشخاص': PEOPLE_BOT,
		'صفحهٔ ابهام‌زدایی': DISAMBIGUATION_BOT,
		'مطالب عمومی': OTHER_REQUESTS,
		'رده‌ها': CATEGORIES_BOT,
		'تصاویر منصفانه': FAIRUSE_IMAGES,
		'انتقال‌دهندهٔ الگو، پودمان و کتاب': TEMPLATE_BOOK_TRANSLATOR,
		'فضای نام راهنما و ویکی‌پدیا': WIKIPEDIA_TRANSLATOR
	};

	function suggestRequestPlace() {
		if (namespaceNumber === 0 && $([
			'.infobox.geography',
			'#catlinks a[href^="/wiki/Category:Rivers"]'
		].join(', ')).length) {
			return CITIES_BOT;
		} else if (namespaceNumber === 0 && $([
			'.infobox.biota',
			'.infobox.haudio',
			'.description a[href="/wiki/Single_(music)"]',
			'#coordinates',
			'.infobox.vcard .fn',
			'#catlinks a[href^="/wiki/Category:Rivers"]',
			'#catlinks a[href^="/wiki/Category:Songs"]',
			'#catlinks a[href^="/wiki/Category:Films"]',
			'#catlinks a[href$="films"]',
			'#catlinks a[href*="video_games"], #catlinks a[href*="Video_game"]'
		].join(', ')).length) {
			return GENERAL_BOT;
		} else if (namespaceNumber === 0 && $([
			'#catlinks a[href^="/wiki/Category:All_article_disambiguation_pages"]',
			'#catlinks a[href^="/wiki/Category:All_set_index_articles"]'
		].join(', ')).length) {
			return DISAMBIGUATION_BOT;
		} else if (namespaceNumber === 0 && $([
			'#catlinks a[href^="/wiki/Category:Island"]'
		].join(', ')).length) {
			return CITIES_BOT;
		} else if ([4, 12].indexOf(namespaceNumber) !== -1) {
			return WIKIPEDIA_TRANSLATOR;
		} else if (namespaceNumber === 14) {
			return CATEGORIES_BOT;
		} else if ([10, 102, 828].indexOf(namespaceNumber) !== -1) {
			return TEMPLATE_BOOK_TRANSLATOR;
		} else if (namespaceNumber === 6) {
			return FAIRUSE_IMAGES;
		} else if (namespaceNumber === 0 && $([
			'.infobox.vcard .fn',
			'#catlinks a[href^="people"]',
			'#catlinks a[href*="Ethnic_groups"]'
		].join(', ')).length) {
			return PEOPLE_BOT;
		}
		return OTHER_REQUESTS;
	}

	function pageExists(page) {
		return new mw.Api({ ajax: { url: '//fa.wikipedia.org/w/api.php' } }).get({
			action: 'query',
			titles: page,
			format: 'json',
			origin: location.protocol + '//' + location.hostname
		}).then(function (data) { return data.query.pages['-1'] === undefined; });
	}

	function isAllowedToUseTofawikiConsole() {
		return new mw.Api({ ajax: { url: '//fa.wikipedia.org/w/api.php' } }).get({
			action: 'query',
			list: 'users',
			ususers: mw.config.get('wgUserName'),
			usprop: 'groups',
			origin: location.protocol + '//' + location.hostname
		}).then(function (res) {
			return res.query.users[0].groups.some(function (x) {
				return ['bot', 'autopatrolled', 'patroller', 'sysop', 'eliminator'].indexOf(x) !== -1;
			});
		});
	}
	
	function addNamespace(title) {
		if (namespaceNumber === 14) { title = 'رده:' + title.replace(/^([Cc]ategory|رده):/, ''); }
		if (namespaceNumber === 10) { title = 'الگو:' + title.replace(/^([Tt]emplate|الگو):/, ''); }
		if (namespaceNumber === 102) { title = 'کتاب:' + title.replace(/^([Bb]ook|کتاب):/, ''); }
		if (namespaceNumber === 828) { title = 'پودمان:' + title.replace(/^([Mm]odule|پودمان):/, ''); }
		if (namespaceNumber === 6) { title = 'پرونده:' + title.replace(/^([Ff]ile|پرونده):/, ''); }
		if (namespaceNumber === 4) { title = 'ویکی‌پدیا:' + title.replace(/^([Ww]ikipedia|ویکی‌پدیا):/, ''); }
		if (namespaceNumber === 12) { title = 'راهنما:' + title.replace(/^([Hh]elp|راهنما):/, ''); }
		return title;
	}

	// Limiting oojs-ui windowing things to this place is intentional
	// so that we can switch to something else easily later.
	function createDialog(dialogContent, onCloseAction) {
		function TranslationDialog(config) {
			TranslationDialog.super.call(this, config);
		}
		OO.inheritClass(TranslationDialog, OO.ui.ProcessDialog);
		TranslationDialog.static.name = 'toFaWikiDialog';
		TranslationDialog.static.title = 'ایجاد در ویکی‌پدیای فارسی';
		// TODO: This should be done by the caller
		TranslationDialog.static.actions = [
			{ action: 'cx', label: 'ایجاد به کمک ترجمهٔ محتوا' },
			{
				action: 'tofawiki',
				label: namespaceNumber === 6 ? 'بارگذاری' : 'ایجاد به کمک ابزار توفاویکی'
			},
			{ label: 'بستن', flags: 'safe' }
		];
		if (namespaceNumber !== 0) {
			// remove CX for namespaces other than the main one
			TranslationDialog.static.actions.splice(0, 1);
		}
		TranslationDialog.prototype.initialize = function () {
			TranslationDialog.super.prototype.initialize.apply(this, arguments);
			this.content = new OO.ui.PanelLayout({ padded: true, expanded: false });
			this.content.$element.append(dialogContent);
			this.$body.append(this.content.$element);
		};
		TranslationDialog.prototype.getActionProcess = function (action) {
			var dialog = this;
			if (action) {
				return new OO.ui.Process(function () {
					onCloseAction(action);
					dialog.close({ action: action });
				})
			} else {
				return TranslationDialog.super.prototype.getActionProcess.call(this, action);
			}
		};
		var windowManager = new OO.ui.WindowManager();
		windowManager.$element.addClass('tofawiki-dialog');
		$(document.body).append(windowManager.$element);
		var dialog = new TranslationDialog();
		windowManager.addWindows([dialog]);
		windowManager.openWindow(dialog);
	}
		
	$(function () {
		if ($('.interlanguage-link.interwiki-fa').length !== 0) { return; }
		// if is commons image, give up
		if ($('#ca-view-foreign').length !== 0) { return; }

		$('#ca-tofawiki').remove();
		if ($('#mw-imagepage-nofile, #noarticletext').length !== 0) {
			return;
		}
		// if it is a free image, bring TransferToCommons instead
		if (namespaceNumber === 6 && $([
			'#catlinks a[href="/wiki/Category:GFDL_files"]',
			'#catlinks a[href^="/wiki/Category:Creative_Commons_Attribution"]',
			'#catlinks a[href="/wiki/Category:Move_to_Commons_Priority_Candidates"]',
			'#catlinks a[href="/wiki/Category:Convert_to_SVG_and_copy_to_Wikimedia_Commons"]',
			'#catlinks a[href^="/wiki/Category:Copy_to_Wikimedia_Commons"]'
		].join(', ')).length && $(
			'#catlinks a[href^="/wiki/Category:Wikipedia_files_not_suitable_for_Commons"]'
		).length === 0) {
			$(mw.util.addPortletLink(
				'p-views',
				new mw.Uri('//commonshelper.toolforge.org/').extend({
					lang: mw.config.get('wgContentLanguage'),
					image: mw.config.get('wgTitle'),
					interface: mw.config.get('wgContentLanguage')
				}),
				'انتقال به ویکی‌انبار'
			)).find('a').prop('target', '_blank').prepend($('<img>', {
				src: '//upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Commons-logo.svg/14px-Commons-logo.svg.png'
			}), ' ');
			return;
		}
		
		var link;
		if (false && mw.config.get('wgMFMode')) { // disabled, WIP
			link = $('#page-actions-history').clone().empty().prop('id', 'page-actions-tofawiki');
			link.append($('<a>', {
				href: '#',
				text: 'tofawiki',
				class: 'mw-ui-icon-with-label-desktop mw-ui-icon'
			}));
			$('#page-actions-history').after(link);
		} else {
			link = mw.util.addPortletLink(
				$('#p-views').length !== 0 ? 'p-views' : 'p-cactions', '#',
				'tofawiki!', 'ca-tofawiki', null, null, '#ca-view'
			);
		}

		$(link).click(function (e) {
			e.preventDefault();
			mw.util.addCSS('.tofawiki-dialog * { font-family: system-ui!important; }');
			mw.loader.load('//fa.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Extra-Editbuttons-persiantools.js&action=raw&ctype=text/javascript');
			mw.loader.load('//fa.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Extra-Editbuttons-persianwikitools.js&action=raw&ctype=text/javascript');
			mw.loader.load('//fa.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Extra-Editbuttons-dictionary.js&action=raw&ctype=text/javascript');

			var dialogContent = $('<div>', { dir: 'rtl' });

			var transliterationButton = namespaceNumber !== 0 ? '' : $('<span>', {
				class: 'tofawiki-transliteration-suggestion mw-ui-button mw-ui-progressive',
				style: 'font-size: 70%; min-height: initial',
				text: 'پیشنهاد',
				title: 'دریافت عنوان پیشنهادی از طریق نویسه‌گردانی رباتیک'
			}).click(function () {
				var button = $(this).prop('disabled', 'disabled').text('لطفاً منتظر بمانید…');
				$.get('https://rezabot.toolforge.org/TileTransliteration.php', {
					page: mw.config.get('wgTitle')
				}).then(function (response) {
					button.replaceWith($('<div>', {
						class: 'tofawiki-transliteration-success',
						style: 'font-size: 90%; color: #d33',
						text: 'نویسه‌گردانی عنوان با موفقیت وارد شد. احتمال خطا وجود دارد، لطفاً به دقت بازبینی کنید!'
					}));
					$('.tofawiki-name', dialogContent).val(response.result);
				}, function () {
					button.remove();
					mw.notify('درخواست نویسه‌گردانی موفق نبود');
				});
			});

			dialogContent.append([
				$('<div>', {
					style: 'font-size: 90%; float: left'
				}).append(
					$('<a>', {
						class: 'tofawiki-consolelink',
						html: 'ابزار ایجاد انبوه',
						tabindex: '-1',
						title: 'ابزار ایجاد انبوه',
						target: '_blank',
						href: '//fa.wikipedia.org' + mw.util.getUrl('ویژه:صفحهٔ_خالی/tofawiki-conosle') + '?withJS=MediaWiki:TofawikiConsole.js'
					}).hide()
				),
				$('<br>').css('clear', 'both'),
				$('<div>').append([
					$('<a>', {
						text: 'راهنما',
						tabindex: '-1',
						title: 'راهنمای کار با ابزار',
						target: '_blank',
						style: 'float: left; font-size: smaller;',
						href: '//fa.wikipedia.org' + mw.util.getUrl('راهنما:ابزار/به_ویکی‌فا')
					}),
					$('<select>', {
						class: 'tofawiki-select',
						style: 'font-family: inherit'
					}).append(
						$.map(requestingPages, function (item, description) {
							var disabled =
								namespaceNumber === 14 && item !== CATEGORIES_BOT ||
								namespaceNumber === 0 && item === CATEGORIES_BOT ||
								namespaceNumber === 4 && item !== WIKIPEDIA_TRANSLATOR ||
								namespaceNumber === 0 && item === WIKIPEDIA_TRANSLATOR ||
								namespaceNumber === 6 && item !== FAIRUSE_IMAGES ||
								namespaceNumber === 0 && item === FAIRUSE_IMAGES ||
								[10, 102, 828].indexOf(namespaceNumber) !== -1 && item !== TEMPLATE_BOOK_TRANSLATOR ||
								namespaceNumber === 0 && item === TEMPLATE_BOOK_TRANSLATOR;
							return $('<option>', { value: item, text: description, disabled: disabled });
						})
					)
				]),
				$('<div>').css('margin-top', '0.4em').append([
					$('<input>', {
						dir: 'rtl',
						placeholder: 'عنوان',
						class: 'tofawiki-name',
						style: 'font-family: inherit; width: 50%;'
					}).on('input', validityCheck), ' ', $('<img>', {
						src: '//upload.wikimedia.org/wikipedia/fa/f/fc/Button_super_tool.png',
						click: function () {
							$('.tofawiki-name', dialogContent).val(persianWikiTools.superToolMove(
								$('.tofawiki-name', dialogContent).val()
							));
						}
					}),
					' ',
					transliterationButton
				]),
				$('<div>', {
					class: 'tofawiki-status',
					html: '<br><br>'
				})
			]);

			$('.tofawiki-select', dialogContent).val(suggestRequestPlace());
			var suggestedTitle = [10, 828, 6].indexOf(namespaceNumber) !== -1 ? mw.config.get('wgTitle') : '';
			$('.tofawiki-name', dialogContent).val(addNamespace(suggestedTitle));
			if (suggestedTitle !== '') validityCheck();
			
			var passedHtml = '<span style="color: #00af89; font-size: 140%">✓</span>';
			var failedHtml = '<span style="color: #d33; font-size: 140%">✗</span>';
			function validityCheck() {
				$('.tofawiki-transliteration-success', dialogContent).hide();
				var origValue = $('.tofawiki-name', dialogContent).val(), page = origValue;
				if (page === '') { $('.tofawiki-status', dialogContent).html(''); return; }
				page = addNamespace(page);
				pageExists(page).then(function (exists) {
					if ($('.tofawiki-name', dialogContent).val() !== origValue) { // that request is no longer relevant
						return;
					}
					if (!exists) {
						$('.tofawiki-status', dialogContent).empty().append(passedHtml + ' صفحه‌ای با نام «' + page + '» ' +
							'در ویکی‌پدیای فارسی موجود نیست پس روند ایجاد را ادامه می‌دهیم!');
					} else {
						$('.tofawiki-status', dialogContent).empty().append(failedHtml, ' عنوان «', $('<a>', {
							target: '_blank',
							href: '//fa.wikipedia.org' + mw.util.getUrl(page),
							text: page
						}), '» در ویکی‌پدیای فارسی وجود دارد. مطمئن شوید که صفحهٔ تکراری نیست!');
						if ($('.tofawiki-select', dialogContent).val() === DISAMBIGUATION_BOT) {
							$('.tofawiki-status', dialogContent).append('<br><br>', $('<a>', {
								text: 'برای افزودن (ابهام‌زدایی) به‌عنوان کلیک کنید',
								href: '#'
							}).click(function (e) {
								e.preventDefault();
								$('.tofawiki-name', dialogContent).val($('.tofawiki-name', dialogContent).val() + ' (ابهام‌زدایی)');
								validityCheck();
							}));
						}
					}
				});
			}
			
			function onCloseAction(action) {
				if (action === 'cx') {
					window.open(new mw.Uri('//fa.wikipedia.org/w/index.php').extend({
						title: 'Special:CX',
						page: mw.config.get('wgPageName'),
						from: 'en',
						to: 'fa',
						targettitle: $('.tofawiki-name', dialogContent).val().replace(/_/g, '+').replace(/ي/g, 'ی').replace(/ك/g, 'ک'),
						withJS: 'MediaWiki:EnableCX.js'
					}));
				} else if (action === 'tofawiki') {
					var faName = $('.tofawiki-name', dialogContent).val().replace(/ي/g, 'ی').replace(/ك/g, 'ک');
					var requestingPage = $('.tofawiki-select', dialogContent).val();
					if (!faName || !requestingPage) {
						$('.tofawiki-status', dialogContent).text('ابتدا نامی وارد کنید!');
						return;
					}
					if (requestingPage === FAIRUSE_IMAGES) {
						window.open(new mw.Uri('https://fa.wikipedia.org/w/index.php').extend({
							title: 'ویژه:بارگذاری_پرونده',
							wpDestFile: faName,
							enName: mw.config.get('wgRelevantPageName'),
							withJS: 'MediaWiki:TofawikiUpload.js',
							wpUploadDescription: '----'
						}));
					} else {
						window.open(new mw.Uri('https://fa.wikipedia.org/w/index.php').extend({
							title: addNamespace(faName),
							enName: mw.config.get('wgRelevantPageName'),
							enOldid: mw.config.get('wgRevisionId'),
							redlink: 1,
							action: 'edit',
							withJS: 'MediaWiki:TofawikiHelper.js',
							requestingPage: requestingPage,
							editintro: 'الگو:به ویکی‌فا/ادیت‌نوتیس'
						}));
					}
				}
			}

			mw.loader.using(['oojs-ui']).then(function () {
				createDialog(dialogContent, onCloseAction);
			});

			isAllowedToUseTofawikiConsole().then(function (allowed) {
				if (allowed) {
					$('.tofawiki-consolelink', dialogContent).show();
				}
			});
		});
	});

	// translate the section part
	function createTranslateLink(sectionId, placeToPutAfter) {
		return $('<span>').append([
			$('<a>', {
				text: 'translate',
				title: 'Translate the section from English to Persian, provided by Targoman',
				href: '#'
			}).click(function (e) {
				e.preventDefault();
				var translateButtonLink = $(e.target);
				if (translateButtonLink.css('color') === 'lightgray') return;
				translateButtonLink.css('color', 'lightgray');
				$.get('https://rezabot.toolforge.org/targoman3.php', {
					title: mw.config.get('wgPageName'),
					subsection: sectionId
				}).then(function (result) {
					translateButtonLink.css('color', '');
					$(placeToPutAfter).after($('<div>', {
						contenteditable: 'true',
						spellcheck: 'true',
						lang: 'fa',
						dir: 'rtl',
						text: result.translation
					}).css({
						'white-space': 'pre-wrap',
						'font-family': 'system-ui',
						border: '2px solid #54595d',
						padding: '1em',
						'background-color': '#f0f0f0',
						'margin-bottom': '8px',
						'border-radius': '15px'
					}))
				}).catch(function (e) {
					console.error(e);
					mw.notify(JSON.stringify(e));
				});
			})
		].concat($('.interlanguage-link.interwiki-fa').length ? [
			'/',
			$('<a>', {
				text: 'transfer',
				title: 'Transfer the section to Persian Wikipedia',
				target: '_blank',
				href: new mw.Uri($('.interlanguage-link.interwiki-fa a')[0].href).extend({
					action: 'edit',
					editintro: 'Template:Null',
					enTitle: mw.config.get('wgPageName'),
					enSectionId: sectionId,
					withJS: 'MediaWiki:TofawikiSection.js'
				})
			})
		] : []));
	}
	$(function () {
		if ([0, 4].indexOf(namespaceNumber) === -1) return;
		$('.mw-editsection a').get().forEach(function (editLink) {
			var sectionId = new mw.Uri(editLink.href).query.section;
			// don't interfere with MediaWiki:Gadget-edittop.js
			if (!sectionId) return;
			if (mw.config.get('wgMFMode')) {
				$('.mw-headline', editLink.parentElement.parentElement).append([
					' ',
					createTranslateLink(
						sectionId,
						editLink.parentElement.parentElement
					).css('font-size', '50%')
				]);
			} else {
				$(editLink).after([
					' | ',
					createTranslateLink(
						sectionId,
						editLink.parentElement.parentElement
					)
				]);
			}
		});
		// first section
		$('h1.firstHeading:first').append($('<span>', {
			class: 'noprint'
		}).css({
			'user-select': 'none',
			'font-size': '40%',
			'margin-left': '2em'
		}).append(
			$('<span>', { contenteditable: true }),
			' ',
			createTranslateLink(0, $('#content h1')).prepend('(').append(')')
		));
	});

	$(function () {
		// improvements when tofawiki is in translation
		if (window.self === window.top || location.hash !== '#tofawikiframe') {
			return;
		}
		mw.util.addCSS('#translatorBar { display: none; }');
		$('#mw-page-base, #mw-head-base, #mw-navigation, #siteSub, #footer, .read-more-container').remove();
		$('#firstHeading').each(function () { this.firstChild.remove(); });
		$('#content').css('margin-left', 0).css('margin-right', 0).css('padding-top', 0);
		importStylesheet('MediaWiki:Print.css');

		// quick specialized links translator
		var links = {};
		document.querySelectorAll('#bodyContent a').forEach(function (x) {
			var href = x.getAttribute('href');
			if (!href || href.indexOf('/wiki/') === -1) return;
			var title = decodeURI(href.replace(/.*?\/wiki\//, ''))
				.replace(/_/g, ' ').replace(/#.*$/g, '');
			if (title) {
				if (!links[title]) links[title] = [];
				links[title].push(x);
			}
		});
		$('#bodyContent').after($('<textarea id="linkstranslator-link-textarea">').css({
			// http://stackoverflow.com/a/30810322
			position: 'fixed', top: 0, right: '-2em', width: '2em', height: '2em',
			padding: 0, border: 'none', outline: 'none', boxShadow: 'none',
			background: 'transparent'
		}));
		$.post('https://tofawiki-linkstranslator.wmflabs.org/', {
			from: 'en',
			to: 'fa',
			p: Object.keys(links).join('|')
		}).then(function (result) {
			Object.entries(links).forEach(function (entry) {
				var translation = result[entry[0]];
				if (translation === undefined) return;
				entry[1].forEach(function (link) {
					$(link).after($('<span>').append('(', !navigator.clipboard ? '' : $('<a>', {
						href: '#',
						style: 'font-size: 140%; font-weight: normal; line-height: 0;',
						title: 'Copy to clipboard',
						text: '⎘',
						click: function (e) {
							// TODO: Maybe some communication with the parent frame and put it there directly?
							e.preventDefault();
							$('#linkstranslator-link-textarea').val('[[' + translation + ']]')[0].select();
							try {
								document.execCommand('copy');
								e.target.animate && e.target.animate([
									{ fontSize: '140%' }, { fontSize: '100%' }
								], { duration: 220, iterations: 1 });
							} catch (e) {}
						}
					}), ' ', $('<bdi>').append($('<a>', {
						lang: 'fa',
						href: '//fa.wikipedia.org' + mw.util.getUrl(translation),
						text: translation
					})), ')'));
				});
			})
		});
	});
}());