r74509 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74508‎ | r74509 | r74510 >
Date:12:45, 8 October 2010
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Changes for 0.4 - fixed issue caused by earlier refactoring and improved error message for inArray criterion
Modified paths:
  • /trunk/extensions/Validator/Validator.i18n.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionInArray.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionItemCount.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionMatchesRegex.php (modified) (history)
  • /trunk/extensions/Validator/includes/criteria/CriterionUniqueItems.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/criteria/CriterionMatchesRegex.php
@@ -46,7 +46,7 @@
4747 * @see ItemParameterCriterion::getItemErrorMessage
4848 */
4949 protected function getItemErrorMessage( Parameter $parameter ) {
50 - return wfMsgExt( 'validator_error_invalid_argument', 'parsemag', $parameter->value, $parameter->getOriginalName() );
 50+ return wfMsgExt( 'validator_error_invalid_argument', 'parsemag', $parameter->getValue(), $parameter->getOriginalName() );
5151 }
5252
5353 /**
Index: trunk/extensions/Validator/includes/criteria/CriterionInArray.php
@@ -58,14 +58,30 @@
5959 protected function getItemErrorMessage( Parameter $parameter ) {
6060 global $wgLang;
6161
62 - return wfMsgExt(
63 - 'validator_error_accepts_only',
64 - 'parsemag',
65 - $parameter->getOriginalName(),
66 - $wgLang->listToText( $this->allowedValues ),
67 - count( $this->allowedValues ),
68 - $parameter->value
69 - );
 62+ $values = $parameter->getValue();
 63+ $originalCount = count( $this->allowedValues );
 64+
 65+ if ( $originalCount > 15 ) {
 66+ $allowedValues = array_slice( $this->allowedValues, 0, 13 );
 67+ return wfMsgExt(
 68+ 'validator-error-accepts-only-omitted',
 69+ 'parsemag',
 70+ $parameter->getOriginalName(),
 71+ $parameter->getValue(),
 72+ $wgLang->listToText( $allowedValues ),
 73+ $originalCount - count( $allowedValues )
 74+ );
 75+ }
 76+ else {
 77+ return wfMsgExt(
 78+ 'validator_error_accepts_only',
 79+ 'parsemag',
 80+ $parameter->getOriginalName(),
 81+ $wgLang->listToText( $this->allowedValues ),
 82+ count( $this->allowedValues ),
 83+ $parameter->getValue()
 84+ );
 85+ }
7086 }
7187
7288 /**
Index: trunk/extensions/Validator/includes/criteria/CriterionItemCount.php
@@ -35,7 +35,7 @@
3636 * @see ParameterCriterion::validate
3737 */
3838 public function validate( Parameter $parameter ) {
39 - $count = count( $parameter->value );
 39+ $count = count( $parameter->getValue() );
4040 return $count <= $this->upperBound && $count >= $this->lowerBound;
4141 }
4242
Index: trunk/extensions/Validator/includes/criteria/CriterionUniqueItems.php
@@ -26,7 +26,7 @@
2727 * @see ParameterCriterion::validate
2828 */
2929 public function validate( Parameter $parameter ) {
30 - return count( $parameter->value ) == count( array_unique( $parameter->value ) );
 30+ return count( $parameter->getValue() ) == count( array_unique( $parameter->getValue() ) );
3131 }
3232
3333 }
\ No newline at end of file
Index: trunk/extensions/Validator/Validator.i18n.php
@@ -60,6 +60,7 @@
6161
6262 // Criteria errors for single values & lists
6363 'validator_error_accepts_only' => 'The value "$4" is not valid for parameter $1. It only accepts {{PLURAL:$3|this value|these values}}: $2.',
 64+ 'validator-error-accepts-only-omitted' => 'The value "$2" is not valid for parameter $1. It only accepts these values: $3 (and $4 omitted values).'
6465 );
6566
6667 /** Message documentation (Message documentation)

Follow-up revisions

RevisionCommit summaryAuthorDate
r74515Follow up to r74509 - fixed i18n issuesjeroendedauw14:02, 8 October 2010
r74516Follow up to r74509 - fixed i18n issuesjeroendedauw14:07, 8 October 2010

Comments

#Comment by Siebrand (talk | contribs)   13:05, 8 October 2010

$3 and $4 in message key 'validator-error-accepts-only-omitted' require plural support.

#Comment by Jeroen De Dauw (talk | contribs)   13:17, 8 October 2010

They can only be plural - does that still require plural support in the message? I actually removed it after copying the above, as it's unneeded complexity.

#Comment by Siebrand (talk | contribs)   13:43, 8 October 2010

It does for languages that have more than one plural form.

#Comment by Raymond (talk | contribs)   13:48, 8 October 2010

And while you are at it: $4 needs a run through $wgLang->formatNum().

#Comment by Jeroen De Dauw (talk | contribs)   14:07, 8 October 2010

Should be fixed now.

Status & tagging log