Saltar para o conteúdo

Usuário:ChristianH/friendlytag.js

Origem: Wikipédia, a enciclopédia livre.

Nota: Depois de publicar, poderá ter de contornar a cache do seu navegador para ver as alterações.

  • Firefox / Safari: Pressione Shift enquanto clica Recarregar, ou pressione Ctrl-F5 ou Ctrl-R (⌘-R no Mac)
  • Google Chrome: Pressione Ctrl-Shift-R (⌘-Shift-R no Mac)
  • Edge: Pressione Ctrl enquanto clica Recarregar, ou pressione Ctrl-F5.
// <nowiki>
// If FriendlyConfig aint exist.
if( typeof( FriendlyConfig ) == 'undefined' ) {
	FriendlyConfig = {};
}

/**
 FriendlyConfig.summaryAd ( string )
 If ad should be added or not to summary, default [[WP:FRIENDLY|Friendly]]
 */
if( typeof( FriendlyConfig.summaryAd ) == 'undefined' ) {
	FriendlyConfig.summaryAd = " usando [[WP:FRIENDLY|Friendly]]";
}

/**
 FriendlyConfig.groupByDefault ( boolean )
 */
if( typeof( FriendlyConfig.groupByDefault ) == 'undefined' ) {
	FriendlyConfig.groupByDefault = true;
}

/**
 FriendlyConfig.watchTaggedPages ( boolean )
 */
if( typeof( FriendlyConfig.watchTaggedPages ) == 'undefined' ) {
	FriendlyConfig.watchTaggedPages = true;
}

/**
 FriendlyConfig.markTaggedPagesAsMinor ( boolean )
 */
if( typeof( FriendlyConfig.markTaggedPagesAsMinor ) == 'undefined' ) {
	FriendlyConfig.markTaggedPagesAsMinor = true;
}

/**
 FriendlyConfig.markTaggedPagesAsPatrolled ( boolean )
 */
if( typeof( FriendlyConfig.markTaggedPagesAsPatrolled ) == 'undefined' ) {
	FriendlyConfig.markTaggedPagesAsPatrolled = true;
}

var isRedirect = false;

function friendlytag() {
	if( QueryString.exists( 'redirect' ) && QueryString.get( 'redirect' ) == 'no' && !QueryString.exists( 'rcid' ) ) {
		isRedirect = true;
		mw.util.addPortletLink( 'p-cactions', "javascript:friendlytag.callback()", "Tag", "friendly-tag", "Tag redirect", "");
	} else if( wgNamespaceNumber != 0 || wgCurRevisionId == false ) {
		return;
	} else {
		mw.util.addPortletLink( 'p-cactions', "javascript:friendlytag.callback()", "Tag", "friendly-tag", "Tag article", "");
	}
}
$(friendlytag);

friendlytag.callback = function friendlytagCallback( uid ) {
	var Window = new SimpleWindow( 600, 400 );
	var form = new QuickForm( friendlytag.callback.evaluate );

	if( !isRedirect ) {
		Window.setTitle( "Article maintenance tagging" );

		form.append( {
				type: 'checkbox',
				list: [
					{
						label: 'Group into {{article issues}} if possible',
						value: 'group',
						name: 'group',
						tooltip: 'If applying three or more templates supported by {{article issues}} and this box is checked, all supported templates will be grouped into a single {{article issues}} template.',
						checked: FriendlyConfig.groupByDefault
					}
				]
			}
		);

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

		form.append( { type:'header', label:'Predefinições de manutenção' } );
		form.append( { type:'checkbox', name: 'maintenance', list: friendlytag.maintenanceList } );

		form.append( { type:'header', label:'Problem templates' } );
		form.append( { type:'checkbox', name: 'problem', list: friendlytag.problemList } );

		form.append( { type:'header', label:'Notice templates' } );
		form.append( { type:'checkbox', name: 'notice', list: friendlytag.noticeList } );

		if( typeof( FriendlyConfig.customTagList ) == 'object' ) {
			form.append( { type:'header', label:'Custom templates' } );
			form.append( { type: 'checkbox', name: 'custom', list: FriendlyConfig.customTagList } );
		}
	} else {
		Window.setTitle( "Redirect tagging" );

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

		form.append( { type:'header', label:'Spelling, misspelling, tense and capitalization templates' } );
		form.append( { type:'checkbox', name: 'spelling', list: friendlytag.spellingList } );

		form.append( { type:'header', label:'Alternative name templates' } );
		form.append( { type:'checkbox', name: 'alternative', list: friendlytag.alternativeList } );

		form.append( { type:'header', label:'Miscellaneous and administrative redirect templates' } );
		form.append( { type:'checkbox', name: 'administrative', list: friendlytag.administrativeList } );
	}

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

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

friendlytag.maintenanceList = [
	{
		label: '\{\{sem-cat\}\}: artigo necessita de adição de categorias.',
		value: 'sem-cat'
	},
	{
		label: '\{\{reciclagem\}\}: artigo necessita ser reescrito',
		value: 'reciclagem'
	},
	{
		label: '\{\{corrigir\}\}: artigo necessita de uma correção textual e gramatical',
		value: 'corrigir'
	},
	{
		label: '\{\{artigo órfão\}\}: o artigo não possui ligações afluentes',
		value: 'ártigo órfão'
	},
	{
		label: '\{\{revisão\}\}: artigo necessita de uma revisão de alguém especializado',
		value: 'revisão'
	},
	{
		label: '\{\{expandir\}\}: artigo necessita de expansão',
		value: 'expandir' 
	},
	{
		label: '\{\{COI\}\}: algum editor tem conflito de interesse no artigo',
		value: 'COI'
	},
	{
		label: '\{\{wikificar\}\}: algum necessita de wikificação',
		value: 'wikificar'
	},
	{
		label: '\{\{Suspeito1\}\}: artigo é suspeito de possui violação de direitos autorais',
		value: 'suspeito1'
	},
	{
		label: '\{\{publicidade\}\}: artigo escrito em forma publicitária',
		value: 'publicidade'
	},
	{
		label: '\{\{parcial\}\}: artigo contém passagens que não respeitam o princípio da imparcialidade',
		value: 'parcial'
	},
	{
		label: '\{\{não-enciclopédico\}\}: artigo tem natureza de não ser enciclopédico',
		value: 'não-enciclopédico'
	},
	{
		label: '\{\{controverso\}\}: artigo está controverso devido a disputa de conteúdo',
		value: 'controverso'
	},
	{
		label: '\{\{sem-fontes\}\}: artigo não cita nenhuma fonte ou referência',
		value: 'sem-fontes'
	},
	{
		label: '\{\{artigo longo\}\}: para artigos que estão ficandos grandes demais',
		value: 'artigo longo'
	},
	{
		label: '\{\{contextualizar\}\}: para artigos e seções que carecem de contexto',
		value: 'contextualizar'
	},
];


friendlytag.noticeList = [
	{
		label: '\{\{atual\}\}: o artigo documenta um evento atual',
		value: 'atual',
		subgroup: {
			name: 'current',
			type: 'select',
			list: [
				{
					label: "\{\{evento atual\}\}: artigo documenta um evento atual",
					value: "evento atual"
				},
				{
					label: "\{\{telenovela atual\}\}: artigo documenta uma telenovela atual",
					value: "telenovela atual"
				},
				{
					label: "\{\{esportes atual\}\}: artigo documenta sobre um evento atual relacionado ao desporto",
					value: "esportes atual"
				},
				{
					label: "\{\{clima atual\}\}: artigo documenta um evento atual relacionado ao clima",
					value: "clima atual"
				},
				{
					label: "\{\{eleição atual\}\}: artigo documenta sobre uma eleição atual",
					value: "eleição atual"
				},
				{
					label: "\{\{guerra atual\}\}: artigo documenta sobre uma guerra atual",
					value: "guerra atual"
				},
				{
					label: "\{\{missão espacial atual\}\}: artigo documenta sobre uma missão especial atual",
					value: "missão especial atual"
				},
				{
					label: "\{\{morte recente\}\}: o artigo é sobre uma pessoa que faleceu recentemente",
					value: "morte recente"
				}
			]
		}
	},
	{
		label: '\{\{em construção\}\}: artigo está sendo construído por uma ou mais pessoas',
		value: 'em construção' }

	{
		label: '\{\{em reforma\}\}: artigo está sendo reformulado por uma ou mais pessoas',
		value: 'em reforma' }
];


// Set to true if template can be grouped into {{articleissues}}
friendlytag.groupHash = {
	'sem-cat': true,
        'reciclagem': true
        'corrigir': true
        'artigo órfão': true
        'revisão': true
        'expandir': false
        'COI': true
        'wikificar': true
        'Suspeito1': true
        'publicidade': true
        'parcial': true
        'reciclagem': true
        'não-enciclopédico': true
        'controverso': true
        'sem-fontes': false
        'artigo longo': false
        'contextualizar': true
}

friendlytag.callbacks = {
	main: function( self ) {
		var form = self.responseXML.getElementById( 'editform' );
		var tagRe, text = '', summaryText = 'Added';
		var tags = new Array(), groupableTags = new Array();

		if( !isRedirect ) {
			// Check for preexisting tags and separate tags into groupable and non-groupable arrays
			Status.info( 'Info', 'Checking for preexisting tags on the article' );
			for( var i = 0; i < self.params.tags.length; i++ ) {
				tagRe = new RegExp( '(\\{\\{' + self.params.tags[i] + '(\\||\\}\\}))', 'im' );
				if( !tagRe.exec( form.wpTextbox1.value ) ) {
					if( friendlytag.groupHash[ self.params.tags[i] ] ) {
						groupableTags = groupableTags.concat( self.params.tags[i] );
					} else {
						tags = tags.concat( self.params.tags[i] );
					}
				} else {
					Status.info( 'Info', 'Found \{\{' + self.params.tags[i]
						+ '\}\} on the article already...excluding' );
				}
			}

			if( self.params.group && groupableTags.length >= 3 ) {
				Status.info( 'Info', 'Grouping supported tags into \{\{article issues\}\}' );

				groupableTags.sort();
				text += '\{\{article issues|article=yes';
				summaryText += ' \{\{[[Template:article issues|article issues]]\}\} with parameters';
				for( var i = 0; i < groupableTags.length; i++ ) {
					text += '|' + groupableTags[i]
					+ '=\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}';

					if( i == (groupableTags.length - 1) ) {
						summaryText += ' and';
					} else if ( i < (groupableTags.length - 1) && i != 0 ) {
						summaryText += ',';
					}
					summaryText += ' ' + groupableTags[i];
				}
				text += '\}\}\n';
			} else {
				tags = tags.concat( groupableTags );
			}
		} else {
			// Check for preexisting tags
			Status.info( 'Info', 'Checking for preexisting tags on the redirect' );
			for( var i = 0; i < self.params.tags.length; i++ ) {
				tagRe = new RegExp( '(\\{\\{' + self.params.tags[i] + '(\\||\\}\\}))', 'im' );
				if( !tagRe.exec( form.wpTextbox1.value ) ) {
					tags = tags.concat( self.params.tags[i] );
				} else {
					Status.info( 'Info', 'Found \{\{' + self.params.tags[i]
						+ '\}\} on the redirect already...excluding' );
				}
			}
		}

		tags.sort();
		for( var i = 0; i < tags.length; i++ ) {
			if( tags[i] == 'uncategorized' || tags[i] == 'catimprove' ) {
				form.wpTextbox1.value += '\n\n\{\{' + tags[i]
				+ '|date=\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}\}\}';
			} else {
				if( tags[i] == 'globalize' ) {
					text += '\{\{' + self.params.globalizeSubcategory;
				} else if( tags[i] == 'current' ) {
					text += '\{\{' + self.params.currentSubcategory;
				} else {
					text += ( isRedirect ? '\n' : '' ) + '\{\{' + tags[i];
				}

				if( tags[i] == 'notability' && self.params.notabilitySubcategory != 'none' ) {
					text += '|' + self.params.notabilitySubcategory;
				}
				
				if( tags[i] == 'do-attempt' ) {
					text += '|att=\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}\}\}\n';
				} else {
					text += isRedirect ? '\}\}' : '|date=\{\{subst:CURRENTMONTHNAME\}\} \{\{subst:CURRENTYEAR\}\}\}\}\n';
				}
			}

			if( i == (tags.length - 1) && ( i > 0 || groupableTags.length > 3 ) ) {
				summaryText += ' and';
			} else if ( i < (tags.length - 1) && ( i != 0 || groupableTags.length > 3 ) ) {
				summaryText += ',';
			}

			summaryText += ' \{\{[[Template:';
			if( tags[i] == 'globalize' ) {
				summaryText += self.params.globalizeSubcategory + '|' + self.params.globalizeSubcategory;			
			} else if( tags[i] == 'current' ) {
				summaryText += self.params.currentSubcategory + '|' + self.params.currentSubcategory;
			} else {
				summaryText += tags[i] + '|' + tags[i];
			}
			summaryText += ']]\}\}';
		}

		if( !isRedirect ) {
			text += form.wpTextbox1.value;
		} else {
			text = form.wpTextbox1.value + text;
		}
		summaryText += ' tag' + ( ( tags.length + ( groupableTags.length > 3 ? 1 : 0 ) ) > 1 ? 's' : '' )
		+ ' to ' + ( isRedirect ? 'redirect.' : 'article.' ) + FriendlyConfig.summaryAd;

		var postData = {
			'wpMinoredit': FriendlyConfig.markTaggedPagesAsMinor ? 1 : undefined,
			'wpWatchthis': form.wpWatchthis.checked ? 1 : (FriendlyConfig.watchTaggedPages ? 1 : undefined),
			'wpStarttime': form.wpStarttime.value,
			'wpEdittime': form.wpEdittime.value,
			'wpAutoSummary': form.wpAutoSummary.value,
			'wpEditToken': form.wpEditToken.value,
			'wpSummary': summaryText,
			'wpTextbox1': text
		};

		self.post( postData );
		
		if( FriendlyConfig.markTaggedPagesAsPatrolled && self.params.rcid != '' ) {
			var query = {
				'title': wgPageName,
				'action': 'markpatrolled',
				'rcid': self.params.rcid
			};

			var wikipedia_wiki = new Wikipedia.wiki( 'Marking page as patrolled', query );
			wikipedia_wiki.post();
		}
	}
}

friendlytag.callback.evaluate = function friendlytagCallbackEvaluate(e) {
	var form = e.target;
	if( isRedirect ) {
		var tags = form.getChecked( 'administrative' ).concat( form.getChecked( 'alternative' ) ).concat( form.getChecked( 'spelling' ) );
	} else {
		if( typeof( FriendlyConfig.customTagList ) == 'object' ) {
			var tags = form.getChecked( 'notice' ).concat( form.getChecked( 'problem' ) ).concat( form.getChecked( 'maintenance' ) ).concat( form.getChecked( 'custom' ) );
		} else {
			var tags = form.getChecked( 'notice' ).concat( form.getChecked( 'problem' ) ).concat( form.getChecked( 'maintenance' ) );
		}
		var globalizeSubcategory = form.getChecked( 'problem.globalize' );
		var notabilitySubcategory = form.getChecked( 'problem.notability' );
		var currentSubcategory = form.getChecked( 'notice.current' );
	}
	var params;

	if( tags.length == 0 ) {
		alert( 'You must select at least one tag!' );
		return;
	}
	if( !isRedirect ) {
		params = {
			tags: tags,
			group: form.group.checked,
			globalizeSubcategory: globalizeSubcategory ? globalizeSubcategory[0] : null,
			notabilitySubcategory: notabilitySubcategory ? notabilitySubcategory[0] : null,
			currentSubcategory: currentSubcategory ? currentSubcategory[0] : null,
			rcid: QueryString.exists( 'rcid' ) ? QueryString.get( 'rcid' ) : ''
		}
	} else {
		params = {
			tags: tags,
			rcid: QueryString.exists( 'rcid' ) ? QueryString.get( 'rcid' ) : ''
		}
	}

	Status.init( form );

	var query = { 
		'title': wgPageName, 
		'action': 'submit'
	};
	Wikipedia.actionCompleted.redirect = wgPageName;
	Wikipedia.actionCompleted.notice = "Tagging complete, reloading article in some seconds";
	var wikipedia_wiki = new Wikipedia.wiki( 'Article modification', query, friendlytag.callbacks.main );
	wikipedia_wiki.params = params;
	wikipedia_wiki.get();
}
// </nowiki>