Warn editors when they're adding blank TemplateData

Bug: T123207
Change-Id: I512ce01a0c7221e7636d26e546d1cbac5395b76b
This commit is contained in:
Alex Monk 2016-07-12 23:40:46 +01:00
parent 0e1dc9732b
commit 1de010108e
4 changed files with 32 additions and 1 deletions

View file

@ -108,6 +108,7 @@
"templatedata-doc-param-type-wiki-user-name",
"templatedata-editbutton",
"templatedata-errormsg-jsonbadformat",
"templatedata-errormsg-insertblank",
"templatedata-exists-on-related-page",
"templatedata-modal-button-add-language",
"templatedata-modal-button-addparam",

View file

@ -46,6 +46,7 @@
"templatedata-doc-params": "Template parameters",
"templatedata-editbutton": "Manage TemplateData",
"templatedata-errormsg-jsonbadformat": "Bad JSON format. You can cancel this operation so you can correct it, delete the current <templatedata> tags and try again, or continue to replace the current TemplateData with a new one.",
"templatedata-errormsg-insertblank": "Are you sure you want to insert TemplateData with no information?",
"templatedata-exists-on-related-page": "Please note: there is already a TemplateData block on the related page \"[[$1]]\".",
"templatedata-helplink": "Information about TemplateData",
"templatedata-helplink-target": "//www.mediawiki.org/wiki/Special:MyLanguage/Help:TemplateData",

View file

@ -56,6 +56,7 @@
"templatedata-doc-params": "Used as caption for the table which describes the parameter or parameters of the current template. If using plural is an issue in your language, you may try and translate as \"Description of each parameter\" or similar.\nThe table has the following headings:\n* {{msg-mw|Templatedata-doc-param-name}}\n* {{msg-mw|Templatedata-doc-param-desc}}\n* {{msg-mw|Templatedata-doc-param-default}}\n* {{msg-mw|Templatedata-doc-param-status}}\n{{Identical|Template parameter}}",
"templatedata-editbutton": "The label of the button to manage templatedata, appearing above the editor field.",
"templatedata-errormsg-jsonbadformat": "Error message that appears in case the JSON string is not possible to parse. The user is asked to choose between correcting or deleting the json or continuing with the editing process and replacing the string completely.",
"templatedata-errormsg-insertblank": "Error message that appears when the user attempts to apply TemplateData that contains nothing useful.",
"templatedata-exists-on-related-page": "A messaged that is displayed when there already is a templatedata string in a related page. $1: The page where templatedata already exists.",
"templatedata-helplink": "The label of the link to the TemplateData documentation, appearing above the editor field.",
"templatedata-helplink-target": "{{ignore}} The target of the link to the TemplateData documentation",

View file

@ -180,7 +180,35 @@
* @param {Object} templateData New templatedata
*/
onDialogApply = function ( templateData ) {
$textbox.val( replaceTemplateData( templateData ) );
if (
Object.keys( templateData ).length > 1 ||
Object.keys( templateData.params ).length > 0
) {
$textbox.val( replaceTemplateData( templateData ) );
} else {
windowManager.closeWindow( windowManager.getCurrentWindow() );
windowManager.openWindow( messageDialog, {
title: mw.msg( 'templatedata-modal-title' ),
message: mw.msg( 'templatedata-errormsg-insertblank' ),
actions: [
{
label: mw.msg( 'templatedata-modal-button-cancel' ),
flags: [ 'primary', 'safe' ]
},
{
action: 'apply',
label: mw.msg( 'templatedata-modal-button-apply' )
}
]
} )
.then( function ( opening ) { return opening; } )
.then( function ( opened ) { return opened; } )
.then( function ( data ) {
if ( data && data.action === 'apply' ) {
$textbox.val( replaceTemplateData( templateData ) );
}
} );
}
};
return {