Utilizator:Anneto/Twinkle5.js

De la Wikipedia, enciclopedia liberă

Notă: După salvare, trebuie să treceți peste cache-ul browser-ului pentru a vedea modificările.

  • Mozilla, Google Chrome, Safari, Konqueror: țineți apăsat Shift în timp ce apăsați butonul Reload (sau apăsați Ctrl-Shift-R).
  • Internet Explorer: apăsați Ctrl-F5.
  • Opera: apăsați F5.
function twinkleprotect() {
    if( wgNamespaceNumber < 0 ) {
		return;
	}
 
	if( userIsInGroup( 'sysop' ) ) {
		twAddPortletLink( "javascript:twinkleprotect.callback()", "PP", "tw-rpp", "Protejare pagină", ""); 
	} else if (<noinclude>[[Categorie:Utilizator:Anneto]]</noinclude>twinkleConfigExists) {
		twAddPortletLink( "javascript:twinkleprotect.callback()", "CPP", "tw-rpp", "Cerere protejare pagină", ""); 
	}
	else
	{
		twAddPortletLink( 'javascript:alert("Your account is too new to use Twinkle.");', 'CPP', 'tw-rpp', 'Cerere protejare pagină', ''); 
	}
}
window.TwinkleInit = (window.TwinkleInit || []).concat(twinkleprotect); //schedule initializer 
 
twinkleprotect.callback = function twinkleprotectCallback() {
	var Window = new SimpleWindow( 600, 400 );
	Window.setTitle( "Protejarea paginilor" );
	var form = new QuickForm( twinkleprotect.callback.evaluate );
	if( userIsInGroup( 'sysop' ) ) {
		form.append( {
				type: 'checkbox',
				name: 'request_only',
				event: twinkleprotect.callback.disabledefaults,
				list: [
					{
						label: 'Cerere protejare',
						value: 'request_only',
						tooltip: 'Dacă doriți să cereți protejarea paginii prin WP:CPP în loc s-o protejați dumneavoastră.'
					}
				]
			} );
	}
	form.append( {
			type: 'select',
			name: 'category',
			label: 'Tipul protejării: ',
			event: twinkleprotect.callback.disabledefaults,
			list: [
				{
					label: 'Protejare completă',
					list: [
						{ label: 'Generic', value: 'pp-protejat' },
						{ label: 'Dispută', selected: wgCurRevisionId != false, value: 'pp-dispută' },
						{ label: 'Vandalism', value: 'pp-vandalism' },
						{ label: 'Format foarte folosit', value: 'pp-template' },
						{ label: 'Pagina de discuție a unui user blocat', value: 'pp-usertalk' }
					]
				},
				{
					label: 'Semi-protejare',
					list: [
						{ label: 'Generic', value: 'pp-semi-protected' },
						{ label: 'Vandalism', value: 'pp-semi-vandalism' },
						{ label: 'Format foarte folosit', value: 'pp-semi-template' },
						{ label: 'Pagina de discuție a unui user blocat', value: 'pp-semi-usertalk' },
						{ label: 'Țintă roboți de spam', value: 'pp-semi-spambot' }
					]
				},
				{
					label: 'Altele',
					list: [
						{ label: 'Protejat la mutare', value: 'pp-mutare' },
						{ label: 'Create-protection', selected: wgCurRevisionId == false , value: 'pp-create' },
						{ label: 'Deprotejare', value: 'unprotect' }
					]
				}
			]
		} );
	var flags = form.append( {
			type: 'field',
			label: 'Opțiuni'
		} );
 
	flags.append( {
			type: 'checkbox',
			list: [
				{
					name: 'noinclude',
					label: 'Învelește cu <noinclude>',
					tooltip: 'Va cuprinde formatul în <noinclude>, pentru a nu fi transclus',
					disabled:!userIsInGroup( 'sysop' ),
					checked:(wgNamespaceNumber==10),
					adminonly: true
				},
				{ 
					name: 'small',
					label: 'Iconiță',
					tooltip: ' Va folosi |small=yes pentru format, și se va afișa doar un „lacăt”',
					disabled:!userIsInGroup( 'sysop' ),
					adminonly: true
				},
				{
					name: 'cascade',
					label: 'Protejare în cascadă',
					tooltip: ' Protejarea în cascadă va proteja și paginile incluse în aceasă pagină'
				}
			]
		} );
 
	if( userIsInGroup( 'sysop' ) ) {
		form.append( {
				type: 'select',
				name: 'expiry',
				label: 'Expirare: ',
				list: [
					{ label: '1 oră', value: '1 hour' },
					{ label: '2 ore', value: '2 hours' },
					{ label: '3 ore', value: '3 hours' },
					{ label: '6 ore', value: '6 hours' },
					{ label: '12 ore', value: '12 hours' },
					{ label: '1 zi', value: '1 day' },
					{ label: '2 zile', value: '2 days' },
					{ label: '3 zile', value: '3 days' },
					{ label: '4 zile', value: '4 days' },
					{ label: '5 zile', value: '5 days' },
					{ label: '6 zile', value: '6 days' },
					{ label: '1 săptămână', value: '1 week' },
					{ label: '2 săptămână', value: '2 weeks' },
					{ label: '1 lună', value: '1 month' },
					{ label: '2 luni', value: '2 months' },
					{ label: '3 luni', value: '3 months' },
					{ label: '6 luni', value: '6 months' },
					{ label: '1 an', value: '1 year' },
					{ label: 'infinit', selected: true, value:'indefinite' }
				]
			} );
	} else {
		form.append( {
				type: 'select',
				name: 'expiry',
				label: 'Expirare: ',
				list: [
					{ label: 'temporar', value: 'temporary' },
					{ label: 'infinit', value: 'indefinite' },
					{ label: '', selected: true, value:'' }
				]
			} );
	}
	form.append( {
			type: 'textarea',
			name: 'reason',
			label: 'Motiv: '
		} );
	form.append( { type:'submit' } );
	var result = form.render();
	Window.setContent( result );
	Window.display();
}
 
 
twinkleprotect.callback.disabledefaults = function twinkleprotectCallbackDisableDefaults(e) {
	var root = e.target.form;
	if( e.target.value == 'unprotect' ) {
		root.noinclude.disabled = true;
		root.cascade.disabled = true;
		root.expiry.disabled = true;
		root.small.disabled = true;
	} else {
		root.noinclude.disabled = true;
		root.cascade.disabled = false;
		root.expiry.disabled = false;
		root.small.disabled = true;
		if( userIsInGroup( 'sysop' ) && !root.request_only.checked ) 
                {
			root.small.disabled = false;
			root.noinclude.disabled = false;
		}
	}
 
	if( /template/.test( e.target.value ) ) {
		root.noinclude.checked = true;
		root.expiry.disabled = true;
	} else {
		root.noinclude.checked = false;
	}
 
}
 
twinkleprotect.callback.evaluate = function twinkleprotectCallbackEvaluate(e) {
	var form = e.target;
 
	var params = {
		noinclude: form.noinclude.checked,
		cascade: form.cascade.checked,
		small: form.small.checked,
		reason: form.reason.value,
		expiry: form.expiry.value,
		type: form.category.value
	}
 
	if( userIsInGroup( 'sysop') ) {
		var request_only = form.request_only.checked;
		if( request_only && params.expiry != 'indefinite' ) {
			params.expiry = 'temporary';
		}
	}
 
	Status.init( form );
 
	if( userIsInGroup( 'sysop' ) && ! request_only ) {
 
		var edit, move, tag = params.type, reason, create = '';
		switch( tag ) {
		case 'pp-dispută':
			edit = 'sysop';
			move = 'sysop';
			reason = 'Protejare completă: dispută';
			break;
		case 'pp-vandalism':
			edit = 'sysop';
			move = 'sysop';
			reason = 'Protejare completă: vandalism';
			break;
		case 'pp-template':
			edit = 'sysop';
			move = 'sysop';
			reason = 'Protejare completă: format foarte folosit';
			break;
		case 'pp-usertalk':
			edit = 'sysop';
			move = 'sysop';
			reason = 'Protejare completă: pagina de discuții a unui utilizator blocat';
			break;
		case 'pp-protejat':
			edit = 'sysop';
			move = 'sysop';
			if( params.reason ) {
				tag += '|motiv=' + params.reason;
				params.reason = undefined;
			}
			reason = 'Full protection';
			break;
		case 'pp-semi-vandalism':
			edit = 'autoconfirmed';
			move = 'autoconfirmed';
			reason = 'Semi-protejare: vandalism';
			break;
		case 'pp-semi-usertalk':
			edit = 'autoconfirmed';
			move = 'autoconfirmed';
			reason = 'Semi-protejare: pagina de discuții a unui utilizator blocat';
			break;
		case 'pp-semi-template':
			edit = 'autoconfirmed';
			move = 'autoconfirmed';
			reason = 'Semi-protejare: format foarte folosit';
			break;
		case 'pp-semi-spambot':
			edit = 'autoconfirmed';
			move = 'autoconfirmed';
			reason = 'Semi-protejare: țintă roboți de spam';
			break;
		case 'pp-semi-protected':
			edit = 'autoconfirmed';
			move = 'autoconfirmed';
			if( params.reason ) {
				tag += '|motiv=' + params.reason;
				params.reason = undefined;
			}
			reason = 'Semi-protejare';
			break;
		case 'pp-mutare':
			edit = '';
			move = 'sysop';
			reason = 'Protejare la mutare';
			break;
		case 'pp-create':
			edit = '';
			move = '';
			create = 'sysop';
			reason = 'Protejare la creare';
			break;
 
		case 'unprotect':
		default:
			edit = '';
			move = '';
			reason = 'Deprotejare';
			break;
		}
		if( params.reason ) {
			reason += ', ' + params.reason;
		}
		if( reason != '' && reason.charAt( reason.length - 1 ) != '.' ) {
			reason += '.';
		}
 
		params.reason = reason;
		params.tag = tag;
		params.edit = edit;
		params.move = move;
		params.create = create;
 
		var query = {
			'title': wgPageName,
			'action': 'protect'
		};
 
		// Updating data for the action completed event
		Wikipedia.actionCompleted.redirect = query['title'];
		Wikipedia.actionCompleted.notice = "Gata...";
 
		var wikipedia_wiki = new Wikipedia.wiki( 'Protejare pagină', query, twinkleprotect.callbacks.sysop.protectingPage );
		wikipedia_wiki.params = params;
		wikipedia_wiki.get();
	} else {	
		var typename, reason;
			switch( params.type ) {
			case 'pp-dispută':
			case 'pp-vandalism':
			case 'pp-template':
			case 'pp-usertalk':
			case 'pp-protected':
				typename = 'Protejare completă';
				break;
			case 'pp-semi-vandalism':
			case 'pp-semi-usertalk':
			case 'pp-semi-template':
			case 'pp-semi-spambot':
			case 'pp-semi-protected':
				typename = 'Semi-protejare';
				break;
			case 'pp-mutare':
				typename = 'Protejare la mutare';
				break;
			case 'pp-create':
				typename = 'Protejare la creare';
				break;
			case 'unprotect':
			default:
				typename = 'Deprotejare';
				break;
		}
 
		switch( params.type ) {
			case 'pp-dispută':
				reason = 'dispută';
				break;
			case 'pp-vandalism':
			case 'pp-semi-vandalism':
				reason = 'vandalism';
				break;
			case 'pp-template':
			case 'pp-semi-template':
				reason = 'format foarte utilizat';
				break;
			case 'pp-usertalk':
			case 'pp-semi-usertalk':
				reason = 'pagina de discuție a unui utilizator blocat';
				break;
			case 'pp-semi-spambot':
				reason = 'țintă a roboților de spam';
				break;
			case 'pp-protected':
			case 'pp-semi-protected':
			case 'pp-mutare':
			case 'pp-create':
			case 'unprotect':
			default:
				reason = '';
				break;
		}
 
		if( reason != '' ) {
			reason = " ''" + reason + "''";
		}
		if( params.reason ) {
			reason += ', ' + params.reason;
		}
		if( reason != '' && reason.charAt( reason.length - 1 ) != '.' ) {
			reason += '.';
		}
 
		params.reason = reason;
		params.typename = typename;
 
		var query = {
			'title': 'Wikipedia:Cereri pentru protejarea paginilor',
			'action': 'submit'
		};
		// Updating data for the action completed event
		Wikipedia.actionCompleted.redirect = query['title'];
		Wikipedia.actionCompleted.notice = "Nominalizare completă, redirecționare la pagina de discuții";
 
		var wikipedia_wiki = new Wikipedia.wiki( 'Se cere protejarea paginii', query, twinkleprotect.callbacks.user );
		wikipedia_wiki.params = params;
		wikipedia_wiki.followRedirect = true;
		wikipedia_wiki.get();
	}
}
 
twinkleprotect.callbacks = {
	sysop: {
		taggingPage: function( self ) {
			var form = self.responseXML.getElementById( 'editform' );
			var oldtag_re = /\s*(?:<noinclude>)?\s*\{\{\s*(pp-[^{}]*?|protejat|(?:t|v|s|p-|usertalk-v|usertalk-s|sb|mutare)protected(?:2)?|protected template|privacy protection)\s*?\}\}\s*(?:<\/noinclude>)?\s*/gi;
 
			var text = form.wpTextbox1.value;
 
			text = text.replace( oldtag_re, '' );
 
			if( self.params.type != 'unprotect' && self.params.expiry != 'indefinite' ) {
				self.params.tag += '|expiry={' + '{subst:#time:j.F.Y|+' + self.params.expiry +'}}'; 
			}
			if( self.params.small ) { 
					self.params.tag += '|small=yes';
			}
 
 
			var summary;
			if( self.params.type == 'unprotect' ) {
				summary = 'șterg formatul protejat' + TwinkleConfig.summaryAd;
			} else {
				if( self.params.noinclude ) {
					text = "<noinclude>\{\{" + self.params.tag + "\}\}</noinclude>" + text;
				} else {
					text = "\{\{" + self.params.tag + "\}\}\n" + text;
				}
				summary = "adaug \{\{" + self.params.tag + "\}\}" + TwinkleConfig.summaryAd;
 
			}
			var postData = {
				'wpMinoredit': form.wpMinoredit.checked ? '' : undefined,
				'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
				'wpStarttime': form.wpStarttime.value,
				'wpEdittime': form.wpEdittime.value,
				'wpAutoSummary': form.wpAutoSummary.value,
				'wpEditToken': form.wpEditToken.value,
				'wpSummary': summary,
				'wpTextbox1': text
			};
 
			self.post( postData );
		},
		protectingPage: function( self ){
			var form  = self.responseXML.getElementById( 'mw-Protect-Form' );
			var postData;
 
			if( self.params.type == 'pp-move' ) {
				postData = {
					'wpEditToken': form.wpEditToken.value,
					'mwProtect-level-move': self.params.move,
					'wpProtectExpirySelection-move': self.params.expiry != 'indefinite' ? 'othertime' : 'indefinite',
					'mwProtect-expiry-move': self.params.expiry != 'indefinite' ? self.params.expiry : undefined,
					'mwProtect-cascade': self.params.cascade ? '' : undefined,
					'mwProtectWatch': form.mwProtectWatch.checked ? '' : undefined,
					'wpProtectReasonSelection': 'other',
					'mwProtect-reason': self.params.reason + TwinkleConfig.protectionSummaryAd
				};
 
			} else if( self.params.type == 'pp-create' ) {
				postData = {
					'wpEditToken': form.wpEditToken.value,
					'mwProtect-level-create': self.params.create,
					'wpProtectExpirySelection-create': self.params.expiry != 'indefinite' ? 'othertime' : 'indefinite',
					'mwProtect-expiry-create': self.params.expiry != 'indefinite' ? self.params.expiry : undefined,
					'mwProtect-cascade': self.params.cascade ? '' : undefined,
					'mwProtectWatch': form.mwProtectWatch.checked ? '' : undefined,
					'wpProtectReasonSelection': 'other',
					'mwProtect-reason': self.params.reason + TwinkleConfig.protectionSummaryAd
				};
 
			} else if( self.params.type == 'unprotect' ) {
				postData = {
					'wpEditToken': form.wpEditToken.value,
					'mwProtect-level-edit': self.params.edit,
					'wpProtectExpirySelection-edit': 'indefinite',
					'mwProtect-level-move': self.params.move,
					'wpProtectExpirySelection-move': 'indefinite',
					'mwProtect-level-create': self.params.create,
					'wpProtectExpirySelection-create': 'indefinite',
					'mwProtect-cascade': self.params.cascade ? '' : undefined,
					'mwProtectWatch': form.mwProtectWatch.checked ? '' : undefined,
					'wpProtectReasonSelection': 'other',
					'mwProtect-reason': self.params.reason + TwinkleConfig.protectionSummaryAd
				};
			} else {
				postData = {
					'wpEditToken': form.wpEditToken.value,
					'mwProtect-level-edit': self.params.edit,
					'wpProtectExpirySelection-edit': self.params.expiry != 'indefinite' ? 'othertime' : 'indefinite',
					'mwProtect-expiry-edit': self.params.expiry != 'indefinite' ? self.params.expiry : undefined,
					'mwProtect-level-move': self.params.move,
					'wpProtectExpirySelection-move': self.params.expiry != 'indefinite' ? 'othertime' : 'indefinite',
					'mwProtect-expiry-move': self.params.expiry != 'indefinite' ? self.params.expiry : undefined,
					'mwProtect-cascade': self.params.cascade ? '' : undefined,
					'mwProtectWatch': form.mwProtectWatch.checked ? '' : undefined,
					'wpProtectReasonSelection': 'other',
					'mwProtect-reason': self.params.reason + TwinkleConfig.protectionSummaryAd
				};
			}
 
			self.post( postData );
 
			var query = {
				'title': wgPageName,
				'action': 'submit'
			};
			if( self.params.create == '' ) {
				var wikipedia_wiki = new Wikipedia.wiki( 'Adaug format', query, twinkleprotect.callbacks.sysop.taggingPage );
				wikipedia_wiki.params = self.params;
				wikipedia_wiki.get();
			}
		}
	},
	user: function( self ) {
		var form = self.responseXML.getElementById( 'editform' );
 
		var text = form.wpTextbox1.value;
 
		var ns2tag	=	{
			'0'	:	'la-l',
			'1'	:	'lat-l',
			'2'	:	'lu-l',
			'3'	:	'lut-l',
			'4'	:	'lw-l',
			'5'	:	'lwt-l',
			'6'	:	'li-l',
			'7'	:	'lit-l',
			'8'	:	'lm-l',
			'9'	:	'lmt-l',
			'10':	'lt-l',
			'11':	'ltt-l',
			'12':	'lh-l',
			'13':	'lht-l',
			'14':	'lc-l',
			'15':	'lct-l',
			'100':	'lp-l',
			'101':	'lpt-l'
		};
 
		var rppRe = new RegExp( '====\\s*\\{\\{\\s*' + ns2tag[ wgNamespaceNumber ] + '\\s*\\|\\s*' + RegExp.escape( wgTitle, true ) + '\\s*\\}\\}\\s*====', 'm' );
		var tag = rppRe.exec( text );
 
		if( tag ) {
			self.statelem.warn( [ htmlNode( 'strong', tag[0] ) , " este deja plasat în pagină." ] )
			return false;
		}
 
		var newtag = '==== \{\{' + ns2tag[ wgNamespaceNumber ] + '|' + wgTitle +  '\}\} ====' + "\n";
		if( ( new RegExp( '^' + RegExp.escape( newtag ).replace( /\s+/g, '\\s*' ), 'm' ) ).test( text ) ) {
			self.statelem.error( 'Este deja o cerere pentru această pagină, opresc...' );
			return;
		}
		var words = [];
		switch( self.params.expiry ) {
		case 'temporar':
			words.push( "Temporar" );
			break;
		case 'infinit':
			words.push( "Infinit" );
			break;
		}
		if( self.params.cascade ) {
			words.push( "în cascadă" );
		}
 
		words.push( self.params.typename );
 
		newtag += "'''" + words.join( ' ' ) + "'''" + ( self.params.reason != '' ? self.params.reason : '' ) + " \~\~\~\~";
 
		if( self.params.type == 'unprotect' ) {
			var reg = /(\n==\s*Cereri pentru deprotejarea paginilor\s*==\s*\n(?:(?:\s*|<!--(?:(?!-->).)*-->|{{\s*(?:[^|{}]*)\d*\s*(\|(?:{{[^{}]*}}|[^{}])*)?}})[\n\s]*)*)/; 
		} else {
			var reg = /(\n==\s*Cereri pentru protejarea paginilor\s*==\s*\n(?:(?:\s*|<!--(?:(?!-->).)*-->|{{\s*(?:[^|{}]*)\d*\s*(\|(?:{{[^{}]*}}|[^{}])*)?}})[\n\s]*)*)/; 
		}
		var originalTextLength= text.length;
		text = text.replace( reg, "$1" + newtag + "\n"); 
		if (text.length==originalTextLength)
		{
			self.statelem.error( 'Marcatorul care identifică unde ar trebui adăugată cererea nu a putut fi găsit. Opresc...' );
			return;
		}
		var postData = {
			'wpMinoredit': undefined,
			'wpWatchthis': form.wpWatchthis.checked ? '' : undefined,
			'wpStarttime': form.wpStarttime.value,
			'wpEdittime': form.wpEdittime.value,
			'wpAutoSummary': form.wpAutoSummary.value,
			'wpEditToken': form.wpEditToken.value,
			'wpSection': '',
			'wpSummary': "Cer " + self.params.typename + ' paginii [[' + wgPageName.replace(/_/g, ' ') + ']].' + TwinkleConfig.summaryAd,
			'wpTextbox1': text
		};
 
		self.post( postData );
	}
}