r97052 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97051‎ | r97052 | r97053 >
Date:13:10, 14 September 2011
Author:catrope
Status:ok (Comments)
Tags:
Comment:
RL2: Followup to r96954 and r97005: add i18n messages for the validation stuff. The messages aren't very good at this point and may need tweaking, but at least they exist now. Merged the notanobject message into the invalidjson message because the distinction between 3A (invalid JSON) and 3 (valid JSON, but of type integer) is not really important.
Modified paths:
  • /branches/RL2/extensions/Gadgets/Gadgets.i18n.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/Gadget.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/Gadgets.i18n.php
@@ -78,6 +78,11 @@
7979 'gadgetmanager-modifylink-tooltip' => 'Modify this gadget',
8080 'gadgetmanager-deletelink' => 'delete',
8181 'gadgetmanager-deletelink-tooltip' => 'Delete ths gadget',
 82+
 83+ # Validation error messages
 84+ 'gadget-validate-invalidjson' => 'The gadget definition page contents are not a valid JSON object.',
 85+ 'gadget-validate-notset' => 'The property $1 is not set.',
 86+ 'gadget-validate-wrongtype' => 'The property $1 must be of type $2 instead of $3.',
8287
8388 # Permissions
8489 'gadgets-cant-create' => 'You do not have the right to create new Gadgets.',
@@ -127,7 +132,11 @@
128133 * $2 is a link to a user page with a user name as link text, followed by a series of related links
129134 * $3 is the date
130135 * $4 is the time
131 -* $5 is the user name which can be used with GENDER'
 136+* $5 is the user name which can be used with GENDER',
 137+ 'gadget-validate-notset' => '$1 is the name of the property, e.g. settings.rights .',
 138+ 'gadget-validate-wrongtype' => '* $1 is the name of the property, e.g. settings.rights or module.messages[3].
 139+* $2 is the type that this property is expected to have
 140+* $3 is the type it actually had',
132141 );
133142
134143 /** Afrikaans (Afrikaans)
Index: branches/RL2/extensions/Gadgets/backend/Gadget.php
@@ -69,13 +69,9 @@
7070 * @return Status object with error message if applicable
7171 */
7272 public static function validatePropertiesArray( $properties ) {
73 - if ( $properties === null ) {
 73+ if ( $properties === null || !is_array( $properties ) ) {
7474 return Status::newFatal( 'gadgets-validate-invalidjson' );
7575 }
76 - if ( !is_array( $properties ) ) {
77 - return Status::newFatal( 'gadgets-validate-notanobject', gettype( $properties ) ); // Use JSON terminology
78 - }
79 -
8076 foreach ( self::$propertyValidation as $property => $validation ) {
8177 $path = explode( '.', $property );
8278 $val = $properties;

Follow-up revisions

RevisionCommit summaryAuthorDate
r99049[RL2] Fix message keys (follows-up r97052 and friends about validation)krinkle20:38, 5 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96954RL2: Put in some more sophisticate validation code for gadget property arrays...catrope11:24, 13 September 2011
r97005R2: Adding some comments that helped me understand Gadget::validateProperties...krinkle21:45, 13 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   13:36, 14 September 2011

Could you also add examples of possible values for $2 and $3 in the docs?

#Comment by Nikerabbit (talk | contribs)   13:38, 14 September 2011

Is this the full change? I don't see those new messages being mentioned in the changes?

#Comment by Krinkle (talk | contribs)   17:06, 14 September 2011

It's a follow-up to r96954, which used these message keys.

Status & tagging log