מדיה ויקי:Gadget-TemplateParamWizard.js: הבדלים בין גרסאות בדף

בינתיים זה לא רצוי - לפי המלצת בורה בורה.
קריאת נתוני התבנית מ-TD
שורה 27: שורה 27:
// the fields, keyed by paramName
// the fields, keyed by paramName
fieldsBypName,
fieldsBypName,
// boolean, indicating we did not find "Parameters" page, so the parameters are extracted from template page itself.
// boolean, indicating the source of data is templatedata.
tdTemplate,
// boolean, indicating the source of the data is analyzing the template page itself.
rawTemplate,
rawTemplate,
isInline,
rtl = $('body').is('.rtl'),
rtl = $('body').is('.rtl'),
// test to see if a string contains wikiCode and hence needs parsing, or cen be used as is.
// test to see if a string contains wikiCode and hence needs parsing, or cen be used as is.
שורה 86: שורה 89:
addParam(paramName);
addParam(paramName);
}
}
}
function buildParamsTd(data) {
var params = data.params,
paramOrder = data.paramOrder;
function onemore(name) {
var param = params[name];
templateParams[name] = { desc: param.description && param.description.he || '', options: { required: param.required }  };
addParam(name);
}
isInline = data.format === 'inline';
if (paramOrder && paramOrder.length)
for (var ind in paramOrder)
onemore(paramOrder[ind]);
else // no order - take them as they come.
for (var paramname in params)
onemore(paramname);
}
}


שורה 468: שורה 491:
if (rawTemplate)
if (rawTemplate)
buildParamsRaw(data);
buildParamsRaw(data);
else if (tdTemplate)
buildParamsTd(data)
else
else
buildParams(data);
buildParams(data);
paramsFromSelection();
paramsFromSelection();
var table = $('<table>');
var table = $('<table>');
שורה 486: שורה 512:
.append($('<p>')
.append($('<p>')
.append(i18n('oneliner'))
.append(i18n('oneliner'))
.append($('<input>', {type: 'checkbox', id: oneLineTemplate}).change(updateRawPreview)
.append($('<input>', {type: 'checkbox', id: oneLineTemplate}).prop('checked', isInline).change(updateRawPreview)
)
)
)
)
שורה 498: שורה 524:
.append($('<pre>', {id: 'tpw_preview'})
.append($('<pre>', {id: 'tpw_preview'})
.css({backgroundColor: "lightGreen", maxWidth: '40em', maxHeight: '8em', overflow: 'auto'}));
.css({backgroundColor: "lightGreen", maxWidth: '40em', maxHeight: '8em', overflow: 'auto'}));
/* comment out temporarily - it works, but too many templates have "inline" erronously
new mw.Api().get( {
action: 'templatedata',
titles: templatePage()
} )
.done( function( data ) {
if ( data && data.pages )
for ( var pageid in data.pages ) {
var page = data.pages[pageid];
if ( page && page.format && page.format === 'inline' ) {
$( '#' + oneLineTemplate ).prop( 'checked', true );
updateRawPreview();
}
}
} );
*/
while (paramsOrder.length)
while (paramsOrder.length)
addRow(paramsOrder.shift(), table);
addRow(paramsOrder.shift(), table);
שורה 587: שורה 597:


function fireDialog() {
function fireDialog() {
var readRaw = function() {
rawTemplate = true;
$.ajax({
url: mw.util.wikiScript(),
data: {title: templatePage(), action: 'raw'},
dataType: 'text',
success: buildDialog,
error: reportError
});
},
readTemplateData = function() {
$.ajax({
url: mw.util.wikiScript('api'),
data: {action: 'templatedata', titles: templatePage(), format: 'json'},
dataType: 'json',
success: function(data) {
var found = false;
if (data && data.pages)
for (var pageid in data.pages) {
tdTemplate = true;
found = true;
buildDialog(data.pages[pageid]);
break;
}
if (! found)
readRaw();
},
error: readRaw
});
};
rawTemplate = false;
rawTemplate = false;
$.ajax({
$.ajax({
שורה 594: שורה 636:
success: buildDialog,
success: buildDialog,
cache: false,
cache: false,
error: function() {
error: readTemplateData
rawTemplate = true;
$.ajax({
url: mw.util.wikiScript(),
data: {title: templatePage(), action: 'raw'},
dataType: 'text',
success: buildDialog,
error: reportError
});
}
});
});
}
}