jenkins-bot has submitted this change and it was merged. Change subject: Make validation errors look consistent ......................................................................
Make validation errors look consistent Make it so that validation errors on Special:MassMessage and Special:CreateMassMessageList have the same styling. Includes trivial change to ext.MassMessage.special.js Change-Id: Id93584eccb0517ff333f10533d3a91bf9cc9cec7 --- M MassMessage.php M i18n/en.json M i18n/qqq.json M modules/ext.MassMessage.create.js M modules/ext.MassMessage.special.css M modules/ext.MassMessage.special.js A modules/ext.MassMessage.validation.css 7 files changed, 78 insertions(+), 64 deletions(-) Approvals: Legoktm: Looks good to me, approved Siebrand: Looks good to me, but someone else must approve Nemo bis: Looks good to me, but someone else must approve jenkins-bot: Verified diff --git a/MassMessage.php b/MassMessage.php index 3869bb3..97d09df 100644 --- a/MassMessage.php +++ b/MassMessage.php @@ -127,6 +127,7 @@ 'ext.MassMessage.special.js', 'ext.MassMessage.badhtml.js', ), + 'styles' => 'ext.MassMessage.validation.css', 'messages' => array( 'massmessage-badhtml', 'massmessage-parse-badpage' @@ -188,9 +189,10 @@ ); $wgResourceModules['ext.MassMessage.create'] = array( 'scripts' => 'ext.MassMessage.create.js', + 'styles' => 'ext.MassMessage.validation.css', 'messages' => array( - 'massmessage-create-exists', - 'massmessage-create-invalidsource', + 'massmessage-create-exists-short', + 'massmessage-create-invalidsource-short', ), 'dependencies' => array( 'mediawiki.jqueryMsg', diff --git a/i18n/en.json b/i18n/en.json index 5dadc0a..9dfc126 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -84,6 +84,8 @@ "massmessage-create-exists": "A page already exists at the specified title.", "massmessage-create-nopermission": "You do not have permission to create a list at this title.", "massmessage-create-invalidsource": "The specified source is not a valid delivery list or category with at least one page.", + "massmessage-create-exists-short": "Already in use", + "massmessage-create-invalidsource-short": "Not a valid list", "editmassmessagelist-legend": "Edit mass message delivery list", "massmessage-edit-pagetitle": "Editing $1", "massmessage-edit-title": "Title:", diff --git a/i18n/qqq.json b/i18n/qqq.json index 9654eb1..55e9e0e 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -88,6 +88,8 @@ "massmessage-create-exists": "Error message shown on [[Special:CreateMassMessageList]] when a page with the title already exists", "massmessage-create-nopermission": "Error message shown on [[Special:CreateMassMessageList]] when the user cannot create a page with the title", "massmessage-create-invalidsource": "Error message shown on [[Special:CreateMassMessageList]] when the source from which to import targets is invalid or empty", + "massmessage-create-exists-short": "Short error shown on [[Special:CreateMassMessageList]] next to the entered title when it is already in use", + "massmessage-create-invalidsource-short": "Short error shown on [[Special:CreateMassMessageList]] next to the entered source from which to import targets when it is invalid", "editmassmessagelist-legend": "Form legend for [[Special:EditMassMessageList]]", "massmessage-edit-pagetitle": "Page title for [[Special:EditMassMessageList]]\n* $1 is the title of the delivery list being edited\n{{Identical|Editing}}", "massmessage-edit-title": "Label for an inputbox on [[Special:EditMassMessageList]]\n{{Identical|Title}}", diff --git a/modules/ext.MassMessage.create.js b/modules/ext.MassMessage.create.js index c8f6427..e900ba0 100644 --- a/modules/ext.MassMessage.create.js +++ b/modules/ext.MassMessage.create.js @@ -3,23 +3,60 @@ /*global setTimeout, clearTimeout*/ 'use strict'; - var $formSource = $( '#mw-input-wpsource' ), - $formSourceTr = $formSource.parent().parent(), + var checkTitle, checkSource, pageIsValidSource, checkSourceTimeout = -1, - checkSource, pageIsValidSource, showCreateError, removeCreateError; + $formTitle = $( '#mw-input-wptitle' ), + $formSource = $( '#mw-input-wpsource' ), + $formSourceTr = $formSource.parent().parent(), + $titleStatus = $( '<span>' ) + .attr( 'id', 'mw-input-wptitle-status' ) + .insertAfter( $formTitle ), + $sourceStatus = $( '<span>' ) + .attr( 'id', 'mw-input-wptitle-status' ) + .insertAfter( $formSource ); + + checkTitle = function () { + var title = $formTitle.val(); + if ( title ) { + ( new mw.Api() ).get( { + action: 'query', + prop: 'info', + titles: title + } ).done( function ( data ) { + if ( data && data.query && !data.query.pages['-1'] ) { + // Page with title already exists + $titleStatus.addClass( 'invalid' ) + .text( mw.message( 'massmessage-create-exists-short' ).text() ); + } else { + // Clear validation error + $titleStatus.removeClass( 'invalid' ).text( '' ); + } + } ); + } else { + // Don't display an error if there is no input + $titleStatus.removeClass( 'invalid' ).text( '' ); + } + }; checkSource = function () { - ( new mw.Api() ).get( { - action: 'query', - prop: 'info', - titles: $formSource.val() - } ).done( function ( data ) { - if ( pageIsValidSource( data ) ) { - removeCreateError( 'massmessage-create-invalidsource' ); - } else { - showCreateError( 'massmessage-create-invalidsource' ); - } - } ); + var source = $formSource.val(); + if ( source ) { + ( new mw.Api() ).get( { + action: 'query', + prop: 'info', + titles: source + } ).done( function ( data ) { + if ( pageIsValidSource( data ) ) { + // Clear validation error + $sourceStatus.removeClass( 'invalid' ).text( '' ); + } else { + $sourceStatus.addClass( 'invalid' ) + .text( mw.message( 'massmessage-create-invalidsource-short' ).text() ); + } + } ); + } else { + $sourceStatus.removeClass( 'invalid' ).text( '' ); + } }; pageIsValidSource = function ( response ) { @@ -40,22 +77,6 @@ return false; }; - // Show an error next to the create form - showCreateError = function ( msgKey ) { - var message = mw.message( msgKey ).escaped(); - if ( !$( 'div.error[data-key=\'' + msgKey + '\']' ).length ) { - $( '.mw-htmlform-submit-buttons' ).prepend( - $( '<div></div>' ).addClass( 'error' ).attr( 'data-key', msgKey ) - .html( '<p>' + message + '</p>' ).hide().fadeIn() - ); - } - }; - - // Remove an error next to the create form - removeCreateError = function ( msgKey ) { - $( 'div.error[data-key=\'' + msgKey + '\']' ).remove(); - }; - // Set the correct field state on load. if ( !$( '#mw-input-wpcontent-import' ).is( ':checked' ) ) { $formSourceTr.hide(); // Progressive disclosure @@ -63,7 +84,6 @@ $( '#mw-input-wpcontent-new' ).click( function () { $formSourceTr.hide(); - removeCreateError( 'massmessage-create-invalidsource' ); } ); $( '#mw-input-wpcontent-import' ).click( function () { @@ -71,28 +91,16 @@ } ); // Warn if page title is already in use - $( '#mw-input-wptitle' ).blur( function () { - ( new mw.Api() ).get( { - action: 'query', - prop: 'info', - titles: $( this ).val() - } ).done( function ( data ) { - if ( data && data.query ) { - if ( !data.query.pages['-1'] ) { - // Page with title already exists - showCreateError( 'massmessage-create-exists' ); - } else { - removeCreateError( 'massmessage-create-exists' ); - } - } - } ); + $formTitle.one( 'blur', function () { + checkTitle(); + $formTitle.on( 'input autocompletechange', checkTitle ); } ); // Warn if delivery list source is invalid $formSource.on( 'input autocompleteselect', function () { - // debouncing - don't want to make an API call per request, nor give an error + // Debouncing - don't want to make an API call per request, nor give an error // when the user starts typing - removeCreateError( 'massmessage-create-invalidsource' ); + $sourceStatus.removeClass( 'invalid' ).text( '' ); clearTimeout( checkSourceTimeout ); checkSourceTimeout = setTimeout( checkSource, 300 ); } ); diff --git a/modules/ext.MassMessage.special.css b/modules/ext.MassMessage.special.css index ecfd4ec..0a7dc2b 100644 --- a/modules/ext.MassMessage.special.css +++ b/modules/ext.MassMessage.special.css @@ -1,21 +1,8 @@ /* Formats the Save/Preview buttons to show up on the same line -@author wctaiwan */ #mw-massmessage-form .mw-htmlform-field-HTMLSubmitField, #mw-massmessage-form .mw-htmlform-field-HTMLSubmitField .mw-label, #mw-massmessage-form .mw-htmlform-field-HTMLSubmitField .mw-input { display: inline; -} - -/* -Styles the invalid page warning - */ -#mw-massmessage-form-spamlist-status.invalid { - border: 1px solid #FF8080; - border-bottom-right-radius: 0.8em; - border-top-right-radius: 0.8em; - background-color: #FFC0C0; - color: black; - padding: 2px 1em; } diff --git a/modules/ext.MassMessage.special.js b/modules/ext.MassMessage.special.js index 1f31c1b..b4377a4 100644 --- a/modules/ext.MassMessage.special.js +++ b/modules/ext.MassMessage.special.js @@ -56,6 +56,6 @@ } ); // Autocomplete for spamlist titles - mw.massmessage.enableTitleComplete( $( '#mw-massmessage-form-spamlist' ) ); + mw.massmessage.enableTitleComplete( $spamlist ); } ); }( mediaWiki, jQuery ) ); diff --git a/modules/ext.MassMessage.validation.css b/modules/ext.MassMessage.validation.css new file mode 100644 index 0000000..ce25c70 --- /dev/null +++ b/modules/ext.MassMessage.validation.css @@ -0,0 +1,13 @@ +/* +Styles inline validation warnings + */ +#mw-massmessage-form-spamlist-status.invalid, +#mw-input-wptitle-status.invalid, +#mw-input-wptitle-status.invalid { + border: 1px solid #FF8080; + border-bottom-right-radius: 0.8em; + border-top-right-radius: 0.8em; + background-color: #FFC0C0; + color: black; + padding: 2px 1em; +} -- To view, visit https://gerrit.wikimedia.org/r/185619 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Id93584eccb0517ff333f10533d3a91bf9cc9cec7 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/extensions/MassMessage Gerrit-Branch: master Gerrit-Owner: Wctaiwan <wctai...@gmail.com> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Nemo bis <federicol...@tiscali.it> Gerrit-Reviewer: Siebrand <siebr...@kitano.nl> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits