미디어위키:Gadget-twinkleprod.js

// 
(function($) {
/ *************************************** *** twinkleprod.js: PROD module
*************************************** * Mode of invocation:     Tab ("PROD")- Active on:              Existing articles, files, books which are not redirects,-                         and user pages in :Category:Wikipedia books (user books)
*/
Twinkle.prod = function twinkleprod() {
	/* 기능 비활성화 : 아직 준비 안 됨 (2020-08-12) */
	if (true) {
		return;
	}
	if (((0, 6, 108.indexOf(mw.config.get('wgNamespaceNumber')) === -1) && (mw.config.get('wgNamespaceNumber') !== 2 
mw.config.get('wgCategories').indexOf('Wikipedia books (user books)') === -1))
		

mw.config.get('wgCurRevisionId') 
Morebits.wiki.isPageRedirect()) {
		return;
	}
	Twinkle.addPortletLink(Twinkle.prod.callback, 'PROD', 'tw-prod', 'Propose deletion via WP:PROD');
};
// Used in edit summaries, for comparisons, etc.
var namespace;
Twinkle.prod.callback = function twinkleprodCallback() {
	Twinkle.prod.defaultReason = Twinkle.getPref('prodReasonDefault');
	switch (mw.config.get('wgNamespaceNumber')) {
		case 0:
			namespace = 'article';
			break;
		case 6:
			namespace = 'file';
			break;
		case 2:
		case 108:
			namespace = 'book';
			break;
		// no default
	}
	var Window = new Morebits.simpleWindow(800, 410);
	Window.setTitle('Proposed deletion (PROD)');
	Window.setScriptName('Twinkle');
	var form = new Morebits.quickForm(Twinkle.prod.callback.evaluate);
	if (namespace === 'article') {
		Window.addFooterLink('Proposed deletion policy', 'WP:PROD');
		Window.addFooterLink('BLP PROD policy', 'WP:BLPPROD');
	} else if (namespace === 'file') {
		Window.addFooterLink('Proposed deletion policy', 'WP:PROD');
	} else { // if book
		Window.addFooterLink('Proposed deletion (books) policy', 'WP:BOOKPROD');
	}
	var field = form.append({
		type: 'field',
		label: 'PROD type',
		id: 'prodtype_fieldset'
	});
	field.append({
		type: 'radio',
		name: 'prodtype',
		event: Twinkle.prod.callback.prodtypechanged,
		list: 
			{
				label: 'PROD (proposed deletion)',
				value: 'prod',
				checked: true,
				tooltip: 'Normal proposed deletion, per WP:PROD'
			},
			{
				label: 'BLP PROD (proposed deletion of unsourced BLPs)',
				value: 'prodblp',
				tooltip: 'Proposed deletion of new, completely unsourced biographies of living persons, per WP:BLPPROD'
			}
		
	});
	// Placeholder fieldset to be replaced in Twinkle.prod.callback.prodtypechanged
	form.append({
		type: 'field',
		name: 'parameters'
	});
	Window.addFooterLink('Twinkle help', 'WP:TW/DOC#prod');
	form.append({ type: 'submit', label: 'Propose deletion' });
	var result = form.render();
	Window.setContent(result);
	Window.display();
	// Hide fieldset for File and Book PROD types since only normal PROD is allowed
	if (namespace !== 'article') {
		$(result).find('#prodtype_fieldset').hide();
	}
	// Fake a change event on the first prod type radio, to initialize the type-dependent controls
	var evt = document.createEvent('Event');
	evt.initEvent('change', true, true);
	result.prodtype0.dispatchEvent(evt);
};
Twinkle.prod.callback.prodtypechanged = function(event) {
	// prepare frame for prod type dependant controls
	var field = new Morebits.quickForm.element({
		type: 'field',
		label: 'Parameters',
		name: 'parameters'
	});
	// create prod type dependant controls
	switch (event.target.values) {
		case 'prod':
			field.append({
				type: 'checkbox',
				list: 
					{
						label: 'Notify page creator if possible',
						value: 'notify',
						name: 'notify',
						tooltip: "A notification template will be placed on the creator's talk page if this is true.",
						checked: true
					}
				
			});
			field.append({
				type: 'textarea',
				name: 'reason',
				label: 'Reason for proposed deletion:',
				value: Twinkle.prod.defaultReason
			});
			break;
		case 'prodblp':
			// first, remember the prod value that the user entered in the textarea, in case they want to switch back. We can abuse the config field for that.
			if (event.target.form.reason) {
				Twinkle.prod.defaultReason = event.target.form.reason.value;
			}
			field.append({
				type: 'checkbox',
				list: 
					{
						label: 'Notify page creator if possible',
						value: 'notify',
						name: 'notify',
						tooltip: 'Creator of article has to be notified.',
						checked: true,
						disabled: true
					}
				
			});
			// temp warning, can be removed down the line once BLPPROD is more established. Amalthea, May 2010.
			var boldtext = document.createElement('b');
			boldtext.appendChild(document.createTextNode('Please note that only unsourced biographies of living persons are eligible for this tag, narrowly construed.'));
			field.append({
				type: 'div',
				label: boldtext
			});
			break;
		default:
			break;
	}
	event.target.form.replaceChild(field.render(), $(event.target.form).find('fieldsetname="parameters"')0);
};
Twinkle.prod.callbacks = {
	checkpriors: function(apiobj) {
		var xmlDoc = apiobj.responseXML;
		var statelem = apiobj.statelem;
		var params = apiobj.params;
		// Check talk page for templates indicating prior XfD or PROD
		var numTemplates = $(xmlDoc).find('templates tl').length;
		if (numTemplates) {
			var template = $(xmlDoc).find('templates tl')0.getAttribute('title');
			if (numTemplates === 1 && template === 'Template:Old prod') {
				params.oldProdPresent = true; // Mark for reference later, when deciding if to endorse
			// if there are multiple templates, at least one of them would be a prior xfd template
			} else {
				statelem.warn('Previous XfD template found on talk page, aborting procedure');
				return;
			}
		}
		var ts = new Morebits.wiki.page(mw.config.get('wgPageName'));
		ts.setFollowRedirect(true);  // for NPP, and also because redirects are ineligible for PROD
		ts.setCallbackParameters(params);
		ts.setLookupNonRedirectCreator(true); // Look for author of first non-redirect revision
		ts.lookupCreation(Twinkle.prod.callbacks.creationInfo);
	},
	creationInfo: function(pageobj) {
		var params = pageobj.getCallbackParameters();
		params.initialContrib = pageobj.getCreator();
		params.creation = pageobj.getCreationTimestamp();
		Morebits.wiki.actionCompleted.redirect = mw.config.get('wgPageName');
		Morebits.wiki.actionCompleted.notice = 'Tagging complete';
		var wikipedia_page = new Morebits.wiki.page(mw.config.get('wgPageName'), 'Tagging page');
		wikipedia_page.setFollowRedirect(true);  // for NPP, and also because redirects are ineligible for PROD
		wikipedia_page.setCallbackParameters(params);
		wikipedia_page.load(Twinkle.prod.callbacks.main);
	},
	main: function(pageobj) {
		var statelem = pageobj.getStatusElement();
		if (!pageobj.exists()) {
			statelem.error("It seems that the page doesn't exist. Perhaps it has already been deleted.");
			return;
		}
		var text = pageobj.getPageText();
		var params = pageobj.getCallbackParameters();
		// Check for already existing deletion tags
		var tag_re = /