مدیاویکی:Gadget-twinkleprotect.js

از ایران پدیا
نسخهٔ تاریخ ‏۲ دسامبر ۲۰۱۷، ساعت ۲۰:۵۲ توسط Rootadmin (بحث | مشارکت‌ها) (۱ نسخه واردشده)
(تفاوت) → نسخهٔ قدیمی‌تر | نمایش نسخهٔ فعلی (تفاوت) | نسخهٔ جدیدتر ← (تفاوت)
پرش به ناوبری پرش به جستجو

نکته: پس از انتشار ممکن است برای دیدن تغییرات نیاز باشد که حافظهٔ نهانی مرورگر خود را پاک کنید.

  • فایرفاکس / سافاری: کلید Shift را نگه دارید و روی دکمهٔ Reload کلیک کنید، یا کلید‌های Ctrl-F5 یا Ctrl-R را با هم فشار دهید (در رایانه‌های اپل مکینتاش کلید‌های ⌘-R)
  • گوگل کروم: کلیدهای Ctrl+Shift+R را با هم فشار دهید (در رایانه‌های اپل مکینتاش کلید‌های ⌘-Shift-R)
  • اینترنت اکسپلورر/ Edge: کلید Ctrl را نگه‌دارید و روی دکمهٔ Refresh کلیک کنید، یا کلید‌های Ctrl-F5 را با هم فشار دهید
  • اپرا: Ctrl-F5 را بفشارید.
//<nowiki>


(function($){


/*
 ****************************************
 *** twinkleprotect.js: Protect/RPP module
 ****************************************
 * Mode of invocation:     Tab ("مص"/"دمص")
 * Active on:              Non-special pages
 * Config directives in:   TwinkleConfig
 */

// Note: a lot of code in this module is re-used/called by batchprotect.

Twinkle.protect = function twinkleprotect() {
	if ( mw.config.get('wgNamespaceNumber') < 0 ) {
		return;
	}

	Twinkle.addPortletLink(Twinkle.protect.callback, Morebits.userIsInGroup('sysop') ? "مص" : "دمص", "tw-rpp",
		Morebits.userIsInGroup('sysop') ? "صفحه را محافظت کن" : "درخواست محافظت صفحه" );
};

Twinkle.protect.callback = function twinkleprotectCallback() {
	Twinkle.protect.protectionLevel = null;

	var Window = new Morebits.simpleWindow( 620, 530 );
	Window.setTitle( Morebits.userIsInGroup( 'sysop' ) ? "اعمال، درخواست، یا افزودن برچسب محافظت" : "درخواست یا افزودن برچسب محافظت" );
	Window.setScriptName( "توینکل" );
	Window.addFooterLink( "الگوهای محافظت", "الگو:الگوهای محافظت" );
	Window.addFooterLink( "سیاست محافظت", "اپ:محافظت" );
	Window.addFooterLink( "راهنمای توینکل", ":en:ip:TW/DOC#protect" );

	var form = new Morebits.quickForm( Twinkle.protect.callback.evaluate );
	var actionfield = form.append( {
			type: 'field',
			label: 'نوع عمل'
		} );
	if( Morebits.userIsInGroup( 'sysop' ) ) {
		actionfield.append( {
				type: 'radio',
				name: 'actiontype',
				event: Twinkle.protect.callback.changeAction,
				list: [
					{
						label: 'صفحه را محافظت کن',
						value: 'protect',
						tooltip: 'محافظت کردن صفحه',
						checked: true
					}
				]
			} );
	}
	actionfield.append( {
			type: 'radio',
			name: 'actiontype',
			event: Twinkle.protect.callback.changeAction,
			list: [
				{
					label: 'درخواست محافظت صفحه',
					value: 'request',
					tooltip: 'اگر می‌خواهید از طریق اپ:دمص درخواست حفاظت دهید' + (Morebits.userIsInGroup('sysop') ? ' جای حفاظت‌کردن توسط خودتان.' : '.'),
					checked: !Morebits.userIsInGroup('sysop')
				},
				{
					label: 'صفحه را با الگوی محافظت برچسب بزن',
					value: 'tag',
					tooltip: 'از این ابزار برای افزودن برچسب محافظت به صفحه‌های محافظت شده می‌توان استفاده کرد.',
					disabled: mw.config.get('wgArticleId') === 0
				}
			]
		} );

	form.append({ type: 'field', label: 'پیش‌تنظیم‌ها', name: 'field_preset' });
	form.append({ type: 'field', label: '1', name: 'field1' });
	form.append({ type: 'field', label: '2', name: 'field2' });

	form.append( { type:'submit' } );

	var result = form.render();
	Window.setContent( result );
	Window.display();

	// We must init the controls
	var evt = document.createEvent( "Event" );
	evt.initEvent( 'change', true, true );
	result.actiontype[0].dispatchEvent( evt );

	// get current protection level asynchronously
	if (Morebits.userIsInGroup('sysop')) {
		Morebits.wiki.actionCompleted.postfix = false;  // avoid Action: completed notice
		Morebits.status.init($('div[name="currentprot"] span').last()[0]);
	}
	Twinkle.protect.fetchProtectionLevel();
};

// Current protection level in a human-readable format
// (a string, or null if no protection; only filled for sysops)
Twinkle.protect.protectionLevel = null;  
// Contains the current protection level in an object
// Once filled, it will look something like:
// { edit: { level: "sysop", expiry: <some date>, cascade: true }, ... }
Twinkle.protect.currentProtectionLevels = {};

Twinkle.protect.fetchProtectionLevel = function twinkleprotectFetchProtectionLevel() {

	var api = new mw.Api();
	api.get({
		format: 'json',
		indexpageids: true,
		action: 'query',
		prop: 'info|flagged',
		inprop: 'protection',
		titles: mw.config.get('wgPageName')
	})
	.done(function(data){
		var pageid = data.query.pageids[0];
		var page = data.query.pages[pageid];
		var result = [];
		var current = {};

		var updateResult = function(label, level, expiry, cascade) {
			// for sysops, stringify, so they can base their decision on existing protection
			if (Morebits.userIsInGroup('sysop')) {
				var boldnode = document.createElement('b');
				boldnode.textContent = label + ": " + level;
				result.push(boldnode);
				if (expiry === 'infinity') {
					result.push(" (بی‌پایان) ");
				} else {
					result.push(" (" + new Date(expiry).toUTCString() + " به پایان می‌رسد) ");
				}
				if (cascade) {
					result.push("(آبشاری) ");
				}
			}
		};

		$.each(page.protection, function( index, protection ) {
			if (protection.type !== "aft") {
				current[protection.type] = {
					level: protection.level,
					expiry: protection.expiry,
					cascade: protection.cascade === ''
				};
				updateResult( Morebits.string.toUpperCaseFirstChar(protection.type), protection.level, protection.expiry, protection.cascade );
			}
		});

		if (page.flagged) {
			current.stabilize = {
				level: page.flagged.protection_level,
				expiry: page.flagged.protection_expiry
			};
			// FlaggedRevision gives bad date
			updateResult( 'Pending Changes', page.flagged.protection_level, page.flagged.protection_expiry, false );
		}

		// show the protection level to sysops
		if (Morebits.userIsInGroup('sysop')) {
			if (!result.length) {
				var boldnode = document.createElement('b');
				boldnode.textContent = "بدون محافظت";
				result.push(boldnode);
			}
			Twinkle.protect.protectionLevel = result;
			Morebits.status.init($('div[name="currentprot"] span').last()[0]);
			Morebits.status.info("سطح محافظت کنونی", Twinkle.protect.protectionLevel);
		}

		Twinkle.protect.currentProtectionLevels = current;
	});
};

Twinkle.protect.callback.changeAction = function twinkleprotectCallbackChangeAction(e) {
	var field_preset;
	var field1;
	var field2;
	var isTemplate = mw.config.get("wgNamespaceNumber") === 10 || mw.config.get("wgNamespaceNumber") === 828;

	switch (e.target.values) {
		case 'protect':
			field_preset = new Morebits.quickForm.element({ type: 'field', label: 'پیش‌تنظیم‌ها', name: 'field_preset' });
			field_preset.append({
					type: 'select',
					name: 'category',
					label: 'انتخاب تنظیمات:',
					event: Twinkle.protect.callback.changePreset,
					list: (mw.config.get('wgArticleId') ?
						Twinkle.protect.protectionTypes.filter(function(v) {
							return isTemplate || v.label !== 'محفاظت الگو';
						}) :
						Twinkle.protect.protectionTypesCreate)
				});

			field2 = new Morebits.quickForm.element({ type: 'field', label: 'گزینه‌های محافظت', name: 'field2' });
			field2.append({ type: 'div', name: 'currentprot', label: ' ' });  // holds the current protection level, as filled out by the async callback
			// for existing pages
			if (mw.config.get('wgArticleId')) {
				field2.append({
						type: 'checkbox',
						name: 'editmodify',
						event: Twinkle.protect.formevents.editmodify,
						list: [
							{
								label: 'تغییر سطح محافظت',
								value: 'editmodify',
								tooltip: 'اگر غیر فعال شود، سطح حفاظت ویرایش و زمان به پایان رسیدن همان که هست باقی می‌ماند.',
								checked: true
							}
						]
					});
				var editlevel = field2.append({
						type: 'select',
						name: 'editlevel',
						label: 'حفاظت در برابر ویرایش:',
						event: Twinkle.protect.formevents.editlevel
					});
				editlevel.append({
						type: 'option',
						label: 'همه',
						value: 'all'
					});
				editlevel.append({
						type: 'option',
						label: 'تأییدشده',
						value: 'autoconfirmed'
					});
				if (isTemplate) {
					editlevel.append({
							type: 'option',
							label: 'ویرایشگران الگو',
							value: 'templateeditor'
						});
				}
				editlevel.append({
						type: 'option',
						label: 'مدیر',
						value: 'sysop',
						selected: true
					});
				field2.append({
						type: 'select',
						name: 'editexpiry',
						label: 'سررسید:',
						event: function(e) {
							if (e.target.value === 'custom') {
								Twinkle.protect.doCustomExpiry(e.target);
							}
						},
						list: [
							{ label: '۱ ساعت', value: '1 hour' },
							{ label: '۲ ساعت', value: '2 hours' },
							{ label: '۳ ساعت', value: '3 hours' },
							{ label: '۶ ساعت', value: '6 hours' },
							{ label: '۱۲ ساعت', value: '12 hours' },
							{ label: '۱ روز', value: '1 day' },
							{ label: '۲ روز', selected: true, value: '2 days' },
							{ label: '۳ روز', value: '3 days' },
							{ label: '۴ روز', value: '4 days' },
							{ label: '۱ هفته', value: '1 week' },
							{ label: '۲ هفته', value: '2 weeks' },
							{ label: '۱ ماه', value: '1 month' },
							{ label: '۲ ماه', value: '2 months' },
							{ label: '۳ ماه', value: '3 months' },
							{ label: '۱ سال', value: '1 year' },
							{ label: 'نامعین', value:'indefinite' },
							{ label: 'سفارشی...', value: 'custom' }
						]
					});
				field2.append({
						type: 'checkbox',
						name: 'movemodify',
						event: Twinkle.protect.formevents.movemodify,
						list: [
							{
								label: 'تغییر محافظت انتقال',
								value: 'movemodify',
								tooltip: 'اگر غیر فعال شود، سطح حفاظت انتقال و زمان به پایان رسیدن همان که هست باقی می‌ماند.',
								checked: true
							}
						]
					});
				var movelevel = field2.append({
						type: 'select',
						name: 'movelevel',
						label: 'محافظت‌شده در برابر انتقال:',
						event: Twinkle.protect.formevents.movelevel
					});
				movelevel.append({
						type: 'option',
						label: 'همه',
						value: 'all'
					});
				movelevel.append({
						type: 'option',
						label: 'تأییدشده',
						value: 'autoconfirmed'
					});
				if (isTemplate) {
					movelevel.append({
							type: 'option',
							label: 'ویرایشگران الگو',
							value: 'templateeditor'
						});
				}
				movelevel.append({
						type: 'option',
						label: 'مدیر',
						value: 'sysop',
						selected: true
					});
				field2.append({
						type: 'select',
						name: 'moveexpiry',
						label: 'سررسید:',
						event: function(e) {
							if (e.target.value === 'custom') {
								Twinkle.protect.doCustomExpiry(e.target);
							}
						},
						list: [
							{ label: '۱ ساعت', value: '1 hour' },
							{ label: '۲ ساعت', value: '2 hours' },
							{ label: '۳ ساعت', value: '3 hours' },
							{ label: '۶ ساعت', value: '6 hours' },
							{ label: '۱۲ ساعت', value: '12 hours' },
							{ label: '۱ روز', value: '1 day' },
							{ label: '۲ روز', value: '2 days' },
							{ label: '۳ روز', value: '3 days' },
							{ label: '۴ روز', value: '4 days' },
							{ label: '۱ هفته', value: '1 week' },
							{ label: '۲ هفته', value: '2 weeks' },
							{ label: '۱ ماه', value: '1 month' },
							{ label: '۲ ماه', value: '2 months' },
							{ label: '۳ ماه', value: '3 months' },
							{ label: '۱ سال', value: '1 year' },
							{ label: 'نامعین', selected: true, value:'indefinite' },
							{ label: 'سفارشی...', value: 'custom' }
						]
					});
				field2.append({
						type: 'checkbox',
						name: 'pcmodify',
						event: Twinkle.protect.formevents.pcmodify,
						list: [
							{
								label: 'تغییر سطح محافظت در حال انتظار',
								value: 'pcmodify',
								tooltip: 'اگر غیر فعال شود، سطح حفاظت تغییرات در حال انتظار و زمان به پایان رسیدن همان که هست باقی می‌ماند.',
								checked: true
							}
						]
					});
				var pclevel = field2.append({
						type: 'select',
						name: 'pclevel',
						label: 'تغییرات در انتظار:',
						event: Twinkle.protect.formevents.pclevel
					});
				pclevel.append({
						type: 'option',
						label: 'هیچ کدام',
						value: 'none'
					});
				pclevel.append({
						type: 'option',
						label: 'سطح ۱',
						value: 'autoconfirmed',
						selected: true
					});
				pclevel.append({
						type: 'option',
						label: 'سطح ۲ (استفاده نکنید)',
						value: 'review'
					});
				field2.append({
						type: 'select',
						name: 'pcexpiry',
						label: 'سررسید:',
						event: function(e) {
							if (e.target.value === 'custom') {
								Twinkle.protect.doCustomExpiry(e.target);
							}
						},
						list: [
							{ label: '۱ ساعت', value: '1 hour' },
							{ label: '۲ ساعت', value: '2 hours' },
							{ label: '۳ ساعت', value: '3 hours' },
							{ label: '۶ ساعت', value: '6 hours' },
							{ label: '۱۲ ساعت', value: '12 hours' },
							{ label: '۱ روز', value: '1 day' },
							{ label: '۲ روز', value: '2 days' },
							{ label: '۳ روز', value: '3 days' },
							{ label: '۴ روز', value: '4 days' },
							{ label: '۱ هفته', value: '1 week' },
							{ label: '۲ هفته', value: '2 weeks' },
							{ label: '۱ ماه', selected: true, value: '1 month' },
							{ label: '۲ ماه', value: '2 months' },
							{ label: '۳ ماه', value: '3 months' },
							{ label: '۱ سال', value: '1 year' },
							{ label: 'نامعین', value:'indefinite' },
							{ label: 'سفارشی...', value: 'custom' }
						]
					});
			} else {  // for non-existing pages
				var createlevel = field2.append({
						type: 'select',
						name: 'createlevel',
						label: 'ایجاد محافظت:',
						event: Twinkle.protect.formevents.createlevel
					});
				createlevel.append({
						type: 'option',
						label: 'همه',
						value: 'all'
					});
				createlevel.append({
						type: 'option',
						label: 'تأییدشده',
						value: 'autoconfirmed'
					});
				if (isTemplate) {
					createlevel.append({
							type: 'option',
							label: 'ویرایشگران الگو',
							value: 'templateeditor'
						});
				}
				createlevel.append({
						type: 'option',
						label: 'مدیر',
						value: 'sysop',
						selected: true
					});
				field2.append({
						type: 'select',
						name: 'createexpiry',
						label: 'سررسید:',
						event: function(e) {
							if (e.target.value === 'custom') {
								Twinkle.protect.doCustomExpiry(e.target);
							}
						},
						list: [
							{ label: '۱ ساعت', value: '1 hour' },
							{ label: '۲ ساعت', value: '2 hours' },
							{ label: '۳ ساعت', value: '3 hours' },
							{ label: '۶ ساعت', value: '6 hours' },
							{ label: '۱۲ ساعت', value: '12 hours' },
							{ label: '۱ روز', value: '1 day' },
							{ label: '۲ روز', value: '2 days' },
							{ label: '۳ روز', value: '3 days' },
							{ label: '۴ روز', value: '4 days' },
							{ label: '۱ هفته', value: '1 week' },
							{ label: '۲ هفته', value: '2 weeks' },
							{ label: '۱ ماه', value: '1 month' },
							{ label: '۲ ماه', value: '2 months' },
							{ label: '۳ ماه', value: '3 months' },
							{ label: '۱ سال', value: '1 year' },
							{ label: 'نامعین', selected: true, value: 'indefinite' },
							{ label: 'سفارشی...', value: 'custom' }
						]
					});
			}
			field2.append({
					type: 'textarea',
					name: 'protectReason',
					label: 'دلیل محافظت (در سیاهه):'
				});
			if (!mw.config.get('wgArticleId')) {  // tagging isn't relevant for non-existing pages
				break;
			}
			/* falls through */
		case 'tag':
			field1 = new Morebits.quickForm.element({ type: 'field', label: 'گزینه‌های برچسب‌زنی', name: 'field1' });
			field1.append( {
					type: 'select',
					name: 'tagtype',
					label: 'گزینش الگوی محافظت:',
					list: Twinkle.protect.protectionTags,
					event: Twinkle.protect.formevents.tagtype
				} );
			field1.append( {
					type: 'checkbox',
					list: [
						{
							name: 'small',
							label: 'افزودن (small=yes)',
							tooltip: 'به کمک  |small=yes تنظیم الگو به صورت قفل دیده‌می‌شود',
							checked: true
						},
						{
							name: 'noinclude',
							label: 'قرار دادن الگو محافظت در میان <noinclude>',
							tooltip: 'الگوی حفاظت را در میان برچسب‌های &lt;noinclude&gt; قرار می‌دهد، بنابراین تراگنجانش نمی‌شود',
							checked: (mw.config.get('wgNamespaceNumber') === 10)
						}
					]
				} );
			break;

		case 'request':
			field_preset = new Morebits.quickForm.element({ type: 'field', label: 'نوع محافظت', name: 'field_preset' });
			field_preset.append({
					type: 'select',
					name: 'category',
					label: 'دلایل:',
					event: Twinkle.protect.callback.changePreset,
					list: (mw.config.get('wgArticleId') ? Twinkle.protect.protectionTypes : Twinkle.protect.protectionTypesCreate)
				});

			field1 = new Morebits.quickForm.element({ type: 'field', label: 'گزینه‌ها', name: 'field1' });
			field1.append( {
					type: 'select',
					name: 'expiry',
					label: 'مدت: ',
					list: [
						{ label: 'موقت', value: 'temporary' },
						{ label: 'نامعین', value: 'indefinite' },
						{ label: '', selected: true, value: '' }
					]
				} );
			field1.append({
					type: 'textarea',
					name: 'reason',
					label: 'دلیل: '
				});
			break;
		default:
			alert("Something's afoot in twinkleprotect");
			break;
	}

	var oldfield;
	if (field_preset) {
		oldfield = $(e.target.form).find('fieldset[name="field_preset"]')[0];
		oldfield.parentNode.replaceChild(field_preset.render(), oldfield);
	} else {
		$(e.target.form).find('fieldset[name="field_preset"]').css('display', 'none');
	}
	if (field1) {
		oldfield = $(e.target.form).find('fieldset[name="field1"]')[0];
		oldfield.parentNode.replaceChild(field1.render(), oldfield);
	} else {
		$(e.target.form).find('fieldset[name="field1"]').css('display', 'none');
	}
	if (field2) {
		oldfield = $(e.target.form).find('fieldset[name="field2"]')[0];
		oldfield.parentNode.replaceChild(field2.render(), oldfield);
	} else {
		$(e.target.form).find('fieldset[name="field2"]').css('display', 'none');
	}

	if (e.target.values === 'protect') {
		// fake a change event on the preset dropdown
		var evt = document.createEvent( "Event" );
		evt.initEvent( 'change', true, true );
		e.target.form.category.dispatchEvent( evt );

		// re-add protection level text, if it's available
		if (Twinkle.protect.protectionLevel) {
			Morebits.status.init($('div[name="currentprot"] span').last()[0]);
			Morebits.status.info("سطح محافظت کنونی", Twinkle.protect.protectionLevel);
		}

		// reduce vertical height of dialog
		$(e.target.form).find('fieldset[name="field2"] select').parent().css({ display: 'inline-block', marginRight: '0.5em' });
	}
};

Twinkle.protect.formevents = {
	editmodify: function twinkleprotectFormEditmodifyEvent(e) {
		e.target.form.editlevel.disabled = !e.target.checked;
		e.target.form.editexpiry.disabled = !e.target.checked || (e.target.form.editlevel.value === 'all');
		e.target.form.editlevel.style.color = e.target.form.editexpiry.style.color = (e.target.checked ? "" : "transparent");
	},
	editlevel: function twinkleprotectFormEditlevelEvent(e) {
		e.target.form.editexpiry.disabled = (e.target.value === 'all');
	},
	movemodify: function twinkleprotectFormMovemodifyEvent(e) {
		e.target.form.movelevel.disabled = !e.target.checked;
		e.target.form.moveexpiry.disabled = !e.target.checked || (e.target.form.movelevel.value === 'all');
		e.target.form.movelevel.style.color = e.target.form.moveexpiry.style.color = (e.target.checked ? "" : "transparent");
	},
	movelevel: function twinkleprotectFormMovelevelEvent(e) {
		e.target.form.moveexpiry.disabled = (e.target.value === 'all');
	},
	pcmodify: function twinkleprotectFormPcmodifyEvent(e) {
		e.target.form.pclevel.disabled = !e.target.checked;
		e.target.form.pcexpiry.disabled = !e.target.checked || (e.target.form.pclevel.value === 'none');
		e.target.form.pclevel.style.color = e.target.form.pcexpiry.style.color = (e.target.checked ? "" : "transparent");
	},
	pclevel: function twinkleprotectFormPclevelEvent(e) {
		e.target.form.pcexpiry.disabled = (e.target.value === 'none');
	},
	createlevel: function twinkleprotectFormCreatelevelEvent(e) {
		e.target.form.createexpiry.disabled = (e.target.value === 'all');
	},
	tagtype: function twinkleprotectFormTagtypeEvent(e) {
		e.target.form.small.disabled = e.target.form.noinclude.disabled = (e.target.value === 'none') || (e.target.value === 'noop');
	}
};

Twinkle.protect.doCustomExpiry = function twinkleprotectDoCustomExpiry(target) {
	var custom = prompt('زمان سررسید دلخواهی را وارد کنید.  \nشما می‌توانید از زمان‌های نزدیک، مانند «۱ دقیقه» یا «۱۹ روز»، یا برچسب‌های زمانی کامل، «yyyymmddhhmm» (برای نمونه: «200602011405» برابر ۱ فوریه ۲۰۰۶ ساعت ۱۴:۰۵ به زمان یوتی‌سی است) استفاده کنید.', '');
	if (custom) {
		var option = document.createElement('option');
		option.setAttribute('value', custom);
		option.textContent = custom;
		target.appendChild(option);
		target.value = custom;
	} else {
		target.selectedIndex = 0;
	}
};

Twinkle.protect.protectionTypes = [
	{ label: 'خروج از محافظت', value: 'unprotect' },
	{
		label: 'محفاظت کامل',
		list: [
			{ label: 'عمومی (کامل)', value: 'pp-protected' },
			{ label: 'مناقشه بر سر محتوا/جنگ ویرایشی (کامل)', value: 'pp-dispute' },
			{ label: 'خرابکاری مداوم (کامل)', value: 'pp-vandalism' },
			{ label: 'بحث کاربر بسته‌شده (کامل)', value: 'pp-usertalk' }
		]
	},
	{
		label: 'محفاظت الگو',
		list: [
			{ label: 'الگوی پربازدید (ویرایشگران الگو)', value: 'pp-template' }
		]
	},
	{
		label: 'نیمه‌حفاظت',
		list: [
			{ label: 'کامل (نیمه)', value: 'pp-semi-protected' },
			{ label: 'خرابکاری مداوم (نیمه)', selected: true, value: 'pp-semi-vandalism' },
			{ label: 'نقض سیاست زندگان (نیمه)', value: 'pp-semi-blp' },
			{ label: 'زاپاس‌بازی (نیمه)', value: 'pp-semi-sock' },
			{ label: 'بحث کاربر بسته‌شده (نیمه)', value: 'pp-semi-usertalk' }
		]
	},
	{
		label: 'تغییرات در حال انتظار',
		list: [
			{ label: 'عمومی (در انتظار)', value: 'pp-pc-protected' },
			{ label: 'ی مداوم (نیمه) (در انتظار)', value: 'pp-pc-vandalism' },
			{ label: 'نقض سیاست زندگان (در انتظار)', value: 'pp-pc-blp' }
		]
	},
	{
		label: 'محافظت در برابر انتقال',
		list: [
			{ label: 'عمومی (انتقال)', value: 'pp-move' },
			{ label: 'مناقشه/جنگ ویرایشی (انتقال)', value: 'pp-move-dispute' },
			{ label: 'خرابکاری با انتقال صفحه (انتقال)', value: 'pp-move-vandalism' },
			{ label: 'صفحهٔ پربازدید (انتقال)', value: 'pp-move-indef' }
		]
	}
];

Twinkle.protect.protectionTypesCreate = [
	{ label: 'خروج از محافظت', value: 'unprotect' },
	{
		label: 'ایجاد محافظت',
		list: [
			{ label: 'عمومی (در برابر ایجاد)', value: 'pp-create' },
			{ label: 'نام نامناسب', value: 'pp-create-offensive' },
			{ label: 'ایجاد پی در پی', selected: true, value: 'pp-create-salt' },
			{ label: 'زندگان به‌تازگی حذف‌شده', value: 'pp-create-blp' }
		]
	}
];

// A page with both regular and PC protection will be assigned its regular
// protection weight plus 2 (for PC1) or 7 (for PC2)
Twinkle.protect.protectionWeight = {
	sysop: 30,
	templateeditor: 20,
	flaggedrevs_review: 15,  // Pending Changes level 2 protection alone
	autoconfirmed: 10,
	flaggedrevs_autoconfirmed: 5,  // Pending Changes level 1 protection alone
	all: 0,
	flaggedrevs_none: 0  // just in case
};

// NOTICE: keep this synched with [[MediaWiki:Protect-dropdown]]
// Also note: stabilize = Pending Changes level
Twinkle.protect.protectionPresetsInfo = {
	'pp-protected': {
		edit: 'sysop',
		move: 'sysop',
		reason: null
	},
	'pp-dispute': {
		edit: 'sysop',
		move: 'sysop',
		reason: '[[ اپ:حفظ|سیاست محافظت از صفحات]]'
	},
	'pp-vandalism': {
		edit: 'sysop',
		move: 'sysop',
		reason: '[[اپ:خ|خرابکاری]] مداوم'
	},
	'pp-usertalk': {
		edit: 'sysop',
		move: 'sysop',
		reason: '[[اپ:سح#اپ:قفل بحث|استفادهٔ نامناسب از صفحهٔ بحث در زمان قطع دسترسی]]'
	},
	'pp-template': {
		edit: 'templateeditor',
		move: 'templateeditor',
		reason: '[[اپ:الگوهای حساس|الگوهای حساس]]'
	},
	'pp-semi-vandalism': {
		edit: 'autoconfirmed',
		reason: '[[اپ:خ|خرابکاری]] مداوم',
		template: 'pp-vandalism'
	},
	'pp-semi-blp': {
		edit: 'autoconfirmed',
		reason: 'نقض [[اپ:زز|سیاست زندگی‌نامهٔ زندگان]]',
		template: 'pp-blp'
	},
	'pp-semi-usertalk': {
		edit: 'autoconfirmed',
		move: 'sysop',
		reason: '[[اپ:سح#اپ:قفل بحث|استفادهٔ نامناسب از صفحهٔ بحث در زمان قطع دسترسی]]',
		template: 'pp-usertalk'
	},
	'pp-semi-template': {  // removed for now
		edit: 'autoconfirmed',
		move: 'sysop',
		reason: '[[اپ:الگوهای حساس|الگوهای حساس]]',
		template: 'pp-template'
	},
	'pp-semi-sock': {
		edit: 'autoconfirmed',
		reason: '[[اپ:زاپاس:|زاپاس‌بازی]] ادامه‌دار',
		template: 'pp-sock'
	},
	'pp-semi-protected': {
		edit: 'autoconfirmed',
		reason: null,
		template: 'pp-protected'
	},
	'pp-pc-vandalism': {
		stabilize: 'autoconfirmed',  // stabilize = Pending Changes
		reason: '[[اپ:خ|خرابکاری]] مداوم',
		template: 'pp-pc1'
	},
	'pp-pc-blp': {
		stabilize: 'autoconfirmed',
		reason: 'نقض [[اپ:زز|سیاست زندگی‌نامهٔ زندگان]]',
		template: 'pp-pc1'
	},
	'pp-pc-protected': {
		stabilize: 'autoconfirmed',
		reason: null,
		template: 'pp-pc1'
	},
	'pp-move': {
		move: 'sysop',
		reason: null
	},
	'pp-move-dispute': {
		move: 'sysop',
		reason: '[[اپ:حفظ|جنگ انتقال]]'
	},
	'pp-move-vandalism': {
		move: 'sysop',
		reason: '[[اپ:حفظ|خرابکاری با انتقال]]'
	},
	'pp-move-indef': {
		move: 'sysop',
		reason: '[[اپ:حفظ|صفحهٔ پربازدید]]'
	},
	'unprotect': {
		edit: 'all',
		move: 'all',
		stabilize: 'none',
		create: 'all',
		reason: null,
		template: 'none'
	},
	'pp-create-offensive': {
		create: 'sysop',
		reason: '[[اپ:حفظ|عنوان اهانت‌آمیز]]'
	},
	'pp-create-salt': {
		create: 'sysop',
		reason: '[[ اپ:حفظ|ایجاد پی‌درپی]]'
	},
	'pp-create-blp': {
		create: 'sysop',
		reason: '[[اپ:زز|زندگی‌نامهٔ زندگان به‌تازگی حذف‌شده]]'
	},
	'pp-create': {
		create: 'sysop',
		reason: '{{pp-create}}'
	}
};

Twinkle.protect.protectionTags = [
	{
		label: 'هیچ (الگوهای محافظت موجود را بردارید)',
		value: 'none'
	},
	{
		label: 'هیچ (الگوهای محافظت موجود را برندارید)',
		value: 'noop'
	},
	{
		label: 'الگوهای محافظت کامل',
		list: [
			{ label: '{{pp-vandalism}}: خرابکاری', value: 'pp-vandalism' },
			{ label: '{{pp-dispute}}: جنگ ویرایشی/اختلاف', value: 'pp-dispute', selected: true },
			{ label: '{{pp-blp}}: نقض‌های زندگی‌نامه زندگان', value: 'pp-blp' },
			{ label: '{{pp-sock}}: زاپاس', value: 'pp-sock' },
			{ label: '{{pp-template}}: الگوهای حساس', value: 'pp-template' },
			{ label: '{{pp-usertalk}}: بحث کاربران مسدودشده', value: 'pp-usertalk' },
			{ label: '{{pp-protected}}: حفاظت عمومی', value: 'pp-protected' },
			{ label: '{{pp-semi-indef}}: نیمه‌حفاظت بلندمدت عمومی', value: 'pp-semi-indef' }
		]
	},
	{
		label: 'الگوهای تغییرات در حال انتظار',
		list: [
			{ label: '{{pp-pc1}}: تغییرات در حال انتظار سطح ۱', value: 'pp-pc1' }
		]
	},
	{
		label: 'الگوهای حفاظت انتقال',
		list: [
			{ label: '{{pp-move-dispute}}: dispute/move war', value: 'pp-move-dispute' },
			{ label: '{{pp-move-vandalism}}: خرابکاری انتقال صفحه', value: 'pp-move-vandalism' },
			{ label: '{{pp-move-indef}}: بلندمدت عمومی', value: 'pp-move-indef' },
			{ label: '{{pp-move}}: دیگر', value: 'pp-move' }
		]
	}
];

Twinkle.protect.callback.changePreset = function twinkleprotectCallbackChangePreset(e) {
	var form = e.target.form;

	var actiontypes = form.actiontype;
	var actiontype;
	for( var i = 0; i < actiontypes.length; i++ )
	{
		if( !actiontypes[i].checked ) {
			continue;
		}
		actiontype = actiontypes[i].values;
		break;
	}

	if (actiontype === 'protect') {  // actually protecting the page
		var item = Twinkle.protect.protectionPresetsInfo[form.category.value];
		if (mw.config.get('wgArticleId')) {
			if (item.edit) {
				form.editmodify.checked = true;
				Twinkle.protect.formevents.editmodify({ target: form.editmodify });
				form.editlevel.value = item.edit;
				Twinkle.protect.formevents.editlevel({ target: form.editlevel });
			} else {
				form.editmodify.checked = false;
				Twinkle.protect.formevents.editmodify({ target: form.editmodify });
			}

			if (item.move) {
				form.movemodify.checked = true;
				Twinkle.protect.formevents.movemodify({ target: form.movemodify });
				form.movelevel.value = item.move;
				Twinkle.protect.formevents.movelevel({ target: form.movelevel });
			} else {
				form.movemodify.checked = false;
				Twinkle.protect.formevents.movemodify({ target: form.movemodify });
			}

			if (item.stabilize) {
				form.pcmodify.checked = true;
				Twinkle.protect.formevents.pcmodify({ target: form.pcmodify });
				form.pclevel.value = item.stabilize;
				Twinkle.protect.formevents.pclevel({ target: form.pclevel });
			} else {
				form.pcmodify.checked = false;
				Twinkle.protect.formevents.pcmodify({ target: form.pcmodify });
			}
		} else {
			if (item.create) {
				form.createlevel.value = item.create;
				Twinkle.protect.formevents.createlevel({ target: form.createlevel });
			}
		}

		var reasonField = (actiontype === "protect" ? form.protectReason : form.reason);
		if (item.reason) {
			reasonField.value = item.reason;
		} else {
			reasonField.value = '';
		}

		// sort out tagging options
		if (mw.config.get('wgArticleId')) {
			if( form.category.value === 'unprotect' ) {
				form.tagtype.value = 'none';
			} else {
				form.tagtype.value = (item.template ? item.template : form.category.value);
			}
			Twinkle.protect.formevents.tagtype({ target: form.tagtype });

			if( /template/.test( form.category.value ) ) {
				form.noinclude.checked = true;
				form.editexpiry.value = form.moveexpiry.value = form.pcexpiry.value = "indefinite";
			} else {
				form.noinclude.checked = false;
			}
		}

	} else {  // RPP request
		if( form.category.value === 'unprotect' ) {
			form.expiry.value = '';
			form.expiry.disabled = true;
		} else {
			form.expiry.disabled = false;
		}
	}
};

Twinkle.protect.callback.evaluate = function twinkleprotectCallbackEvaluate(e) {
	var form = e.target;

	var actiontypes = form.actiontype;
	var actiontype;
	for( var i = 0; i < actiontypes.length; i++ )
	{
		if( !actiontypes[i].checked ) {
			continue;
		}
		actiontype = actiontypes[i].values;
		break;
	}

	var tagparams;
	if( actiontype === 'tag' || (actiontype === 'protect' && mw.config.get('wgArticleId')) ) {
		tagparams = {
			tag: form.tagtype.value,
			reason: ((form.tagtype.value === 'pp-protected' || form.tagtype.value === 'pp-semi-protected' || form.tagtype.value === 'pp-move') && form.protectReason) ? form.protectReason.value : null,
			expiry: (actiontype === 'protect') ?
				(form.editmodify.checked ? form.editexpiry.value :
					(form.movemodify.checked ? form.moveexpiry.value :
						(form.pcmodify.checked ? form.pcexpiry.value : null)
					)
				) : null,
			small: form.small.checked,
			noinclude: form.noinclude.checked
		};
	}

	switch (actiontype) {
		case 'protect':
			// protect the page

			Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
			Morebits.wiki.actionCompleted.notice = "حفاظت کامل شد";

			var statusInited = false;
			var thispage;

			var allDone = function twinkleprotectCallbackAllDone() {
				if (thispage) {
					thispage.getStatusElement().info("done");
				}
				if (tagparams) {
					Twinkle.protect.callbacks.taggingPageInitial(tagparams);
				}
			};

			var protectIt = function twinkleprotectCallbackProtectIt(next) {
				thispage = new Morebits.wiki.page(mw.config.get('wgPageName'), "در حال حفاظت از صفحه");
				if (mw.config.get('wgArticleId')) {
					if (form.editmodify.checked) {
						thispage.setEditProtection(form.editlevel.value, form.editexpiry.value);
					}
					if (form.movemodify.checked) {
						thispage.setMoveProtection(form.movelevel.value, form.moveexpiry.value);
					}
				} else {
					thispage.setCreateProtection(form.createlevel.value, form.createexpiry.value);
					thispage.setWatchlist(false);
				}

				if (form.protectReason.value) {
					thispage.setEditSummary(form.protectReason.value);
				} else {
					alert("نیاز است حتماً یک دلیل برای محافظت ذکر کنید. این دلیل در سیاههٔ محافظت ثبت خواهد شد.");
					return;
				}

				if (!statusInited) {
					Morebits.simpleWindow.setButtonsEnabled( false );
					Morebits.status.init( form );
					statusInited = true;
				}

				thispage.protect(next);
			};

			var stabilizeIt = function twinkleprotectCallbackStabilizeIt() {
				if (thispage) {
					thispage.getStatusElement().info("done");
				}

				thispage = new Morebits.wiki.page(mw.config.get('wgPageName'), "در حال اعمال حفاظت تغییرات در حال انتظار");
				thispage.setFlaggedRevs(form.pclevel.value, form.pcexpiry.value);

				if (form.protectReason.value) {
					thispage.setEditSummary(form.protectReason.value);
				} else {
					alert("نیاز است حتماً یک دلیل برای محافظت ذکر کنید. این دلیل در سیاههٔ محافظت ثبت خواهد شد.");
					return;
				}

				if (!statusInited) {
					Morebits.simpleWindow.setButtonsEnabled(false);
					Morebits.status.init(form);
					statusInited = true;
				}

				thispage.stabilize(allDone);
			};

			if ((form.editmodify && form.editmodify.checked) || (form.movemodify && form.movemodify.checked) ||
				!mw.config.get('wgArticleId')) {
				if (form.pcmodify && form.pcmodify.checked) {
					protectIt(stabilizeIt);
				} else {
					protectIt(allDone);
				}
			} else if (form.pcmodify && form.pcmodify.checked) {
				stabilizeIt();
			} else {
				alert("لطفاً به توینکل کاری برای انجام دهید! \nاگر فقط می‌خواهید به صفحه برچسب بزنید، می‌توانید گزینهٔ 'صفحه را با الگوی محافظت برچسب بزن' را در بالا انتخاب کنید.");
			}

			break;

		case 'tag':
			// apply a protection template

			Morebits.simpleWindow.setButtonsEnabled( false );
			Morebits.status.init( form );

			Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
			Morebits.wiki.actionCompleted.followRedirect = false;
			Morebits.wiki.actionCompleted.notice = "برچسب‌زدن کامل شد";

			Twinkle.protect.callbacks.taggingPageInitial(tagparams);
			break;

		case 'request':
			// file request at RPP
			var typename, typereason;
			switch( form.category.value ) {
				case 'pp-dispute':
				case 'pp-vandalism':
				case 'pp-usertalk':
				case 'pp-protected':
					typename = 'محافظت کامل';
					break;
				case 'pp-template':
					typename = 'محافظت الگو';
					break;
				case 'pp-semi-vandalism':
				case 'pp-semi-usertalk':
				case 'pp-semi-sock':
				case 'pp-semi-blp':
				case 'pp-semi-protected':
					typename = 'نیمه‌حفاظت';
					break;
				case 'pp-pc-vandalism':
				case 'pp-pc-blp':
				case 'pp-pc-protected':
					typename = 'تغییرات در حال انتظار';
					break;
				case 'pp-move':
				case 'pp-move-dispute':
				case 'pp-move-indef':
				case 'pp-move-vandalism':
					typename = 'محافظت در برابر انتقال';
					break;
				case 'pp-create':
				case 'pp-create-offensive':
				case 'pp-create-blp':
				case 'pp-create-salt':
					typename = 'محافظت در برابر ایجاد';
					break;
				case 'unprotect':
					/* falls through */
				default:
					typename = 'برداشتن محافظت';
					break;
			}
			switch (form.category.value) {
				case 'pp-dispute':
					typereason = 'مناقشه بر سر محتوا/جنگ ویرایشی';
					break;
				case 'pp-vandalism':
				case 'pp-semi-vandalism':
				case 'pp-pc-vandalism':
					typereason = 'خرابکاری مداوم';
					break;
				case 'pp-template':
					typereason = 'الگوی پربازدید';
					break;
				case 'pp-usertalk':
				case 'pp-semi-usertalk':
					typereason = 'استفاده نامناسب کاربر بسته شده از صفحهٔ بحث';
					break;
				case 'pp-semi-sock':
					typereason = 'زاپاس‌بازی مداوم';
					break;
				case 'pp-semi-blp':
				case 'pp-pc-blp':
					typereason = 'نقض [[اپ:زز|سیاست زندگی‌نامهٔ زندگان]]';
					break;
				case 'pp-move-dispute':
					typereason = 'مناقشه بر سر عنوان صفحه/جنگ ویرایشی';
					break;
				case 'pp-move-vandalism':
					typereason = 'خرابکاری در انتقال صفحه';
					break;
				case 'pp-move-indef':
					typereason = 'صفحهٔ پربازدید';
					break;
				case 'pp-create-offensive':
					typereason = 'نام نامناسب';
					break;
				case 'pp-create-blp':
					typereason = 'اخیراً حذف شده [[اپ:زز]]';
					break;
				case 'pp-create-salt':
					typereason = 'ایجاد پی در پی';
					break;
				default:
					typereason = '';
					break;
			}

			var reason = typereason;
			if( form.reason.value !== '') {
				if ( typereason !== '' ) {
					reason += "\u00A0\u2013 ";  // U+00A0 NO-BREAK SPACE; U+2013 EN RULE
				}
				reason += form.reason.value;
			}
			if( reason !== '' && reason.charAt( reason.length - 1 ) !== '.' ) {
				reason += '.';
			}

			var rppparams = {
				reason: reason,
				typename: typename,
				category: form.category.value,
				expiry: form.expiry.value
			};

			Morebits.simpleWindow.setButtonsEnabled( false );
			Morebits.status.init( form );

			var rppName = 'ایران‌پدیا:درخواست محافظت صفحه';

			// Updating data for the action completed event
			Morebits.wiki.actionCompleted.redirect = rppName;
			Morebits.wiki.actionCompleted.notice = "نامزد کردن انجام شد، در حال هدایت به صفحهٔ گفتگو";

			var rppPage = new Morebits.wiki.page( rppName, 'در حال ایجاد درخواست حفاظت از صفحه');
			rppPage.setFollowRedirect( true );
			rppPage.setCallbackParameters( rppparams );
			rppPage.load( Twinkle.protect.callbacks.fileRequest );
			break;
		default:
			alert("توینکل: درخواست نامعلوم");
			break;
	}
};

Twinkle.protect.callbacks = {
	taggingPageInitial: function( tagparams ) {
		if (tagparams.tag === 'noop') {
			Morebits.status.info("در حال اعمال الگوی حفاظت", "کاری برای انجام‌دادن نیست");
			return;
		}

		var protectedPage = new Morebits.wiki.page( mw.config.get('wgPageName'), 'در حال برچسب‌زدن صفحه');
		protectedPage.setCallbackParameters( tagparams );
		protectedPage.load( Twinkle.protect.callbacks.taggingPage );
	},
	taggingPage: function( protectedPage ) {
		var params = protectedPage.getCallbackParameters();
		var text = protectedPage.getPageText();
		var tag, summary;

		var oldtag_re = /\s*(?:<noinclude>)?\s*\{\{\s*(pp-[^{}]*?|protected|(?:t|v|s|p-|usertalk-v|usertalk-s|sb|move)protected(?:2)?|protected template|privacy protection)\s*?\}\}\s*(?:<\/noinclude>)?\s*/gi;
		var re_result = oldtag_re.exec(text);
		if (re_result) {
			if (confirm("{{" + re_result[1] + "}} در صفحه یافت شد. \nبرای برداشتنش روی دکمه پذیرش کلیک کنید و یا با انصراف دادن بگذارید آنجا بماند.")) {
				text = text.replace( oldtag_re, '' );
			}
		}

		if ( params.tag !== 'none' ) {
			tag = params.tag;
			if( params.reason ) {
				tag += '|معیار=' + params.reason;
			}
			if( ['indefinite', 'infinite', 'never', null].indexOf(params.expiry) === -1 ) {
				tag += '|expiry={{subst:#time:j F Y|' + (/^\s*\d+\s*$/.exec(params.expiry) ? params.expiry : '+' + params.expiry) + '|en}}' + '';
			}
			if( params.small ) {
				tag += '|small=yes';
			}
		}

		if( params.tag === 'none' ) {
			summary = 'حذف الگوی محافظت' + Twinkle.getPref('summaryAd');
		} else {
			if( params.noinclude ) {
				text = "<noinclude>{{" + tag + "}}</noinclude>" + text;
			} else if( Morebits.wiki.isPageRedirect() ) {
				text = text + "\n{{" + tag + "}}";
			} else {
				text = "{{" + tag + "}}\n" + text;
			}
			summary = "افزودن {{" + params.tag + "}}" + Twinkle.getPref('summaryAd');
		}

		protectedPage.setEditSummary( summary );
		protectedPage.setPageText( text );
		protectedPage.setCreateOption( 'nocreate' );
		protectedPage.suppressProtectWarning(); // no need to let admins know they are editing through protection
		protectedPage.save();
	},

	fileRequest: function( rppPage ) {

		var params = rppPage.getCallbackParameters();
		var text = rppPage.getPageText();
		var statusElement = rppPage.getStatusElement();

		var ns2tag = {
			'0': 'مقاله',
			'1': 'lat',
			'2': 'lu',
			'3': 'lut',
			'4': 'lw',
			'5': 'lwt',
			'6': 'lf',
			'7': 'lft',
			'8': 'lm',
			'9': 'lmt',
			'10': 'lt',
			'11': 'ltt',
			'12': 'lh',
			'13': 'lht',
			'14': 'lc',
			'15': 'lct',
			'100': 'lp',
			'101': 'lpt',
			'108': 'lb',
			'109': 'lbt',
			'118': 'ld',
			'119': 'ldt',
			'710': 'lttxt',
			'711': 'lttxtt',
			'828': 'lmd',
			'829': 'lmdt'
		};

		var linkTemplate = ns2tag[ mw.config.get('wgNamespaceNumber') ];
		// support other namespaces like TimedText
		// (this could support talk spaces better, but doesn't seem worth it)
		if (!linkTemplate) {
			linkTemplate = 'ln|' + Morebits.pageNameNorm.substring(0, Morebits.pageNameNorm.indexOf(':'));
		}

		var rppRe = new RegExp( '===\\s*\\{\\{\\s*' + linkTemplate + '\\s*\\|\\s*' + window.RegExp.escape( mw.config.get('wgTitle'), true ) + '\\s*\\}\\}\\s*===', 'm' );
		var tag = rppRe.exec( text );

		var rppLink = document.createElement('a');
		rppLink.setAttribute('href', mw.util.getUrl(rppPage.getPageName()) );
		rppLink.appendChild(document.createTextNode(rppPage.getPageName()));

		if ( tag ) {
			statusElement.error( [ 'درخواست محافظت برای این صفحه وجود  در', rppLink, 'وجود دارد. درخواست شما لغو شد.' ] );
			return;
		}

		var newtag = '=== {{' + linkTemplate + '|' + mw.config.get('wgTitle') + '}} ===' + "\n";
		if( ( new RegExp( '^' + window.RegExp.escape( newtag ).replace( /\s+/g, '\\s*' ), 'm' ) ).test( text ) ) {
			statusElement.error( [ 'درخواست محافظت برای این صفحه وجود  در', rppLink, 'وجود دارد. درخواست شما لغو شد.' ] );
			return;
		}

		var words;
		switch( params.expiry ) {
		case 'temporary':
			words = "موقت ";
			break;
		case 'indefinite':
			words = "بی‌پایان ";
			break;
		default:
			words = "";
			break;
		}

		words += params.typename;

		newtag += "'''" + Morebits.string.toUpperCaseFirstChar(words) + ( params.reason !== '' ? ( ":''' " +
			Morebits.string.formatReasonText(params.reason) ) : ".'''" ) + " ~~~~";

		// If either protection type results in a increased status, then post it under increase
		// else we post it under decrease
		var increase = false;
		var protInfo = Twinkle.protect.protectionPresetsInfo[params.category];

		// function to compute protection weights (see comment at Twinkle.protect.protectionWeight)
		var computeWeight = function(mainLevel, stabilizeLevel) {
			var result = Twinkle.protect.protectionWeight[mainLevel || 'all'];
			if (stabilizeLevel) {
				if (result) {
					if (stabilizeLevel.level === "autoconfirmed") {
						result += 2;
					} else if (stabilizeLevel.level === "review") {
						result += 7;
					}
				} else {
					result = Twinkle.protect.protectionWeight["flaggedrevs_" + stabilizeLevel];
				}
			}
			return result;
		};

		// compare the page's current protection weights with the protection we are requesting
		var editWeight = computeWeight(Twinkle.protect.currentProtectionLevels.edit &&
			Twinkle.protect.currentProtectionLevels.edit.level,
			Twinkle.protect.currentProtectionLevels.stabilize &&
			Twinkle.protect.currentProtectionLevels.stabilize.level);
		if (computeWeight(protInfo.edit, protInfo.stabilize) > editWeight ||
			computeWeight(protInfo.move) > computeWeight(Twinkle.protect.currentProtectionLevels.move && 
			Twinkle.protect.currentProtectionLevels.move.level) ||
			computeWeight(protInfo.create) > computeWeight(Twinkle.protect.currentProtectionLevels.create && 
			Twinkle.protect.currentProtectionLevels.create.level)) {
			increase = true;
		}

		var reg;
		if ( increase ) {
			reg = /(\n==\s*درخواست‌های محافظت\s*==\s*\n\s*)/;
		} else {
			reg = /(\n==\s*درخواست‌های خروج از محافظت\s*==\s*\n\s*)/;
		}
		var originalTextLength = text.length;
		text = text.replace( reg, "$1" + newtag + "\n");
		if (text.length === originalTextLength)
		{
			var linknode = document.createElement('a');
			linknode.setAttribute("href", mw.util.getUrl("اپ:توینکل/تعمیر") );
			linknode.appendChild(document.createTextNode('چگونگی اصلاح دمص'));
			statusElement.error( [ 'عنوان مورد نظر در اپ:دمص یافت نشد. برای رفع مشکل لطفاً ببینید:', linknode, '.' ] );
			return;
		}
		statusElement.status( 'در حال افزودن درخواست تازه...' );
		rppPage.setEditSummary( "درخواست " + params.typename + (params.typename === "تغییرات در حال انتظار" ? ' در [[' : ' از [[') +
			Morebits.pageNameNorm + ']].' + Twinkle.getPref('summaryAd') );
		rppPage.setPageText( text );
		rppPage.setCreateOption( 'recreate' );
		rppPage.save();
	}
};
})(jQuery);


//</nowiki>