MediaWiki:Gadget-LiveRC 1x.js/InserisciTemplate.js: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
wpajax -> mw.Api (2) |
Altre semplificazioni piccoline |
||
(3 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 621:
}
};
function getTemplateList() {
return Object.keys( Custom_lstMyTemplate ).length
? Custom_lstMyTemplate
: lstMyTemplate;
}
// ####################################################################################################################
// ####################################################################################################################
/**
* Add options in the "Tag" form
*/
function lrcRunInsertTemplate( data ) {
var TagSelect = document.getElementById( 'LiveTagReason' )
TemplateList = getTemplateList();
$.each( TemplateList, function( i, val ) {
var optTag = document.createElement( 'option' );
Riga 641 ⟶ 645:
TagSelect.appendChild( optTag );
} );
.attr( 'id', 'gtb-dialog' )
}
LiveRC_AddHook( "AfterPreviewArticle", lrcRunInsertTemplate );
/**
* Function launched when choosing one of this extension options
*/
getLiveTagFunctions.InserisciTemplateExtension = function( page, option ) {
lrcDisableLink( "LiveTagReason" );
lrcDisableLink( "LiveTagLink" );
var TemplateList =
new mw.Api().get( {
format: 'json',
action: 'query',
prop: 'info',
inprop: 'protection',
titles: page
Riga 680 ⟶ 674:
return false;
};
function InserisciTemplate_PostTagPage( res, page, message ) {
var resPage = Object.values( res.query.pages )[0];
if ( !resPage ) {
return;
}
for ( var prEntry in resPage.protection ) {
if ( prEntry.type === "edit" && mw.config.get( 'wgUserGroups' ).indexOf( prEntry.level ) === -1 ) {
LiveRC_alert( "<b>" + lrcMakeText( "PROTECTEDPAGE" ).split( "$1" ).join( page ) + "</b>" );
}
}
InserisciTemplate_showDialog( message, page );
}
/**
* Show the dialog in order to ask for the template parameters.
*/
function InserisciTemplate_showDialog( data, page ) {
var $dialog, $fieldset;
$dialog = $( '#gtb-dialog' ).html( lrcMakeText( "IT_InsertTemplate1" ) );
$( '<a>' )
.attr( 'href', mw.
.attr( 'target', '_blank' )
.attr( 'tabindex', '-1' )
Riga 729 ⟶ 717:
.append( '<br/>' );
} );
var
var Buttons
var params = {};
$dialog.find( 'input:text,select' ).each( function() { params[ $( this ).attr( 'id' ) ] = $.trim( $( this ).val() );
} );
text = InserisciTemplate_dumpTemplate( data, params );
$( this ).dialog( 'close' );
InserisciTemplate_postTemplate( data, text, page );
$( this ).dialog( 'close' );
}
};
$dialog.dialog( {
Riga 756 ⟶ 746:
function InserisciTemplate_buildInputEl( id, data ) {
var label
inputEl;
if ( data.type == 'string' ) {
inputEl = $( '<input/>' )
.attr( 'id', id )
Riga 765 ⟶ 755:
.attr( 'value', ( data.value || '' ) );
} else if ( data.type == 'select' ) {
inputEl = $( '<select>' )
.attr( 'id', id )
Riga 781 ⟶ 770:
}
/**
* Check the dialog box and create the wikitext from the template and its params
*/
function InserisciTemplate_dumpTemplate( template, params ) {
return ( template.noinclude ? '<noinclude>' : '' ) +
'{{' + ( template.subst ? 'subst:' : '' ) +
template.template + '|' +
LiveRC_FormatTemplateParams( params ) +
'}}' +
( template.noinclude ? '</noinclude>' : '' ) + '\n';
Riga 803 ⟶ 792:
}
/**
* Save the edit
*/
function InserisciTemplate_postTemplate( data, text, page ) {
lrcDisableLink( "LiveTagReason" );
Riga 812 ⟶ 802:
summary: lrcMakeText( "RESUMESTART" ) + lrcMakeText( "TAG_RESUME" ) + ' ' + data.template,
title: page,
watchlist: lrcMakeParam( "BypassWatchdefault" ) ? 'nochange' : "preferences",
notminor: 1,
nocreate: 1
};
if ( data.where == 'bottom' ) {
} else { // top, or default = top
EditParam.prependtext = text + "\n";
}
new mw.Api().postWithEditToken( EditParam )
.done( function () {
LiveRC_alert( "<b>" + page + " : " + lrcMakeText( "TAG_DONE" ) + "</b> <small>(" +
} );
}
Riga 839 ⟶ 822:
/**
* Create a fieldset in the configuration panel
*/
function InserisciTemplate_CreateConfigPanel() {
var InserisciTemplateUl = LiveRC_ManageParams_CreateNewListMenu( "InserisciTemplateLegend", LiveRC_ManageParams_CreateActionButtons() ),
Target = InserisciTemplateUl.parentNode,
Templates = getTemplateList();
for ( var temp in Templates ) {
if (
Target.appendChild( InserisciTemplate_CreateTemplateConfigPanel( Templates[ temp ] ) );
}
}
var NewTemplate = document.createElement( 'p' );
Riga 904 ⟶ 883:
return;
}
}
Riga 915 ⟶ 894:
Title.innerHTML = "{{" + Template.template + "}} ";
Title.target = "_blank";
Title.href =
Title.title =
Title.onclick = function() {
liveArticle(
return false;
};
Riga 1 043 ⟶ 1 022:
function InserisciTemplate_AddParamToTemplate( AddParamLink ) {
var NewParams = {
name: '',
Riga 1 050 ⟶ 1 028:
};
var NewParamLi = InserisciTemplate_CreateNewParam( "", NewParams );
}
function InserisciTemplate_CreateNewParam( param, Params ) {
var ParamType = Params.type;
var ParamValue = Params.value;
Riga 1 065 ⟶ 1 042:
DeleteParamLink.href = "javascript:;";
DeleteParamLink.onclick = function() {
$( this.parentNode ).remove();
};
LI_Param.appendChild( DeleteParamLink );
Riga 1 090 ⟶ 1 067:
Input_name.id = 'Param_name';
Input_name.type = "text";
Input_name.value = (
LI_Param.appendChild( Input_name );
LI_Param.appendChild( document.createTextNode( " - " ) );
Riga 1 113 ⟶ 1 090:
}
Select_type.onchange = function() {
};
LI_Param.appendChild( Select_type );
Riga 1 166 ⟶ 1 143:
}
function
var
var LastLabel = Labels[ ( Labels.length - 1 ) ];
while ( LastLabel.nextSibling ) {
}
if (
var Input_value = document.createElement( 'input' );
Input_value.id = 'Param_value';
Riga 1 212 ⟶ 1 187:
function InserisciTemplate_DeleteOptionFromSelect( DeleteOptionLink ) {
var
for ( var a = 0, l = Selects.length; a < l; a++ ) {
var Select = Selects[ a ];
Riga 1 263 ⟶ 1 237:
var Span = AddOptionInputCancel.parentNode;
var Link = Span.nextSibling;
Link.style.display = "";
}
Riga 1 285 ⟶ 1 259:
}
/**
* Check the fieldset and add a text to be saved in /LiveRCparam.js page
*/
function InserisciTemplate_CheckConfigPanel() {
var $ITConfigPanel =
if ( !$ITConfigPanel.length ) {
return;
}
var Items = {};
$ITConfigPanel.find( 'form.InserisciTemplate_TemplateForm' ).each( function () {
var
template: this.getElementById( 'template' ).value,
string: this.getElementById( 'string' ).value,
where: this.getElementById( 'where' ).value,
noinclude: this.getElementById( 'noinclude' ).checked,
subst: this.getElementById( 'subst' ).checked
};
NewItem.parameters = {};
var ParamLIs = $(
var
name: this.getElementById( 'Param_name' ).value,
type: this.getElementById( 'Param_type' ).value
};
if ( NewParam.type == "string" ) {
if (
}
} else {
NewParam.value = [];
var
Opt.each( function () {
NewParam.value.push( this.value.unhtmlize() );
} );
}
NewItem.parameters[
} );
Items[ NewItem.template ] = NewItem;
} );
var TextToSave = InserisciTemplate_CompareNewParams( Items );
if ( !TextToSave ) {
Riga 1 381 ⟶ 1 348:
function InserisciTemplate_CompareNewParams( NewItems ) {
var OldItems = lstMyTemplate;
if ( JSON.stringify( Object.keys( OldItems ).sort() ) !== JSON.stringify( Object.keys( NewItems ).sort() ) ) {
return true;
}
for ( var template in OldItems ) {
if ( item !== "parameters" && OldItems[ template ][ item ] !== NewItems[ template ][ item ] ) {
return true;
}
}
var oldParams = OldItems[ template ].parameters,
newParams = NewItems[ template ].parameters;
if ( Object.keys( oldParams ).length !== Object.keys( newParams ).length ) {
return true;
}
for ( var
if (
return true;
}
for ( var paramitem in oldParams[ param ] ) {
if ( paramitem != "value" || ( typeof( oldParams[ param ][ paramitem ] ) != "object" && typeof( newParams[ param ][ paramitem ] ) != "object" ) ) {
if (
return true;
}
} else {
return true;
for ( var a = 0, l = oldParams[ param ][ paramitem ].length; a < l; a++ ) {
if ( oldParams[ param ][ paramitem ][ a ] != newParams[ param ][ paramitem ][ a ] ) {
return true;
}
}
}
}
}
}
Riga 1 426 ⟶ 1 391:
}
/
lrcTexts.IT_InsertTemplate1 = "Inserisce il template {{";
Riga 1 440 ⟶ 1 403:
lrcTexts.IT_AddOption = "Aggiungi una nuova opzione";
lrcParamDesc.DescIT_InsertTemplate1 = "[InserisciTemplate] Inserisci la parte 1 della frase del template";
lrcParamDesc.DescIT_InsertTemplate2 = "[InserisciTemplate] Inserisci la parte 2 della frase del template";
Riga 1 457 ⟶ 1 418:
// Hide/Show tabs panel item
addParamMenuTab( "InserisciTemplateLegend", true );
|