מדיה ויקי:Gadget-TemplateParamWizard.js: הבדלים בין גרסאות בדף
מאין תקציר עריכה |
מ 148 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-TemplateParamWizard.js יובאו |
||
| (38 גרסאות ביניים של 4 משתמשים אינן מוצגות) | |||
| שורה 40: | שורה 40: | ||
localStorageKey = 'templateParamWizard', | localStorageKey = 'templateParamWizard', | ||
emptiesKey = 'writeEmpties', | emptiesKey = 'writeEmpties', | ||
oneLineTemplate = 'oneLineTemplate'; | oneLineTemplate = 'oneLineTemplate', | ||
allAliases = []; | |||
function addParam(name) { | function addParam(name) { | ||
| שורה 79: | שורה 80: | ||
} | } | ||
if (name && paramPair.length) { | if (name && paramPair.length) { | ||
var tp = templateParams[name] = templateParams[name] || {options: {notInParamPage: 1}}; | var tp = templateParams[name] = | ||
templateParams[name] || | |||
~allAliases.indexOf(name) && { param:{}, options: {isAlias: 1} } || | |||
{param: {}, options: { notInParamPage: 1}}; | |||
addParam(name); | addParam(name); | ||
$.extend( tp.options, { defval: val } ); | $.extend( tp.options, { defval: val } ); | ||
| שורה 96: | שורה 100: | ||
while (m = paramExtractor.exec(data)) { | while (m = paramExtractor.exec(data)) { | ||
var paramName = $.trim(m[1]); | var paramName = $.trim(m[1]); | ||
templateParams[paramName] = {desc: '', options: {multiline: 5}}; | templateParams[paramName] = { desc: '', options: {multiline: 5}, label: paramName, param:{} }; | ||
addParam(paramName); | addParam(paramName); | ||
} | } | ||
| שורה 104: | שורה 108: | ||
var params = data.params, | var params = data.params, | ||
paramOrder = data.paramOrder; | paramOrder = data.paramOrder; | ||
function optionsOfParam(param) { | |||
var options = {}; | |||
if (param.required) options.required = true; | |||
if (param.suggestedvalues && param.suggestedvalues.length) options.choices = param.suggestedvalues.join(','); | |||
return options; | |||
} | |||
function onemore(name) { | function onemore(name) { | ||
var param = params[name]; | var param = params[name]; | ||
templateParams[name] = { desc: param.description | if (param.deprecated) | ||
return; // ignore deprecated parameters - pretend they are not in TD. | |||
templateParams[name] = { | |||
desc: param.description || '', | |||
options: optionsOfParam(param), | |||
label: param.label || name, | |||
param: param | |||
}; | |||
if (param.aliases) $.merge(allAliases, param.aliases); // collect alliases if there are any | |||
addParam(name); | addParam(name); | ||
} | } | ||
| שורה 210: | שורה 229: | ||
var par = [template], | var par = [template], | ||
delim = $('#' + oneLineTemplate).prop('checked') ? '' : '\n', | delim = $('#' + oneLineTemplate).prop('checked') ? '' : '\n', | ||
createEmpties = $('#createEmpties').prop('checked'); | paramValueDelim = $('#' + oneLineTemplate).prop('checked') ? '=' : ' = ', | ||
createEmpties = $('#createEmpties').prop('checked'), | |||
mustNumberNameless, | |||
valuedOrdered; | |||
for (var i = dialogFields.length - 1; i >= 0; i--) { | |||
var field = dialogFields[i], | |||
val = $.trim(field[1].val()); | |||
if (isNaN(field[0])) continue; // look only at order-based fields | |||
mustNumberNameless |= | |||
/=/.test(val) // order-based value containing "=" | |||
|| valuedOrdered && !val; // empty ordered w lower index than a non-empty one. | |||
if (val) valuedOrdered = true; | |||
} | |||
for (var i in dialogFields) { | for (var i in dialogFields) { | ||
var | var | ||
| שורה 217: | שורה 252: | ||
f = field[1], | f = field[1], | ||
opts = f.data('options'), | opts = f.data('options'), | ||
param = templateParams[name], | |||
hidden = f.parents('.tpw_hidden').length, | hidden = f.parents('.tpw_hidden').length, | ||
val = f.val().replace( /\s+$/, '' ); // leave leading newlines, for lists etc., but remove trailing. | val = f.val().replace( /\s+$/, '' ); // leave leading newlines, for lists etc., but remove trailing. | ||
if (param && param.param && param.param.type === 'url') | |||
val = val.replace(/\|/g, '{{!}}'); | |||
if (f.attr('type') == 'checkbox' && ! f.prop('checked')) | if (f.attr('type') == 'checkbox' && ! f.prop('checked')) | ||
val = ""; | val = ""; | ||
if ( ( !createEmpties || opts.notInParamPage ) && $.trim( val ) === "" ) | if ( ( !createEmpties || opts.notInParamPage ) && $.trim( val ) === "" ) | ||
continue;//skip parameters with no value | continue;//skip parameters with no value | ||
var next = mustNumberNameless || isNaN(name) | |||
? name + paramValueDelim + $.trim( val ) | |||
: $.trim( val ); | |||
par.push(next); | |||
} | } | ||
return "{{" + par.join(delim + "|") + delim + "}}"; | return "{{" + par.join(delim + ($('#' + oneLineTemplate).prop('checked')? "|" : "| ")) + delim + "}}"; | ||
} | } | ||
| שורה 279: | שורה 321: | ||
case 'choices': return 'خيارات'; | case 'choices': return 'خيارات'; | ||
case 'date': return 'تاريخ'; | case 'date': return 'تاريخ'; | ||
case 'extended': return ' | case 'extended': return 'مفصل'; | ||
case 'button hint': return 'معالج وسائط القالب'; | case 'button hint': return 'معالج وسائط القالب'; | ||
case 'template selector title': return 'اكتب اسم القالب:'; | case 'template selector title': return 'اكتب اسم القالب:'; | ||
case 'notInParamPage': return 'وسيط "' + param + '" ليس من وسائط القالب'; | case 'notInParamPage': return 'وسيط "' + param + '" ليس من وسائط القالب'; | ||
| שורה 288: | שורה 329: | ||
case 'please select template': return 'اسم القالب'; | case 'please select template': return 'اسم القالب'; | ||
case 'oneliner': return 'اجعله في صف واحد'; | case 'oneliner': return 'اجعله في صف واحد'; | ||
case 'createempties': return ' | case 'createempties': return 'إضافة الوسائط فارغة'; | ||
case 'dateFormat': return 'd MM yy'; | case 'dateFormat': return 'd MM yy'; | ||
case 'extended labels': return ' | case 'extended labels': return 'عرض كل الوسائط'; | ||
default: return key; | default: return key; | ||
} | } | ||
| שורה 296: | שורה 337: | ||
case 'he': | case 'he': | ||
switch (key) { | switch (key) { | ||
case 'explain': return | case 'explain': return hebExplain(); | ||
case 'wizard dialog title': return 'מילוי הפרמטרים עבור ' + '<a href="' + mw.util.getUrl('תבנית:' + template) + '" target="_blank">' + 'תבנית:' + template + '</a>'; | case 'wizard dialog title': return 'מילוי הפרמטרים עבור ' + '<a href="' + mw.util.getUrl('תבנית:' + template) + '" target="_blank">' + 'תבנית:' + template + '</a>'; | ||
case 'ok': return 'אישור'; | case 'ok': return 'אישור'; | ||
case 'cancel': return 'ביטול'; | case 'cancel': return 'ביטול'; | ||
case 'preview': return 'תצוגה מקדימה'; | case 'preview': return 'תצוגה מקדימה'; | ||
case 'options select': return 'בחרו ערך מהרשימה'; | case 'options select': return 'בחרו ערך מהרשימה'; | ||
| שורה 314: | שורה 352: | ||
case 'extended': return 'משני'; | case 'extended': return 'משני'; | ||
case 'button hint': return 'אשף מילוי תבניות'; | case 'button hint': return 'אשף מילוי תבניות'; | ||
case 'template selector title': return 'אנא הזינו את שם התבנית:'; | case 'template selector title': return 'אנא הזינו את שם התבנית:'; | ||
case 'notInParamPage': return 'השדה "' + param + '" לא מופיע ברשימת הפרמטרים של התבנית'; | case 'notInParamPage': return 'השדה "' + param + '" לא מופיע ברשימת הפרמטרים של התבנית'; | ||
| שורה 324: | שורה 361: | ||
case 'dateFormat': return 'd בMM yy'; | case 'dateFormat': return 'd בMM yy'; | ||
case 'extended labels': return 'הראה את כל הפרמטרים'; | case 'extended labels': return 'הראה את כל הפרמטרים'; | ||
case 'pve-required-empty': return 'התבנית דורשת שפרמטר זה יקבל ערך'; | |||
case 'pve-deprecated': return 'שימוש בפרמטר מיושן'; | |||
case 'pve-incompatible': return 'שדה זה מצפה לערך מספרי'; | |||
case 'pve-no-such-name': return 'שדה זה לא קיים בתבנית'; | |||
case 'explain-pve': return 'שדות עם שגיאה מסומנים ברקע ורוד'; | |||
case 'pve-approve-close': return 'יש בתבנית שגיאות. אנא אשרו יציאה מהאשף'; | |||
} | |||
break; | |||
case 'ur': | |||
switch (key) { | |||
case 'explain': return 'جو خانے لازمی ہیں ان کے گرد سرخ رنگ کی لکیر کھینچ دی گئی ہے، بقیہ خانے اختیاری ہوں گے۔'; | |||
case 'wizard dialog title': return 'سانچہ: "' + template + '" میں مطلوبہ معلومات درج کریں۔'; | |||
case 'ok': return 'ٹھیک'; | |||
case 'cancel': return 'منسوخ کریں'; | |||
case 'params subpage': return 'پیرامیٹر'; | |||
case 'preview': return 'نمائش'; | |||
case 'options select': return 'کسی ایک کو منتخب کریں:'; | |||
case 'multiline': return 'سطروں کی تعداد'; | |||
case 'close': return 'بند کریں'; | |||
case 'required': return 'لازمی'; | |||
case 'depends': return 'اس پر موقوف ہے'; | |||
case 'defval': return 'طے شدہ'; | |||
case 'choices': return 'اختیارات'; | |||
case 'date': return 'تاریخ'; | |||
case 'extended': return 'مفصل'; | |||
case 'button hint': return 'ساحر محددات سانچہ'; | |||
case 'template selector title': return 'براہ کرم سانچہ کا نام درج کریں'; | |||
case 'notInParamPage': return 'پیرامیٹر کی فہرست میں "' + param + '" ظاہر نہیں ہو رہا ہے'; | |||
case 'editParamPage': return 'پیرامیٹر کے صفحہ میں ترمیم کریں'; | |||
case 'unknown error': return 'نقص پیش آیا: \n' + param; | |||
case 'please select template': return 'براہ کرم سانچہ کا نام درج کریں'; | |||
case 'oneliner': return 'یک سطری'; | |||
case 'createempties': return 'صفحہ میں خالی پیرامیٹر درج کریں'; | |||
case 'dateFormat': return 'd MM yy'; | |||
case 'extended labels': return 'تمام پیرامیٹر دکھائیں'; | |||
} | } | ||
break; | break; | ||
case 'ru': | |||
switch (key) { | |||
case 'explain': return 'поля с красной рамкой обязательны, остальные - по желанию'; | |||
case 'wizard dialog title': return 'Настройте параметры для шаблона: ' + template; | |||
case 'ok': return 'OK'; | |||
case 'cancel': return 'Отмена'; | |||
case 'params subpage': return 'Параметры'; | |||
case 'preview': return 'Просмотр'; | |||
case 'options select': return 'Выбрать:'; | |||
case 'multiline': return 'Многострочный вид'; | |||
case 'close': return 'Закрыть'; | |||
case 'required': return 'Необходимое'; | |||
case 'depends': return 'Зависит от'; | |||
case 'defval': return 'По умолчанию'; | |||
case 'choices': return 'Выбор'; | |||
case 'date': return 'Дата'; | |||
case 'extended': return 'Расширенный'; | |||
case 'button hint': return 'Мастер параметров шаблона'; | |||
case 'able templates category name': throw('Необходимо определить название категории для шаблонов с поддержкой мастера'); | |||
case 'template selector title': return 'Пожалуйста, введите имя шаблона'; | |||
case 'notInParamPage': return 'поле "' + param + '" не отображается в списке параметров шаблона'; | |||
case 'editParamPage': return 'Править страницу параметров'; | |||
case 'unknown error': return 'Произошла ошибка: \n' + param; | |||
case 'please select template': return 'Пожалуйста, введите имя шаблона'; | |||
case 'oneliner': return 'Однострочный вид'; | |||
case 'dateFormat': return 'ММ дд, гг'; | |||
case 'extended labels': return 'Показать все параметры'; | |||
} | |||
default: | default: | ||
switch (key) { | switch (key) { | ||
| שורה 344: | שורה 444: | ||
case 'extended': return 'Extended'; | case 'extended': return 'Extended'; | ||
case 'button hint': return 'Template parameters wizard'; | case 'button hint': return 'Template parameters wizard'; | ||
case 'template selector title': return 'Please enter the template name'; | case 'template selector title': return 'Please enter the template name'; | ||
case 'notInParamPage': return 'field "' + param + '" does not appear in the template\'s parameters list'; | case 'notInParamPage': return 'field "' + param + '" does not appear in the template\'s parameters list'; | ||
| שורה 354: | שורה 453: | ||
case 'dateFormat': return 'MM d, yy'; | case 'dateFormat': return 'MM d, yy'; | ||
case 'extended labels': return 'Show all parameters'; | case 'extended labels': return 'Show all parameters'; | ||
case 'pve-required-empty': return 'The template requires a value for this filedך'; | |||
case 'pve-deprecated': return 'deprecated parameter'; | |||
case 'pve-incompatible': return 'expaects numteric value'; | |||
case 'pve-no-such-name': return 'undercgonzed parameter'; | |||
case 'explain-pve': return 'fields with errors are marked with pink background'; | |||
case 'pve-approve-close': return 'Template contains errors. Please confim exit'; | |||
} | } | ||
} | } | ||
| שורה 359: | שורה 464: | ||
} | } | ||
function | function hebExplain() { | ||
var explanation; | |||
function templatePage() {return mw.config.get('wgFormattedNamespaces')[10] + ':' + | if (rawTemplate) return 'לתבנית "' + template + '" אין דף פרמטרים, ולכן לשדות אין תיאור.'; | ||
if (anyRequiredParam()) return 'שדות חובה מסומנים במסגרת אדומה'; | |||
return ''; | |||
} | |||
function anyRequiredParam() { | |||
for (name in templateParams) { | |||
var param = templateParams[name]; | |||
if (param.options.required) return true; | |||
} | |||
return false; | |||
} | |||
function templatePage() { | |||
var t = $.trim(template) | |||
return t.match(':') ? t : mw.config.get('wgFormattedNamespaces')[10] + ':' + t; | |||
} | |||
function updateRawPreview(){ | function updateRawPreview(){ | ||
| שורה 381: | שורה 502: | ||
$('#tpw_preview').text(createWikiCode()); | $('#tpw_preview').text(createWikiCode()); | ||
localStorage.setItem(localStorageKey + '.' + emptiesKey, $('#createEmpties').prop('checked')); | localStorage.setItem(localStorageKey + '.' + emptiesKey, $('#createEmpties').prop('checked')); | ||
validate(); | |||
} | |||
function validate() { | |||
function validateField(param, input) { | |||
function markError(msg) { | |||
input | |||
.addClass('tpw-paramvalidation') | |||
.attr('title', i18n(msg)); | |||
return false; | |||
} | |||
var hasVal = !! input.val(); | |||
if (param.options.notInParamPage && hasVal) return markError('pve-no-such-name'); | |||
if (param.param.required && ! hasVal) return markError('pve-required-empty'); | |||
if (param.param.deprecated && hasVal) return markError('pve-deprecated'); | |||
if (param.param.type === 'number' && isNaN( Number( input.val().replace(/,/g, '') ) ) ) return markError('pve-incompatible'); | |||
return true; | |||
} | |||
var aOK = true; | |||
for (var i in dialogFields) { | |||
var | |||
field = dialogFields[i], | |||
name = $.trim(field[0]), | |||
input = field[1].removeClass('tpw-paramvalidation'), | |||
param = templateParams[name]; | |||
aOK = validateField(param, input) && aOK; | |||
} | |||
$('#tpw-explain').html(i18n(aOK ? 'explain' : 'explain-pve') ); | |||
return aOK; | |||
} | } | ||
function createInputField(paramName) { | function createInputField(paramName) { | ||
var | var params = templateParams[paramName], | ||
options = params.options || {}, | |||
f, | f, | ||
checkbox = false; | checkbox = false; | ||
| שורה 391: | שורה 548: | ||
var choices = options.choices.split(/\s*,\s*/); | var choices = options.choices.split(/\s*,\s*/); | ||
if (choices.length > 1) { | if (choices.length > 1) { | ||
f = $('<select>').append($('<option>', {text: i18n('options select'), value: ''})); | f = $('<select>').append($('<option>', {text: i18n('options select'), value: '' })); | ||
for (var i in choices) | for (var i in choices) { | ||
var choice = choices[i].trim(); // first and last may carry spaces | |||
var option = $('<option>', {text: choice, value: choice}); | |||
f.append(option); | |||
} | |||
} | } | ||
else { | else { | ||
checkbox = true; | checkbox = true; | ||
f = $('<input>', {type: 'checkbox', value: choices[0], text: choices[0]}) | var choice = choices[0].trim(); | ||
f = $('<input>', {type: 'checkbox', value: choices[0], text: choices[0].trim()}) | |||
.css({float: rtl ? 'right' : 'left'}); | .css({float: rtl ? 'right' : 'left'}); | ||
f.prop('checked', options.defval && options.defval == choices[0]); | f.prop('checked', options.defval && options.defval.trim() == choices[0]); | ||
} | } | ||
} | } | ||
| שורה 405: | שורה 566: | ||
var rows = options.multiline; | var rows = options.multiline; | ||
f = $('<textarea>', {rows: 1}) | f = $('<textarea>', {rows: 1}) | ||
.focus(function(){this.rows = 5;}) | |||
.focus(function(){this.rows = | |||
.blur(function(){this.rows = 1}); | .blur(function(){this.rows = 1}); | ||
} | } | ||
| שורה 419: | שורה 579: | ||
.on('paste cut drop input change', updateRawPreview); | .on('paste cut drop input change', updateRawPreview); | ||
if (options.defval) | if (options.defval && ! checkbox) | ||
f.val(options.defval); | f.val(options.defval.trim()); | ||
if (options.required) | if (options.required) | ||
f.addClass(' | f.addClass('tpw-required'); | ||
if (options.date) | if (options.date) | ||
f.datepicker({dateFormat: typeof options.date == "string" ? options.date : i18n('dateFormat')}); | f.datepicker({dateFormat: typeof options.date == "string" ? options.date : i18n('dateFormat')}); | ||
return f; | return f; | ||
} | } | ||
| שורה 449: | שורה 610: | ||
function tipsyContent() { | function tipsyContent() { | ||
var | var | ||
paramName = $(this). | paramName = $(this).data('paramname'), | ||
def = templateParams[paramName], | def = templateParams[paramName], | ||
desc = def.desc || ''; | desc = def && def.desc || ''; | ||
if (!def) return ''; // early terminate if param name is not valid | |||
if (def.htmlDesc) | if (def.htmlDesc) | ||
return def.htmlDesc; | return def.htmlDesc; | ||
if (wikiCodeFinder.test(desc)) // does it need parsing? | if (wikiCodeFinder.test(desc)) // does it need parsing? | ||
$.ajax({ | $.ajax({ | ||
| שורה 480: | שורה 637: | ||
def = templateParams[paramName], | def = templateParams[paramName], | ||
inputField = createInputField(paramName), | inputField = createInputField(paramName), | ||
nameColor = def.desc ? 'blue' : | nameColor = def.desc | ||
? 'blue' | |||
: def.options.notInParamPage | |||
? 'red' | |||
: def.options.isAlias | |||
? 'green' | |||
: 'black', | |||
tr = $('<tr>') | tr = $('<tr>') | ||
.append( | .append( | ||
$('<td>', {width: 120}) | $('<td>', {width: 120}) | ||
.css({fontWeight: 'bold', color: nameColor}) | .css({fontWeight: 'bold', color: nameColor}) | ||
.text(paramName) | .data({ paramname: paramName }) | ||
.text(templateParams[paramName].label || paramName) | |||
.tipsy({html: true, trigger: 'manual', title: tipsyContent}) | .tipsy({html: true, trigger: 'manual', title: tipsyContent}) | ||
.mouseenter(function() { | .mouseenter(function() { | ||
| שורה 520: | שורה 684: | ||
function buildDialog(data) { | function buildDialog(data) { | ||
var title = $('<span>').html(i18n('wizard dialog title', template)); | |||
$('.tpw_disposable').remove(); | $('.tpw_disposable').remove(); | ||
if (rawTemplate) | if (rawTemplate) | ||
buildParamsRaw(data); | buildParamsRaw(data); | ||
else if (tdTemplate) | else if (tdTemplate) { | ||
buildParamsTd(data) | buildParamsTd(data); | ||
if (data.description) title.find('a').attr({ title: data.description }); | |||
} | |||
paramsFromSelection(); | paramsFromSelection(); | ||
| שורה 532: | שורה 698: | ||
var dialog = $('<div>', {'class': 'tpw_disposable'}) | var dialog = $('<div>', {'class': 'tpw_disposable'}) | ||
.dialog({height: 'auto', | .dialog({height: 'auto', | ||
title: | title: title.html(), | ||
width: 'auto', | width: 'auto', | ||
overflow: 'auto', | overflow: 'auto', | ||
| שורה 539: | שורה 705: | ||
}) | }) | ||
.append($('<div>', {id: 'tpw_globalExplanation'}).html(globalExplanation)) | .append($('<div>', {id: 'tpw_globalExplanation'}).html(globalExplanation)) | ||
.append($('<p>').html(i18n('explain'))) | .append($('<p>', { id: 'tpw-explain' } ).html(i18n('explain')) ) | ||
.append(anyExtended ? createExtendedCheckBox() : '') | .append(anyExtended ? createExtendedCheckBox() : '') | ||
.append(table) | .append(table) | ||
| שורה 554: | שורה 720: | ||
) | ) | ||
) | ) | ||
.append($('<pre>', {id: 'tpw_preview'}) | .append($('<pre>', {id: 'tpw_preview'}).addClass('tpw-wikicode-preview')); | ||
while (paramsOrder.length) | while (paramsOrder.length) | ||
addRow(paramsOrder.shift(), table); | addRow(paramsOrder.shift(), table); | ||
var buttons = {}; // we need to do it this way, because with literal object, the keys must be literal. | var buttons = {}; // we need to do it this way, because with literal object, the keys must be literal. | ||
buttons[i18n('ok')] = function() {injectResults(); dialog.dialog('close'); }; | buttons[i18n('ok')] = function() { | ||
if (! validate() && ! confirm(i18n('pve-approve-close' ) ) ) return; | |||
injectResults(); | |||
dialog.dialog('close'); | |||
}; | |||
buttons[i18n('cancel')] = function() {dialog.dialog('close');}; | buttons[i18n('cancel')] = function() {dialog.dialog('close');}; | ||
buttons[i18n('preview')] = showPreview; | buttons[i18n('preview')] = showPreview; | ||
| שורה 643: | שורה 813: | ||
$.ajax({ | $.ajax({ | ||
url: mw.util.wikiScript('api'), | url: mw.util.wikiScript('api'), | ||
data: {action: 'templatedata', titles: templatePage(), redirects: true, format: 'json'}, | data: {action: 'templatedata', titles: templatePage(), redirects: true, format: 'json', lang: mw.config.get('wgUserLanguage') }, | ||
dataType: 'json', | dataType: 'json', | ||
success: function(data) { | success: function(data) { | ||
| שורה 662: | שורה 832: | ||
rawTemplate = false; | rawTemplate = false; | ||
readTemplateData(); | |||
} | } | ||
| שורה 710: | שורה 873: | ||
function doIt() { | function doIt() { | ||
mw.loader.using(['jquery.ui | mw.loader.using(['jquery.ui','jquery.tipsy','jquery.textSelection', 'mediawiki.api'], function() { | ||
init(); | init(); | ||
var match = templateContext().match(/^\{\{([^|}]*)/); | var match = templateContext().match(/^\{\{([^|}]*)/); | ||