MediaWiki:Gadget-LiveRC 1x.js/InserisciTemplate.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Nessun oggetto della modifica
Dr. Brains modif
Riga 18:
* Licence : ...?
* Documentation :
* Auteur : [[:it:User:Jalo]] [[:it:User:Rotpunkt]] [[:fr:User:Dr Brains]]
*
* This script contains functions (InserisciTemplate_showDialog, InserisciTemplate_dumpTemplate and InserisciTemplate_buildInputEl)
Riga 144:
/* Template list:
*
* 'template': (string) name of the template to be inserted
* 'string': (string) option label in the template combo box
* 'where': (string) where to insert the template in the page. (topAccepted orvalues are: top, bottom)
* 'noinclude': (boolean) whether the template shall be tagged with "noinclude"
* 'subst': (boolean) whether the template shall be "substed"
* 'parameters': (object) list of the parameters of the template
* 'name': (string) parameter name shown in the popup dialog
* 'type': (string) type of the argument. Accepted values are: string, checkbox, select
* 'value':
* type==string Not(string) requiredSome text (or nothing)
* type==checkboxselect The boolean initial(array) state (trueThe orlist false)of combo box options
* type==select The list of combo box options
* 'format': The format of the written template
*/
 
Riga 170 ⟶ 168:
argomento: {name: 'Argomento', type: 'select', value: templateArguments_A},
argomento2: {name: 'Argomento2', type: 'select', value: templateArguments_A},
mese: {name: 'Mese', type: 'string' , value: '{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}'}
}
},
Riga 397 ⟶ 395:
}
};
 
function LiveRC_FormatTemplateParams(params) {
var text = new Array();
for(var arg in params){
if(params.hasOwnProperty(arg)) text.push(arg+"="+params[arg]);
}
return text.join("|");
}
 
// ####################################################################################################################
// ####################################################################################################################
 
// Add options in the "Tag" form
 
function lrcRunInsertTemplate(data){
var TagSelect = document.getElementById('LiveTagReason');
 
jQuery.each(lstMyTemplate, function(i, val) {
var optTag = document.createElement('option');
Riga 419 ⟶ 410:
TagSelect.appendChild(optTag);
});
 
// setup dialog
mw.loader.using(['jquery.ui.dialog'], function () {
Riga 427 ⟶ 417:
});
}
////////////////////////////////////////// HOOKS
 
LiveRC_AddHook("AfterPreviewArticle", lrcRunInsertTemplate);
 
// Function launched when choosing one of this extension options
// Récupération des information et requête de page
getLiveTagFunctions["InserisciTemplateExtension"] = function(page, option){
lrcDisableLink("LiveTagReason");
lrcDisableLink("LiveTagLink");
var message = lstMyTemplate[option.value];
wpajax.http({ url: wgServer + wgScriptPath + '/api.php?format=xml'
Riga 446 ⟶ 435:
}
// Get page edit token and protection status
// Traitement ajout de bandeau
function InserisciTemplate_PostTagPage(xmlreq, data){
Riga 464 ⟶ 453:
}
var Page = ObjetXML.getElementsByTagName("page")[0];
LiveRC_Config["edittoken"] = Page.getAttribute("edittoken");
 
// show dialog
var tpl = InserisciTemplate_showDialog(message, page);
}
function InserisciTemplate_PostTagPageDone(Req, data){
var params = data.params;
var where = data.where;
var text = "<b>" +params["title"]+ " : " + lrcMakeText("TAG_DONE") + "</b> <small>("+params[(where=='bottom')?"appendtext":"prependtext"]+")</small>";
LiveRC_alert(text);
}
 
// Show the dialog in order to ask for the template parameters.
/**
 
* Show the dialog in order to ask for the template parameters.
*/
function InserisciTemplate_showDialog(data, page) {
var $dialog, $fieldset;
 
// create the dialog html
$dialog = $('#gtb-dialog').html(lrcMakeText("IT_InsertTemplate1"));
Riga 494 ⟶ 473:
$dialog.append(lrcMakeText("IT_InsertTemplate2"));
$fieldset = $('<fieldset>').css('border-color', 'gray').appendTo($dialog);
$('<legend>').text(lrcMakeText('ParametriIT_InsertTemplateParams')).appendTo($fieldset);
$.each(data.parameters, function (id, val) {
var inputEl = InserisciTemplate_buildInputEl(id, val);
Riga 506 ⟶ 485:
.append('<br/>');
});
 
// show the dialog
var Buttons = new Object();
$dialog.dialog({
var OKText = lrcMakeText('OK');
title: '<img src="https://upload.wikimedia.org/wikipedia/commons/b/b6/LiveRC-cropt.svg" width="42"/>&nbsp;' + data.string,
var CancelText = lrcMakeText('Cancel');
width: 500,
Buttons[OKText] = function () {
resizable: false,
modal: true,
zIndex: 10000,
buttons: {
'Inserisci': function () {
var params = {};
$dialog.find('input:text,select').each(function () {
params[$(this).attr('id')] = $.trim($(this).val());
});
$dialog.find('input:checkbox').each(function () {
params[$(this).attr('id')] = $(this).prop('checked');
});
text = InserisciTemplate_dumpTemplate(data, params);
$(this).dialog('close');
InserisciTemplate_postTemplate(data, text, page);
},;
Buttons[CancelText] 'Annulla':= function () {
$(this).dialog('close');
};
$dialog.dialog({
}
title: lrcMakeIcon("LogoIcon") + '&nbsp;' + data.string,
width: 500,
resizable: false,
modal: true,
zIndex: 10000,
buttons: Buttons
});
}
 
function InserisciTemplate_buildInputEl(id, data) {
var label, inputEl;
if (data.type == 'string') {
label = data.name;
inputEl = $('<input/>')
.attr('id', id)
.attr('type', 'text')
.attr('size', 50)
.attr('value', (data.value || ''));
} else if (data.type == 'select') {
label = data.name;
inputEl = $('<select>')
.attr('id', id)
.css('width', '200px');
$.each(data.value, function (i, option) {
$('<option>')
.html(option)
.appendTo(inputEl);
});
}
return { label: label, el: inputEl };
}
 
// Check the dialog box and create the wikitext from the template and its params
 
function InserisciTemplate_dumpTemplate(template, params) {
Riga 543 ⟶ 545:
'}}' +
(template.noinclude ? '</noinclude>' : '') + '\n';
 
return text;
}
 
function LiveRC_FormatTemplateParams(params) {
var edittoken = "";
var text = new Array();
for(var arg in params){
if(params.hasOwnProperty(arg)) text.push(arg+"="+params[arg]);
}
return text.join("|");
}
 
// Save the edit
 
function InserisciTemplate_postTemplate (data, text, page){
lrcDisableLink("LiveTagReason");
lrcDisableLink("LiveTagLink");
var EditParam = new Array();
EditParam["token"] = LiveRC_Config["edittoken"];
if (data.where == 'top')
EditParam["prependtext"] = text+"\n";
Riga 564 ⟶ 574:
EditParam["notminor"] = "1";
EditParam["nocreate"] = "1";
if(lrcMakeParam("BypassWatchdefault")) EditParam["watchlist"] = "nochange";
var Params = new Array();
for(var Param in EditParam){
Riga 581 ⟶ 590:
});
}
 
function InserisciTemplate_buildInputElInserisciTemplate_PostTagPageDone(idReq, data) {
var params = data.params;
var label, inputEl;
var where = data.where;
 
var text = "<b>" +params["title"]+ " : " + lrcMakeText("TAG_DONE") + "</b> <small>("+params[(where=='bottom')?"appendtext":"prependtext"]+")</small>";
if (data.type == 'string') {
LiveRC_alert(text);
label = data.name;
inputEl = $('<input/>')
.attr('id', id)
.attr('type', 'text')
.attr('size', 50)
.attr('value', (data.value || ''));
} else if (data.type == 'checkbox') {
label = data.name;
inputEl = $('<input/>')
.attr('id', id)
.attr('type', 'checkbox')
.attr('checked', data.value);
} else if (data.type == 'select') {
label = data.name;
inputEl = $('<select>')
.attr('id', id)
.css('width', '200px');
$.each(data.value, function (i, option) {
$('<option>')
.html(option)
.appendTo(inputEl);
});
}
 
return { label: label, el: inputEl };
}
 
/* ########################################## CONFIGURATION PANEL ################################## */
Riga 1 028 ⟶ 1 012:
NewParam.type = getElementWithId('Param_type', 'select', ParamLi).value;
if(NewParam.type == "string"){
NewParam.value = getElementWithId('Param_value', 'input', ParamLi).value.unhtmlize();
if(!NewParam.value) delete NewParam.value;
}else{
NewParam.value = new Array();
Riga 1 034 ⟶ 1 019:
var Opt = ParamValueSelect.getElementsByTagName('option');
for(var c=0,k=Opt.length;c<k;c++){
NewParam.value.push(Opt[c].value.unhtmlize());
}
}
Riga 1 041 ⟶ 1 026:
Items[NewItem.template] = NewItem;
}
var TextToSave = InserisciTemplate_CompareNewParams(Items);
if(!TextToSave) return;
var SavedText = "\nCustom_lstMyTemplate = {\n";
var SavedItems = new Array();
Riga 1 050 ⟶ 1 037:
var tempParamValue = ThisTemplate[tempParam];
if(tempParam!="parameters"){
SavedItem += ( typeof(tempParamValue)=="string" ? lrcEscapeStrlrcEscapeStrHTML(tempParamValue) : tempParamValue ) + ",\n";
}else{
SavedItem += "{\n";
Riga 1 060 ⟶ 1 047:
var thisparamItemValue = thisparam[paramItem];
if(paramItem!="value" || typeof(thisparamItemValue)=="string"){
ParamItems.push( paramItem + ":" + lrcEscapeStrlrcEscapeStrHTML(thisparamItemValue) );
}else{
var ThisParamValue = new Array();
for(var a=0,l=thisparamItemValue.length;a<l;a++){
ThisParamValue.push(lrcEscapeStrlrcEscapeStrHTML(thisparamItemValue[a]));
}
ParamItems.push( paramItem +": [" + ThisParamValue.join(",") + "]" );
}
}
tempParameters.push(" " + lrcEscapeStrlrcEscapeStrHTML(parameter) + " : {" + ParamItems.join(",") + "}");
}
SavedItem += tempParameters.join(",\n");
Riga 1 084 ⟶ 1 071:
LiveRC_AddHook("BeforeParamPanelSaved", InserisciTemplate_CheckConfigPanel);
 
function InserisciTemplate_CompareNewParams(NewItems){
 
var OldItems = lstMyTemplate;
for(var template in OldItems){
if(typeof(NewItems[template])==="undefined") return true;
for(var item in OldItems[template]){
if(item != "parameters"){
if(OldItems[template][item] !== NewItems[template][item]) return true;
}else{
if(lrcGetObjectLength(OldItems[template][item]) != lrcGetObjectLength(NewItems[template][item])) return true;
for(var param in OldItems[template][item]){
if(!NewItems[template][item][param]) return true;
for(var paramitem in OldItems[template][item][param]){
if(paramitem != "value" || (typeof(OldItems[template][item][param][paramitem]) != "object" && typeof(NewItems[template][item][param][paramitem]) != "object")){
if(OldItems[template][item][param][paramitem] !== NewItems[template][item][param][paramitem]) return true;
}else{
if(OldItems[template][item][param][paramitem].length != NewItems[template][item][param][paramitem].length) return true;
for(var a=0, l=OldItems[template][item][param][paramitem].length;a<l;a++){
if(OldItems[template][item][param][paramitem][a] != NewItems[template][item][param][paramitem][a]) return true;
}
}
}
}
}
}
}
for(var template in NewItems){
if(typeof(OldItems[template])==="undefined") return true;
}
return false;
}
 
// ===== Vars for configuration panel fieldset =====
Riga 1 091 ⟶ 1 107:
 
try{
lrcTexts["IT_InsertTemplate1"] = "Inserisce il template {{";
lrcTexts["IT_InsertTemplate2"] = "}} nella pagina.";
lrcTexts["IT_InsertTemplateParams"] = "Parametri";
lrcTexts["IT_AddTemplate"] = "Aggiungi un nuovo template";
lrcTexts["IT_DeleteTemplate"] = "Cancella questo template";
Riga 1 104 ⟶ 1 121:
// Descriptions
try{
lrcParamDesc["DescIT_InsertTemplate1"] = "[InserisciTemplate] Inserisci la parte 1 della frase del template";
lrcParamDesc["DescIT_InsertTemplate2"] = "[InserisciTemplate] Inserisci la parte e2 della frase del template";
lrcParamDesc["DescIT_InsertTemplateParams"] = "[InserisciTemplate] Parametri";
 
lrcParamDesc["DescIT_AddTemplate"] = "[InserisciTemplate] Frase Aggiungi un nuovo template";
lrcParamDesc["DescIT_DeleteTemplate"] = "[InserisciTemplate] Frase Cancella questo template";