MediaWiki:Common.js/TemplateEditor.js

window.dataTemplates = [ {		'match':/(Template)\:Data.+/ig, 'before': '{'+'{'+'{'+'{'+'{1 |champion data }}}|2={'+'{'+'{2|}}}|3={'+'{'+'{3|}}}|4={'+'{'+'{4|}}}|5={'+'{'+'{5|}}}\n', 'after': '}}', } ]; function dataTemplateEditor { window.templateEditorReady = false; var permision = true; if(typeof(wgRestrictionEdit) != 'undefined') { if(wgRestrictionEdit[0] == 'autoconfirmed') { permision = false; var groups = ['adminmentor', 'bot', 'autoconfirmed', 'helper', 'staff', 'sysop', 'vstf']; for(var x=0;x<groups.length;x++) { if(wgUserGroups.indexOf(groups[x]) != -1) { permision = true; break; }			}		} else if(wgRestrictionEdit[0] == 'sysop') { permision = false; var groups = ['adminmentor', 'helper', 'staff', 'sysop', 'vstf']; for(var x=0;x<groups.length;x++) { if(wgUserGroups.indexOf(groups[x]) != -1) { permision = true; break; }			}		}	} else permision = true; if(!permision) return; for(var i=0;i').find('img').remove; def.append(' form') .attr('href', def.attr('href').replace('action=', 'teaction=')) .attr('id', 'ca-teedit') .data('template', index) .click(function(e) {				dataTemplateStartEditor($(this).data('template'));				e.preventDefault;				return false;			}); } else if($('body').hasClass('skin-monobook')) { var def = $('#p-cactions #ca-edit'); var form = def.clone.insertBefore(def).attr('id', 'ca-teedit'); form.find('a').append(' form') .attr('href', form.find('a').attr('href').replace('action=', 'teaction=')) .data('template', index) .removeAttr('title') .removeAttr('primary') .click(function(e) {				dataTemplateStartEditor($(this).data('template'));				e.preventDefault;				return false;			}); } } function dataTemplateHandle(index) { dataTemplateMenu(index); var edit = $('') .data('template', index) .click(function {			dataTemplateStartEditor($(this).data('template'));		}); var save = $('') .data('template', index) .click(function {			dataTemplateSave($(this).data('template'));		}); var savespan = $(' Edit summary:  ') .append([' ', save]); var retry = $('') .data('template', index) .click(function {			dataTemplateGetToken(wgArticleId);		}); var msg = $(' '); $('.te-controls').append([msg,' ',edit,' ',retry,' ',savespan]); if(/teaction\=edit/.test(location.search)) { dataTemplateStartEditor($(this).data('template')); } } function dataTemplateGetToken(pageid) { $('#te-error, #te-retry-button').fadeOut('slow'); var url = '/api.php?format=json&action=query&prop=info%7Crevisions&intoken=edit&pageids='+pageid; $.ajax({		url: url,		dataType: 'json',		success: function(data) {			window.teStartTimestamp = data['query']['pages'][pageid]['starttimestamp'];			window.teEditTimestamp = data['query']['pages'][pageid]['revisions'][0]['timestamp'];			window.teEditToken = data['query']['pages'][pageid]['edittoken'];			window.teTitle = data['query']['pages'][pageid]['title'];			$('#te-save').fadeIn;		},		error: function(data) {			$('#te-error').fadeIn('slow').html('There was a problem retrieving the token');			$('#te-retry-button').fadeIn('slow');		},	}); return 'asd'; } function dataTemplateStartEditor(index) { location.hash = '#Parameters'; if(!templateEditorReady) { templateEditorReady = true; template = window.dataTemplates[index]; $('#te-edit-button').fadeOut('slow', function {			window.teEditToken = dataTemplateGetToken(wgArticleId);		}); var inputs = $('#mw-content-text .te-input'); inputs.each(function {			$this = $(this);			$this.data('value', $this.text.replace(/^\s+|\s+$/, ''));			$this.html(' '+$this.html+' ');			$this.find('input').val($this.data('value'));		}); inputs.find('.old-value').hide; inputs.find('.new-value').show; } } function dataTemplateSaveText(title, text) { $('#te-error, #te-retry-button').fadeOut('slow'); if($('#te-summary').val) var summ = 'Edited with MediaWiki:TemplateEditor.js: '+$('#te-summary').val; else var summ = 'Edited with MediaWiki:TemplateEditor.js'; $.ajax({		url: '/api.php',		data: {			'format': 'json',			'action': 'edit',			'title': title,			'notminor': true,			'basetimestamp': teEditTimestamp,			'starttimestamp': teStartTimestamp,			'summary': summ,			'text': text,			'token': teEditToken,		},		type: 'POST',		dataType: 'json',		success: function(data) {			if(data['edit'] && data['edit']['result'] == 'Success') {				location.reload;			} else if(data['error']) {				$('#te-error').fadeIn('slow').html('An error occurred while saving: '+data['error']['info']+' ');			}		},		failure: function(data) {			$('#te-error').fadeIn('slow').html('An error occurred while saving');		},	}); } function dataTemplateSave(index) { template = window.dataTemplates[index]; var values = []; var inputs = $('#mw-content-text .te-input .new-value input'); var required = false; inputs.each(function {		$(this).css('border-color', '');		var name = $(this).closest('.te-input').data('name');		var value = $(this).val;		if(!value) {			if($(this).closest('.te-input').hasClass('empty'))				return values.push('|'+name+'='+'\n');			if($(this).closest('.te-input').hasClass('required')) {				$(this).css('border-color', 'red');				return required = true;			}		} else			return values.push('|'+name+'='+value+'\n');	}); if(required) return; dataTemplateSaveText(teTitle, template['before']+values.join('')+template['after']); } $(dataTemplateEditor);