User:Hamish/Twinkle/modules/twinklexfd.js

维基百科,自由的百科全书

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。

// <nowiki>


(function($) {


/*
 ****************************************
 *** twinklexfd.js: XFD module
 ****************************************
 * Mode of invocation:     Tab ("XFD")
 * Active on:              Existing, non-special pages, except for file pages with no local (non-Commons) file which are not redirects
 */

Twinkle.xfd = function twinklexfd() {
	// Disable on:
	// * special pages
	// * Flow pages
	// * non-existent pages
	// * files on Commons, whether there is a local page or not (unneeded local pages of files on Commons are eligible for CSD F2)
	// * file pages without actual files (these are eligible for CSD G8)
	if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgPageContentModel') === 'flow-board' || !mw.config.get('wgArticleId') || (mw.config.get('wgNamespaceNumber') === 6 && (document.getElementById('mw-sharedupload') || (!document.getElementById('mw-imagepage-section-filehistory') && !Morebits.wiki.isPageRedirect())))) {
		return;
	}
	Twinkle.addPortletLink(Twinkle.xfd.callback, wgULS('提删', '提刪'), 'tw-xfd', wgULS('提交删除讨论', '提交刪除討論'));

	var date = new Morebits.date();
	if (date.getUTCMonth() === 3 && date.getUTCDate() === 1) {
		Twinkle.addPortletLink(Twinkle.xfd.aprilfool, wgULS('愚人节提删', '愚人節提刪'), 'tw-xfd-april-fool', wgULS('愚人节提删', '愚人節提刪'));
	}
};

Twinkle.xfd.currentRationale = null;

// error callback on Morebits.status.object
Twinkle.xfd.printRationale = function twinklexfdPrintRationale() {
	if (Twinkle.xfd.currentRationale) {
		Morebits.status.printUserText(Twinkle.xfd.currentRationale, wgULS('您的理由已在下方提供,如果您想重新提交,请将其复制到一新窗口中:', '您的理由已在下方提供,如果您想重新提交,請將其複製到一新視窗中:'));
		// only need to print the rationale once
		Twinkle.xfd.currentRationale = null;
	}
};

Twinkle.xfd.callback = function twinklexfdCallback() {
	var Window = new Morebits.simpleWindow(600, 350);
	Window.setTitle(wgULS('提交存废讨论', '提交存廢討論'));
	Window.setScriptName('Twinkle');
	Window.addFooterLink(wgULS('关于存废讨论', '關於存廢討論'), 'WP:XFD');
	Window.addFooterLink(wgULS('Twinkle帮助', 'Twinkle說明'), 'WP:TW/DOC#xfd');

	var form = new Morebits.quickForm(Twinkle.xfd.callback.evaluate);
	var categories = form.append({
		type: 'select',
		name: 'category',
		label: wgULS('提交类型:', '提交類別:'),
		event: Twinkle.xfd.callback.change_category
	});
	categories.append({
		type: 'option',
		label: wgULS('页面存废讨论', '頁面存廢討論'),
		selected: mw.config.get('wgNamespaceNumber') === 0,  // Main namespace
		value: 'afd'
	});
	categories.append({
		type: 'option',
		label: wgULS('文件存废讨论', '檔案存廢討論'),
		selected: mw.config.get('wgNamespaceNumber') === 6,  // File namespace
		value: 'ffd'
	});
	form.append({
		type: 'checkbox',
		list: [
			{
				label: wgULS('如可能,通知页面创建者', '如可能,通知頁面建立者'),
				value: 'notify',
				name: 'notify',
				tooltip: wgULS('在页面创建者讨论页上放置一通知模板。', '在頁面建立者討論頁上放置一通知模板。'),
				checked: true
			}
		]
	}
	);
	form.append({
		type: 'field',
		label: '工作区',
		name: 'work_area'
	});
	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.category.dispatchEvent(evt);
};

Twinkle.xfd.callback.change_category = function twinklexfdCallbackChangeCategory(e) {
	var value = e.target.value;
	var form = e.target.form;
	var old_area = Morebits.quickForm.getElements(e.target.form, 'work_area')[0];
	var work_area = null;

	var oldreasontextbox = form.getElementsByTagName('textarea')[0];
	var oldreason = oldreasontextbox ? oldreasontextbox.value : '';

	var appendReasonBox = function twinklexfdAppendReasonBox(xfd_cat) {
		switch (xfd_cat) {
			case 'fwdcsd':
				oldreason = decodeURIComponent($('#delete-reason').text()).replace(/\+/g, ' ');
				break;
			case 'fame':
				oldreason = Twinkle.getPref('afdFameDefaultReason');
				break;
			case 'substub':
				oldreason = Twinkle.getPref('afdSubstubDefaultReason');
				break;
			default:
				break;
		}
		work_area.append({
			type: 'textarea',
			name: 'xfdreason',
			label: wgULS('提删理由:', '提刪理由:'),
			value: oldreason,
			tooltip: wgULS('您可以使用维基格式,Twinkle将自动为您添加签名。如果您使用批量提删功能,存废讨论页只会使用第一次提交的理由,但之后您仍需提供以用于删除通告模板的参数。', '您可以使用維基格式,Twinkle將自動為您加入簽名。如果您使用批次提刪功能,存廢討論頁只會使用第一次提交的理由,但之後您仍需提供以用於刪除通告模板的參數。'),
			placeholder: wgULS('此值亦显示于页面的删除通告模板内,故务必提供此值,避免使用“同上”等用语。', '此值亦顯示於頁面的刪除通告模板內,故務必提供此值,避免使用「同上」等用語。')
		});
		// TODO possible future "preview" link here
	};

	switch (value) {
		case 'afd':
			work_area = new Morebits.quickForm.element({
				type: 'field',
				label: wgULS('页面存废讨论', '頁面存廢討論'),
				name: 'work_area'
			});
			work_area.append({
				type: 'checkbox',
				list: [
					{
						label: '使用<noinclude>包裹模板',
						value: 'noinclude',
						name: 'noinclude',
						checked: mw.config.get('wgNamespaceNumber') === 10 && mw.config.get('wgPageContentModel') !== 'Scribunto', // Template namespace
						tooltip: wgULS('使其不会在被包含时出现。', '使其不會在被包含時出現。'),
						disabled: mw.config.get('wgPageContentModel') === 'Scribunto'
					}
				]
			});
			var afd_category = work_area.append({
				type: 'select',
				name: 'xfdcat',
				label: wgULS('选择提删类型:', '選擇提刪類別:'),
				event: Twinkle.xfd.callback.change_afd_category
			});

			var afd_cat = 'delete';
			if (Twinkle.getPref('afdDefaultCategory') === 'same') {
				if (localStorage.Twinkle_afdCategory === undefined) {
					localStorage.Twinkle_afdCategory = 'delete';
				} else {
					afd_cat = localStorage.Twinkle_afdCategory;
				}
			}
			afd_category.append({ type: 'option', label: wgULS('删除', '刪除'), value: 'delete', selected: afd_cat === 'delete' });
			afd_category.append({ type: 'option', label: wgULS('合并', '合併'), value: 'merge', selected: afd_cat === 'merge' });
			afd_category.append({ type: 'option', label: wgULS('移动到维基词典', '移動到維基詞典'), value: 'vmd', selected: afd_cat === 'vmd' });
			afd_category.append({ type: 'option', label: wgULS('移动到维基文库', '移動到維基文庫'), value: 'vms', selected: afd_cat === 'vms' });
			afd_category.append({ type: 'option', label: wgULS('移动到维基教科书', '移動到維基教科書'), value: 'vmb', selected: afd_cat === 'vmb' });
			afd_category.append({ type: 'option', label: wgULS('移动到维基语录', '移動到維基語錄'), value: 'vmq', selected: afd_cat === 'vmq' });
			afd_category.append({ type: 'option', label: wgULS('移动到维基导游', '移動到維基導遊'), value: 'vmvoy', selected: afd_cat === 'vmvoy' });
			afd_category.append({ type: 'option', label: wgULS('移动到维基学院', '移動到維基學院'), value: 'vmv', selected: afd_cat === 'vmv' });
			if (Twinkle.getPref('FwdCsdToXfd')) {
				afd_category.append({ type: 'option', label: wgULS('转交自快速删除候选', '轉交自快速刪除候選'), value: 'fwdcsd', selected: afd_cat === 'fwdcsd' });
			}
			afd_category.append({ type: 'option', label: wgULS('批量关注度提删', '批次關注度提刪'), value: 'fame', selected: afd_cat === 'fame' });
			afd_category.append({ type: 'option', label: wgULS('批量小小作品提删', '批次小小作品提刪'), value: 'substub', selected: afd_cat === 'substub' });
			afd_category.append({ type: 'option', label: wgULS('批量其他提删', '批次其他提刪'), value: 'batch', selected: afd_cat === 'batch' });


			work_area.append({
				type: 'input',
				name: 'mergeinto',
				label: wgULS('合并到:', '合併到:'),
				hidden: true
			});
			appendReasonBox(afd_cat);
			work_area.append({
				type: 'textarea',
				name: 'fwdcsdreason',
				label: wgULS('转交理由:', '轉交理由:'),
				tooltip: wgULS('您可以使用维基格式,Twinkle将自动为您添加签名。', '您可以使用維基格式,Twinkle將自動為您加入簽名。'),
				hidden: true
			});

			work_area = work_area.render();
			old_area.parentNode.replaceChild(work_area, old_area);

			var evt = document.createEvent('Event');
			evt.initEvent('change', true, true);
			form.xfdcat.dispatchEvent(evt);
			break;
		case 'ffd':
			work_area = new Morebits.quickForm.element({
				type: 'field',
				label: wgULS('文件存废讨论', '檔案存廢討論'),
				name: 'work_area'
			});
			appendReasonBox('ffd');
			work_area = work_area.render();
			old_area.parentNode.replaceChild(work_area, old_area);
			break;
		default:
			work_area = new Morebits.quickForm.element({
				type: 'field',
				label: wgULS('未定义', '未定義'),
				name: 'work_area'
			});
			work_area = work_area.render();
			old_area.parentNode.replaceChild(work_area, old_area);
			break;
	}

	// Return to checked state when switching
	form.notify.checked = true;
	form.notify.disabled = false;
};

Twinkle.xfd.callback.change_afd_category = function twinklexfdCallbackChangeAfdCategory(e) {
	if (e.target.value === 'merge') {
		e.target.form.mergeinto.parentElement.removeAttribute('hidden');
		e.target.form.fwdcsdreason.parentElement.setAttribute('hidden', '');
		e.target.form.mergeinto.previousElementSibling.innerHTML = wgULS('合并到:', '合併到:');
	} else if (e.target.value === 'fwdcsd') {
		e.target.form.mergeinto.parentElement.removeAttribute('hidden');
		e.target.form.fwdcsdreason.parentElement.removeAttribute('hidden');
		e.target.form.mergeinto.previousElementSibling.innerHTML = '提交人:';
		e.target.form.xfdreason.value = decodeURIComponent($('#delete-reason').text()).replace(/\+/g, ' ');
	} else if (e.target.value === 'fame') {
		e.target.form.mergeinto.parentElement.setAttribute('hidden', '');
		e.target.form.fwdcsdreason.parentElement.setAttribute('hidden', '');
		e.target.form.xfdreason.value = Twinkle.getPref('afdFameDefaultReason');
	} else if (e.target.value === 'substub') {
		e.target.form.mergeinto.parentElement.setAttribute('hidden', '');
		e.target.form.fwdcsdreason.parentElement.setAttribute('hidden', '');
		e.target.form.xfdreason.value = Twinkle.getPref('afdSubstubDefaultReason');
	} else {
		e.target.form.mergeinto.parentElement.setAttribute('hidden', '');
		e.target.form.fwdcsdreason.parentElement.setAttribute('hidden', '');
	}
	if (Twinkle.getPref('afdDefaultCategory') === 'same') {
		localStorage.Twinkle_afdCategory = e.target.value;
	}
};

Twinkle.xfd.callbacks = {
	afd: {
		main: function(pageobj) {
			// this is coming in from lookupCreator...!
			var params = pageobj.getCallbackParameters();

			// Adding discussion
			var wikipedia_page = new Morebits.wiki.page(params.logpage, wgULS('添加讨论到当日列表', '加入討論到當日列表'));
			wikipedia_page.setFollowRedirect(true);
			wikipedia_page.setCallbackParameters(params);
			wikipedia_page.load(Twinkle.xfd.callbacks.afd.todaysList);

			// Notification to first contributor
			if (params.usertalk) {
				var initialContrib = pageobj.getCreator();

				// Disallow warning yourself
				if (initialContrib === mw.config.get('wgUserName')) {
					pageobj.getStatusElement().warn(wgULS('您(' + initialContrib + ')创建了该页,跳过通知', '您(' + initialContrib + ')建立了該頁,跳過通知'));
					initialContrib = null;
				} else {
					var talkPageName = 'User talk:' + initialContrib;
					Morebits.wiki.flow.check(talkPageName, function () {
						var flowpage = new Morebits.wiki.flow(talkPageName, wgULS('通知页面创建者(' + initialContrib + ')', '通知頁面建立者(' + initialContrib + ')'));
						flowpage.setTopic('页面[[:' + Morebits.pageNameNorm + ']]存废讨论通知');
						flowpage.setContent('{{subst:AFDNote|' + Morebits.pageNameNorm + '|flow=yes}}');
						flowpage.newTopic();
					}, function () {
						var usertalkpage = new Morebits.wiki.page(talkPageName, wgULS('通知页面创建者(' + initialContrib + ')', '通知頁面建立者(' + initialContrib + ')'));
						var notifytext = '\n{{subst:AFDNote|' + Morebits.pageNameNorm + '}}--~~~~';
						usertalkpage.setAppendText(notifytext);
						usertalkpage.setEditSummary('通知:页面[[' + Morebits.pageNameNorm + ']]存废讨论提名' + Twinkle.getPref('summaryAd'));
						usertalkpage.setTags(Twinkle.getPref('revisionTags'));
						usertalkpage.setCreateOption('recreate');
						switch (Twinkle.getPref('xfdWatchUser')) {
							case 'yes':
								usertalkpage.setWatchlist(true);
								break;
							case 'no':
								usertalkpage.setWatchlistFromPreferences(false);
								break;
							default:
								usertalkpage.setWatchlistFromPreferences(true);
								break;
						}
						usertalkpage.setFollowRedirect(true, false);
						usertalkpage.append();
					});
				}
				// add this nomination to the user's userspace log, if the user has enabled it
				if (params.lognomination) {
					Twinkle.xfd.callbacks.addToLog(params, initialContrib);
				}

			// or, if not notifying, add this nomination to the user's userspace log without the initial contributor's name
			} else if (params.lognomination) {
				Twinkle.xfd.callbacks.addToLog(params, null);
			}

		},
		taggingArticle: function(pageobj) {
			var text = pageobj.getPageText();
			var params = pageobj.getCallbackParameters();

			var tag = '{{vfd|' + Morebits.string.formatReasonText(params.reason);

			switch (params.xfdcat) {
				case 'vmd':
					tag += '|wikt';
					break;
				case 'vms':
					tag += '|s';
					break;
				case 'vmb':
					tag += '|b';
					break;
				case 'vmq':
					tag += '|q';
					break;
				case 'vmvoy':
					tag += '|voy';
					break;
				case 'vmv':
					tag += '|v';
					break;
				default:
					break;
			}
			if (Morebits.wiki.isPageRedirect()) {
				tag += '|r';
			}
			tag += '|date={{subst:#time:Y/m/d}}}}';
			if (params.noinclude) {
				tag = '<noinclude>' + tag + '</noinclude>';

				// 只有表格需要单独加回车,其他情况加回车会破坏模板。
				if (text.indexOf('{|') === 0) {
					tag += '\n';
				}
			} else {
				tag += '\n';
			}

			// Then, test if there are speedy deletion-related templates on the article.
			var textNoSd = text.replace(/\{\{\s*(db(-\w*)?|d|delete|(?:hang|hold)[- ]?on)\s*(\|(?:\{\{[^{}]*\}\}|[^{}])*)?\}\}\s*/ig, '');
			if (text !== textNoSd && confirm(wgULS('在页面上找到快速删除模板,要移除吗?', '在頁面上找到快速刪除模板,要移除嗎?'))) {
				text = textNoSd;
			}

			var textNoNotMandarin = text.replace(/\{\{\s*(NotMandarin|Notchinese|非中文|非現代漢語|非现代汉语|非現代標準漢語|非现代标准汉语)\s*(\|(?:\{\{[^{}]*\}\}|[^{}])*)?\}\}\s*/ig, '');
			if (text !== textNoNotMandarin && confirm(wgULS('在页面上找到非现代标准汉语模板,要移除吗?', '在頁面上找到非現代標準漢語模板,要移除嗎?'))) {
				text = textNoNotMandarin;
			}

			// Mark the page as patrolled, if wanted
			if (Twinkle.getPref('markXfdPagesAsPatrolled')) {
				pageobj.patrol();
			}

			// Insert tag after short description or any hatnotes
			var wikipage = new Morebits.wikitext.page(text);
			text = wikipage.insertAfterTemplates(tag, Twinkle.hatnoteRegex).getText();

			pageobj.setPageText(text);
			pageobj.setEditSummary(wgULS('页面存废讨论:[[', '頁面存廢討論:[[') + params.logpage + '#' + Morebits.pageNameNorm + ']]' + Twinkle.getPref('summaryAd'));
			pageobj.setTags(Twinkle.getPref('revisionTags'));
			switch (Twinkle.getPref('xfdWatchPage')) {
				case 'yes':
					pageobj.setWatchlist(true);
					break;
				case 'no':
					pageobj.setWatchlistFromPreferences(false);
					break;
				default:
					pageobj.setWatchlistFromPreferences(true);
					break;
			}
			pageobj.save();
		},
		todaysList: function(pageobj) {
			var text = pageobj.getPageText();
			var params = pageobj.getCallbackParameters();
			var type = '';
			var to = '';

			switch (params.xfdcat) {
				case 'vmd':
				case 'vms':
				case 'vmb':
				case 'vmq':
				case 'vmvoy':
				case 'vmv':
					type = 'vm';
					to = params.xfdcat;
					break;
				case 'fwdcsd':
				case 'merge':
					to = params.mergeinto;
					/* Fall through */
				default:
					type = params.xfdcat;
					break;
			}

			var append = true;
			switch (type) {
				case 'fame':
				case 'substub':
				case 'batch':
					var commentText = '<!-- Twinkle: User:' + mw.config.get('wgUserName') + ' 的 ' + type + ' 提刪插入點,請勿變更或移除此行,除非不再於此頁提刪 -->';
					var newText = '===[[:' + Morebits.pageNameNorm + ']]===';
					if (type === 'fame') {
						newText += '\n{{Findsources|' + Morebits.pageNameNorm + '}}';
					}
					if (text.indexOf(commentText) !== -1) {
						text = text.replace(commentText, newText + '\n\n' + commentText);
						pageobj.setPageText(text);
						append = false;
					} else {
						var appendText = '\n{{safesubst:SafeAfdHead}}\n' +
							{
								'fame': '==30天后仍掛有{{tl|notability}}模板的條目==\n' +
									'<span style="font-size:smaller;">(已掛[[template:notability|關注度模板]]30天)</span>',
								'substub': '==到期篩選的小小作品==',
								'batch': '==批量提刪=='
							}[type] + '\n' +
							newText + '\n\n' +
							commentText + '\n' +
							'----\n' +
							':{{删除}}理據:' + Morebits.string.formatReasonText(params.reason) + '\n' +
							'提报以上' + {
							'fame': '<u>关注度不足</u>条目',
							'substub': '<u>小小作品</u>',
							'batch': '頁面'
						}[type] + '的維基人及時間:<br id="no-new-title" />~~~~';
						pageobj.setAppendText(appendText);
					}
					break;
				default:
					pageobj.setAppendText('\n{{subst:DRItem|Type=' + type + '|DRarticles=' + Morebits.pageNameNorm + '|Reason=' + Morebits.string.formatReasonText(params.reason) + (params.fwdcsdreason.trim() !== '' ? '<br>\n轉交理由:' + params.fwdcsdreason : '') + '|To=' + to + '}}~~~~');
					break;
			}

			pageobj.setEditSummary(wgULS('添加[[', '加入[[') + Morebits.pageNameNorm + ']]' + Twinkle.getPref('summaryAd'));
			pageobj.setTags(Twinkle.getPref('revisionTags'));
			switch (Twinkle.getPref('xfdWatchDiscussion')) {
				case 'yes':
					pageobj.setWatchlist(true);
					break;
				case 'no':
					pageobj.setWatchlistFromPreferences(false);
					break;
				default:
					pageobj.setWatchlistFromPreferences(true);
					break;
			}
			pageobj.setCreateOption('recreate');
			if (append) {
				pageobj.append();
			} else {
				pageobj.save();
			}
			Twinkle.xfd.currentRationale = null;  // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
		},
		tryTagging: function (pageobj) {
			var statelem = pageobj.getStatusElement();
			// defaults to /doc for lua modules, which may not exist
			if (!pageobj.exists() && mw.config.get('wgPageContentModel') !== 'Scribunto') {
				statelem.error(wgULS('页面不存在,可能已被删除', '頁面不存在,可能已被刪除'));
				return;
			}

			var text = pageobj.getPageText();

			var xfd = /(?:\{\{([rsaiftcmv]fd|md1|proposed deletion)[^{}]*?\}\})/i.exec(text);
			if (xfd && !confirm(wgULS('删除相关模板{{' + xfd[1] + '}}已被置于页面中,您是否仍想继续提报?', '刪除相關模板{{' + xfd[1] + '}}已被置於頁面中,您是否仍想繼續提報?'))) {
				statelem.error(wgULS('页面已被提交至存废讨论。', '頁面已被提交至存廢討論。'));
				return;
			}

			var copyvio = /(?:\{\{\s*(copyvio)[^{}]*?\}\})/i.exec(text);
			if (copyvio) {
				statelem.error(wgULS('页面中已有著作权验证模板。', '頁面中已有著作權驗證模板。'));
				return;
			}

			Twinkle.xfd.callbacks.afd.taggingArticle(pageobj);

			// Notification to first contributor
			var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'));
			wikipedia_page.setCallbackParameters(pageobj.getCallbackParameters());
			if (mw.config.get('wgPageContentModel') !== 'Scribunto') {
				wikipedia_page.setLookupNonRedirectCreator(true); // Look for author of first non-redirect revision
			}
			wikipedia_page.lookupCreator(Twinkle.xfd.callbacks.afd.main);
		}
	},

	ffd: {
		main: function(pageobj) {
			// this is coming in from lookupCreator...!
			var params = pageobj.getCallbackParameters();
			var initialContrib = pageobj.getCreator();
			params.uploader = initialContrib;

			// Adding discussion
			var wikipedia_page = new Morebits.wiki.page(params.logpage, wgULS('添加讨论到当日列表', '加入討論到當日列表'));
			wikipedia_page.setFollowRedirect(true);
			wikipedia_page.setCallbackParameters(params);
			wikipedia_page.load(Twinkle.xfd.callbacks.ffd.todaysList);

			// Notification to first contributor
			if (params.usertalk) {
				// Disallow warning yourself
				if (initialContrib === mw.config.get('wgUserName')) {
					pageobj.getStatusElement().warn(wgULS('您(' + initialContrib + ')创建了该页,跳过通知', '您(' + initialContrib + ')建立了該頁,跳過通知'));
					return;
				}

				var talkPageName = 'User talk:' + initialContrib;

				Morebits.wiki.flow.check(talkPageName, function () {
					var flowpage = new Morebits.wiki.flow(talkPageName, wgULS('通知页面创建者(' + initialContrib + ')', '通知頁面建立者(' + initialContrib + ')'));
					flowpage.setTopic('文件[[:File:' + mw.config.get('wgTitle') + ']]存废讨论通知');
					flowpage.setContent('{{subst:idw|File:' + mw.config.get('wgTitle') + '|flow=yes}}');
					flowpage.newTopic();
				}, function () {
					var usertalkpage = new Morebits.wiki.page(talkPageName, wgULS('通知页面创建者(' + initialContrib + ')', '通知頁面建立者(' + initialContrib + ')'));
					var notifytext = '\n{{subst:idw|File:' + mw.config.get('wgTitle') + '}}--~~~~';
					usertalkpage.setAppendText(notifytext);
					usertalkpage.setEditSummary('通知:文件[[' + Morebits.pageNameNorm + ']]存废讨论提名' + Twinkle.getPref('summaryAd'));
					usertalkpage.setTags(Twinkle.getPref('revisionTags'));
					usertalkpage.setCreateOption('recreate');
					switch (Twinkle.getPref('xfdWatchUser')) {
						case 'yes':
							usertalkpage.setWatchlist(true);
							break;
						case 'no':
							usertalkpage.setWatchlistFromPreferences(false);
							break;
						default:
							usertalkpage.setWatchlistFromPreferences(true);
							break;
					}
					usertalkpage.setFollowRedirect(true, false);
					usertalkpage.append();
				});
				// add this nomination to the user's userspace log, if the user has enabled it
				if (params.lognomination) {
					Twinkle.xfd.callbacks.addToLog(params, initialContrib);
				}
			// or, if not notifying, add this nomination to the user's userspace log without the initial contributor's name
			} else if (params.lognomination) {
				Twinkle.xfd.callbacks.addToLog(params, null);
			}
		},
		taggingImage: function(pageobj) {
			var text = pageobj.getPageText();
			var params = pageobj.getCallbackParameters();

			pageobj.setPageText('{{ifd|' + Morebits.string.formatReasonText(params.reason) + '|date={{subst:#time:c}}}}\n' + text);
			pageobj.setEditSummary(wgULS('文件存废讨论:[[', '檔案存廢討論:[[') + params.logpage + '#' + Morebits.pageNameNorm + ']]' + Twinkle.getPref('summaryAd'));
			pageobj.setTags(Twinkle.getPref('revisionTags'));
			switch (Twinkle.getPref('xfdWatchPage')) {
				case 'yes':
					pageobj.setWatchlist(true);
					break;
				case 'no':
					pageobj.setWatchlistFromPreferences(false);
					break;
				default:
					pageobj.setWatchlistFromPreferences(true);
					break;
			}
			pageobj.setCreateOption('recreate');  // it might be possible for a file to exist without a description page
			pageobj.save();
		},
		todaysList: function(pageobj) {
			// var text = pageobj.getPageText();
			var params = pageobj.getCallbackParameters();

			pageobj.setAppendText('\n{{subst:IfdItem|Filename=' + mw.config.get('wgTitle') + '|Uploader=' + params.uploader + '|Reason=' + Morebits.string.formatReasonText(params.reason) + '}}--~~~~');
			pageobj.setEditSummary(wgULS('添加[[', '加入[[') + Morebits.pageNameNorm + ']]' + Twinkle.getPref('summaryAd'));
			pageobj.setTags(Twinkle.getPref('revisionTags'));
			switch (Twinkle.getPref('xfdWatchDiscussion')) {
				case 'yes':
					pageobj.setWatchlist(true);
					break;
				case 'no':
					pageobj.setWatchlistFromPreferences(false);
					break;
				default:
					pageobj.setWatchlistFromPreferences(true);
					break;
			}
			pageobj.setCreateOption('recreate');
			pageobj.append(function() {
				Twinkle.xfd.currentRationale = null;  // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
			});
		},
		tryTagging: function (pageobj) {
			var statelem = pageobj.getStatusElement();
			if (!pageobj.exists()) {
				statelem.error(wgULS('页面不存在,可能已被删除', '頁面不存在,可能已被刪除'));
				return;
			}

			var text = pageobj.getPageText();

			var xfd = /(?:\{\{([rsaiftcmv]fd|md1|proposed deletion)[^{}]*?\}\})/i.exec(text);
			if (xfd && !confirm(wgULS('删除相关模板{{' + xfd[1] + '}}已被置于页面中,您是否仍想继续提报?', '刪除相關模板{{' + xfd[1] + '}}已被置於頁面中,您是否仍想繼續提報?'))) {
				statelem.error(wgULS('页面已被提交至存废讨论。', '頁面已被提交至存廢討論。'));
				return;
			}

			Twinkle.xfd.callbacks.ffd.taggingImage(pageobj);

			// Contributor specific edits
			var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'));
			wikipedia_page.setCallbackParameters(pageobj.getCallbackParameters());
			wikipedia_page.setLookupNonRedirectCreator(true); // Look for author of first non-redirect revision
			wikipedia_page.lookupCreator(Twinkle.xfd.callbacks.ffd.main);
		}
	},
	addToLog: function(params, initialContrib) {
		var editsummary = wgULS('记录对[[', '記錄對[[') + Morebits.pageNameNorm + wgULS(']]的存废讨论提名', ']]的存廢討論提名') + Twinkle.getPref('summaryAd');
		var usl = new Morebits.userspaceLogger(Twinkle.getPref('xfdLogPageName'));
		usl.initialText =
			wgULS('这是该用户使用[[WP:TW|Twinkle]]的提删模块做出的[[WP:XFD|存废讨论]]提名列表。\n\n' +
			'如果您不再想保留此日志,请在[[' + Twinkle.getPref('configPage') + '|参数设置]]中关掉,并' +
			'使用[[WP:CSD#O1|CSD O1]]提交快速删除。',
			'這是該使用者使用[[WP:TW|Twinkle]]的提刪模塊做出的[[WP:XFD|存廢討論]]提名列表。\n\n' +
			'如果您不再想保留此日誌,請在[[' + Twinkle.getPref('configPage') + '|偏好設定]]中關掉,並' +
			'使用[[WP:CSD#O1|CSD O1]]提交快速刪除。');
		var xfdCatName;
		switch (params.xfdcat) {
			case 'delete':
				xfdCatName = wgULS('删除', '刪除');
				break;
			case 'merge':
				xfdCatName = wgULS('合并到', '合併到');
				break;
			case 'vmd':
				xfdCatName = wgULS('移动到维基词典', '移動到維基詞典');
				break;
			case 'vms':
				xfdCatName = wgULS('移动到维基文库', '移動到維基文庫');
				break;
			case 'vmb':
				xfdCatName = wgULS('移动到维基教科书', '移動到維基教科書');
				break;
			case 'vmq':
				xfdCatName = wgULS('移动到维基语录', '移動到維基語錄');
				break;
			case 'vmvoy':
				xfdCatName = wgULS('移动到维基导游', '移動到維基導遊');
				break;
			case 'vmv':
				xfdCatName = wgULS('移动到维基学院', '移動到維基學院');
				break;
			case 'fwdcsd':
				xfdCatName = wgULS('转交自快速删除候选', '轉交自快速刪除候選');
				break;
			case 'fame':
				xfdCatName = wgULS('批量关注度提删', '批次關注度提刪');
				break;
			case 'substub':
				xfdCatName = wgULS('批量小小作品提删', '批次小小作品提刪');
				break;
			case 'batch':
				xfdCatName = wgULS('批量其他提删', '批次其他提刪');
				break;
			default:
				xfdCatName = wgULS('文件存废讨论', '檔案存廢討論');
				break;
		}

		// If a logged file is deleted but exists on commons, the wikilink will be blue, so provide a link to the log
		var appendText = '# [[:' + Morebits.pageNameNorm + ']]';
		if (mw.config.get('wgNamespaceNumber') === 6) {
			appendText += '([{{fullurl:Special:Log|page=' + mw.util.wikiUrlencode(mw.config.get('wgPageName')) + '}} ' + wgULS('日志', '日誌') + '])';
		}
		appendText += ':' + xfdCatName + '。';

		if (params.xfdcat === 'fwdcsd') {
			if (params.reason) {
				appendText += "'''原刪除理據''':" + Morebits.string.formatReasonText(params.reason);
			}
			if (params.fwdcsdreason) {
				appendText += "'''轉交理據''':" + Morebits.string.formatReasonText(params.fwdcsdreason);
			}
		} else if (params.xfdcat === 'merge') {
			appendText += '[[:' + params.mergeinto + ']]';
			if (params.reason) {
				appendText += "'''理據''':" + Morebits.string.formatReasonText(params.reason);
			}
		} else {
			appendText += params.reason ? "'''理據''':" + Morebits.string.formatReasonText(params.reason) : '';
		}

		if (initialContrib) {
			appendText += ';通知{{user|' + initialContrib + '}}';
		}
		appendText += ' ~~~~~\n';
		usl.log(appendText, editsummary);
	}
};



Twinkle.xfd.callback.evaluate = function(e) {
	var type = e.target.category.value;
	var usertalk = e.target.notify.checked;
	var reason = e.target.xfdreason.value;
	var fwdcsdreason, xfdcat, mergeinto, noinclude;
	if (type === 'afd') {
		fwdcsdreason = e.target.fwdcsdreason.value;
		noinclude = e.target.noinclude.checked;
		xfdcat = e.target.xfdcat.value;
		mergeinto = e.target.mergeinto.value;
	}
	if (xfdcat === 'merge' && mergeinto.trim() === '') {
		alert(wgULS('请提供合并目标!', '請提供合併目標!'));
		return;
	}

	Morebits.simpleWindow.setButtonsEnabled(false);
	Morebits.status.init(e.target);

	Twinkle.xfd.currentRationale = reason;
	Morebits.status.onError(Twinkle.xfd.printRationale);

	if (!type) {
		Morebits.status.error('错误', '未定义的动作');
		return;
	}

	var wikipedia_page, logpage, lognomination, params;
	var date = new Morebits.date(); // XXX: avoid use of client clock, still used by TfD, FfD and CfD
	switch (type) {

		case 'afd': // AFD
			logpage = 'Wikipedia:頁面存廢討論/記錄/' + date.format('YYYY/MM/DD', 'utc');
			lognomination = Twinkle.getPref('logXfdNominations') && Twinkle.getPref('noLogOnXfdNomination').indexOf(xfdcat) === -1;
			params = { usertalk: usertalk, xfdcat: xfdcat, mergeinto: mergeinto, noinclude: noinclude, reason: reason, fwdcsdreason: fwdcsdreason, logpage: logpage, lognomination: lognomination};

			Morebits.wiki.addCheckpoint();
			// Updating data for the action completed event
			Morebits.wiki.actionCompleted.redirect = logpage;
			Morebits.wiki.actionCompleted.notice = wgULS('提名完成,重定向到讨论页', '提名完成,重新導向到討論頁');

			// Tagging page
			var isScribunto = mw.config.get('wgPageContentModel') === 'Scribunto';
			wikipedia_page = isScribunto ? new Morebits.wiki.page(mw.config.get('wgPageName') + '/doc', wgULS('添加存废讨论模板到模块文件页', '加入存廢討論模板到模組文件頁')) : new Morebits.wiki.page(mw.config.get('wgPageName'), wgULS('添加存废讨论模板到页面', '加入存廢討論模板到頁面'));
			wikipedia_page.setFollowRedirect(false);
			wikipedia_page.setCallbackParameters(params);
			wikipedia_page.load(Twinkle.xfd.callbacks.afd.tryTagging);

			Morebits.wiki.removeCheckpoint();
			break;

		case 'ffd': // FFD
			logpage = 'Wikipedia:檔案存廢討論/記錄/' + date.format('YYYY/MM/DD', 'utc');
			lognomination = Twinkle.getPref('logXfdNominations') && Twinkle.getPref('noLogOnXfdNomination').indexOf('ffd') === -1;
			params = { usertalk: usertalk, reason: reason, logpage: logpage, lognomination: lognomination};

			Morebits.wiki.addCheckpoint();
			// Updating data for the action completed event
			Morebits.wiki.actionCompleted.redirect = logpage;
			Morebits.wiki.actionCompleted.notice = wgULS('提名完成,重定向到讨论页', '提名完成,重新導向到討論頁');

			// Tagging file
			wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), wgULS('添加存废讨论模板到文件描述页', '加入存廢討論模板到檔案描述頁'));
			wikipedia_page.setFollowRedirect(false);
			wikipedia_page.setCallbackParameters(params);
			wikipedia_page.load(Twinkle.xfd.callbacks.ffd.tryTagging);

			Morebits.wiki.removeCheckpoint();
			break;

		default:
			alert('twinklexfd:未定义的类别');
			break;
	}
};


/**
 * 愚人节提删
 */

Twinkle.xfd.aprilfool = function twinklexfdCallback() {
	var Window = new Morebits.simpleWindow(600, 350);
	Window.setTitle('APRIL FOOL');
	Window.setScriptName('Twinkle');
	Window.addFooterLink(wgULS('关于愚人节', '關於愚人節'), 'Wikipedia:愚人節玩笑規範');
	Window.addFooterLink(wgULS('Twinkle帮助', 'Twinkle說明'), 'WP:TW/DOC#xfd');

	var form = new Morebits.quickForm(Twinkle.xfd.aprilfool.evaluate);
	var categories = form.append({
		type: 'select',
		name: 'category',
		label: wgULS('提交类型:', '提交類別:'),
		event: Twinkle.xfd.callback.change_category
	});
	categories.append({
		type: 'option',
		label: wgULS('页面存废讨论', '頁面存廢討論'),
		selected: mw.config.get('wgNamespaceNumber') === 0,  // Main namespace
		value: 'afd'
	});
	categories.append({
		type: 'option',
		label: wgULS('文件存废讨论', '檔案存廢討論'),
		selected: mw.config.get('wgNamespaceNumber') === 6,  // File namespace
		value: 'ffd'
	});
	form.append({
		type: 'checkbox',
		list: [
			{
				label: wgULS('通知还是不通知,这是一个问题', '通知還是不通知,這是一個問題'),
				value: 'notify',
				name: 'notify',
				tooltip: wgULS('无论选还是不选都不通知!', '無論選還是不選都不通知!'),
				checked: true
			}
		]
	}
	);
	form.append({
		type: 'field',
		label: '工作区',
		name: 'work_area'
	});
	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.category.dispatchEvent(evt);
};

Twinkle.xfd.aprilfool.evaluate = function(e) {
	var type = e.target.category.value;
	var reason = e.target.xfdreason.value;
	var xfdcat, mergeinto, noinclude;
	if (type === 'afd') {
		noinclude = e.target.noinclude.checked;
		xfdcat = e.target.xfdcat.value;
		mergeinto = e.target.mergeinto.value;
	}

	Morebits.simpleWindow.setButtonsEnabled(false);
	Morebits.status.init(e.target);

	Twinkle.xfd.currentRationale = reason;
	Morebits.status.onError(Twinkle.xfd.printRationale);

	var wikipedia_page, logpage, params;
	var date = new Morebits.date();

	logpage = 'Wikipedia:頁面存廢和諧討論/記錄/' + date.format('YYYY', 'utc') + '/04/01';
	params = { xfdcat: xfdcat, mergeinto: mergeinto, noinclude: noinclude, reason: reason, logpage: logpage };

	Morebits.wiki.addCheckpoint();
	// Updating data for the action completed event
	Morebits.wiki.actionCompleted.redirect = logpage;
	Morebits.wiki.actionCompleted.notice = wgULS('提名完成,重定向到讨论页', '提名完成,重新導向到討論頁');

	// Tagging file
	wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), wgULS('假装添加存废讨论模板到页面', '假裝加入存廢討論模板到頁面'));
	wikipedia_page.setFollowRedirect(false);
	wikipedia_page.setCallbackParameters(params);
	wikipedia_page.load(Twinkle.xfd.aprilfool.tryTagging);

	Morebits.wiki.removeCheckpoint();
};

Twinkle.xfd.aprilfool.todaysList = function(pageobj) {
	// var text = pageobj.getPageText();
	var params = pageobj.getCallbackParameters();
	var type = '';
	var to = '';

	switch (params.xfdcat) {
		case 'vmd':
		case 'vms':
		case 'vmb':
		case 'vmq':
		case 'vmvoy':
		case 'vmv':
			type = 'vm';
			to = params.xfdcat;
			break;
		case 'fwdcsd':
		case 'merge':
			to = params.mergeinto;
			/* Fall through */
		default:
			type = params.xfdcat;
			break;
	}

	pageobj.setAppendText('\n{{subst:DRItem|Type=' + type + '|DRarticles=' + Morebits.pageNameNorm + '|Reason=' + Morebits.string.formatReasonText(params.reason) + '|To=' + to + '}}~~~~');
	pageobj.setEditSummary('添加[[' + Morebits.pageNameNorm + ']]' + Twinkle.getPref('summaryAd'));
	pageobj.setTags(Twinkle.getPref('revisionTags'));
	switch (Twinkle.getPref('xfdWatchDiscussion')) {
		case 'yes':
			pageobj.setWatchlist(true);
			break;
		case 'no':
			pageobj.setWatchlistFromPreferences(false);
			break;
		default:
			pageobj.setWatchlistFromPreferences(true);
			break;
	}
	pageobj.setCreateOption('recreate');
	pageobj.append();
	Twinkle.xfd.currentRationale = null;  // any errors from now on do not need to print the rationale, as it is safely saved on-wiki
};

Twinkle.xfd.aprilfool.tryTagging = function (pageobj) {
	var statelem = pageobj.getStatusElement();
	var params = pageobj.getCallbackParameters();
	if (!pageobj.exists()) {
		statelem.error(wgULS('页面不存在,可能已被删除', '頁面不存在,可能已被刪除'));
		return;
	}

	var text = pageobj.getPageText();

	var xfd = /(?:\{\{([rsaiftcmv]fd|md1|proposed deletion)[^{}]*?\}\})/i.exec(text);
	if (xfd && !confirm(wgULS('删除相关模板{{' + xfd[1] + '}}已被置于页面中,您是否仍想继续提报?', '刪除相關模板{{' + xfd[1] + '}}已被置於頁面中,您是否仍想繼續提報?'))) {
		statelem.error(wgULS('页面已被提交至存废讨论。', '頁面已被提交至存廢討論。'));
		return;
	}

	var copyvio = /(?:\{\{\s*(copyvio)[^{}]*?\}\})/i.exec(text);
	if (copyvio) {
		statelem.error(wgULS('页面中已有著作权验证模板。', '頁面中已有著作權驗證模板。'));
	}

	var wikipedia_page = new Morebits.wiki.page(params.logpage, wgULS('添加讨论到当日列表', '加入討論到當日列表'));
	wikipedia_page.setFollowRedirect(true);
	wikipedia_page.setCallbackParameters(params);
	wikipedia_page.load(Twinkle.xfd.aprilfool.todaysList);
};

Twinkle.addInitCallback(Twinkle.xfd, 'xfd');
})(jQuery);


// </nowiki>