r60387 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60386‎ | r60387 | r60388 >
Date:12:03, 25 December 2009
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Modified paths:
  • /trunk/extensions/Validator/Validator.class.php (modified) (history)
  • /trunk/extensions/Validator/Validator.php (modified) (history)
  • /trunk/extensions/Validator/Validator_Functions.php (modified) (history)
  • /trunk/extensions/Validator/Validator_Manager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/Validator.class.php
@@ -56,6 +56,7 @@
5757 'is_integer' => array( 'ValidatorFunctions', 'is_integer' ),
5858 'not_empty' => array( 'ValidatorFunctions', 'not_empty' ),
5959 'has_length' => array( 'ValidatorFunctions', 'has_length' ),
 60+ 'regex' => array( 'ValidatorFunctions', 'regex' ),
6061 );
6162
6263 /**
Index: trunk/extensions/Validator/Validator_Functions.php
@@ -110,4 +110,16 @@
111111 public static function has_unique_items( array $values ) {
112112 return count($values) == count(array_unique($values));
113113 }
 114+
 115+ /**
 116+ * Returns the result of preg_match.
 117+ *
 118+ * @param string $value
 119+ * @param string $pattern
 120+ *
 121+ * @return boolean
 122+ */
 123+ public static function regex( $value, $pattern ) {
 124+ return preg_match($pattern, $value);
 125+ }
114126 }
Index: trunk/extensions/Validator/Validator_Manager.php
@@ -81,7 +81,7 @@
8282 $msg = wfMsgExt( 'validator_list_error_empty_argument', array( 'parsemag' ), $error['name'] );
8383 break;
8484 case 'in_range' :
85 - $msg = wfMsgExt( 'validator_list_error_invalid_range', array( 'parsemag' ), $error['name'], $error['args'][0], $error['args'][1] );
 85+ $msg = wfMsgExt( 'validator_list_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0]. '</b>', '<b>' .$error['args'][1]. '</b>' );
8686 break;
8787 case 'is_numeric' :
8888 $msg = wfMsgExt( 'validator_list_error_must_be_number', array( 'parsemag' ), $error['name'] );
@@ -111,7 +111,7 @@
112112 $errors[] = wfMsgExt( 'validator_error_empty_argument', array( 'parsemag' ), $error['name'] );
113113 break;
114114 case 'in_range' :
115 - $errors[] = wfMsgExt( 'validator_error_invalid_range', array( 'parsemag' ), $error['name'], $error['args'][0], $error['args'][1] );
 115+ $errors[] = wfMsgExt( 'validator_error_invalid_range', array( 'parsemag' ), $error['name'], '<b>' . $error['args'][0]. '</b>', '<b>' .$error['args'][1]. '</b>' );
116116 break;
117117 case 'is_numeric' :
118118 $errors[] = wfMsgExt( 'validator_error_must_be_number', array( 'parsemag' ), $error['name'] );
@@ -124,7 +124,7 @@
125125 $errors[] = wfMsgExt( 'validator_error_accepts_only', array( 'parsemag' ), $error['name'], $itemsText, count( $error['args'] ) );
126126 break;
127127 case 'invalid' : default :
128 - $errors[] = wfMsgExt( 'validator_error_invalid_argument', array( 'parsemag' ), $error['value'], $error['name'] );
 128+ $errors[] = wfMsgExt( 'validator_error_invalid_argument', array( 'parsemag' ), '<b>' . $error['value'] . '</b>', $error['name'] );
129129 break;
130130 }
131131 }
Index: trunk/extensions/Validator/Validator.php
@@ -24,7 +24,7 @@
2525 die( 'Not an entry point.' );
2626 }
2727
28 -define( 'Validator_VERSION', '0.2 a7' );
 28+define( 'Validator_VERSION', '0.2 a8' );
2929
3030 // Constants indicating the strictness of the parameter validation.
3131 define( 'Validator_ERRORS_NONE', 0 );

Comments

#Comment by Nikerabbit (talk | contribs)   15:11, 25 December 2009

preg_match returns int and not boolean to be exact.

#Comment by Jeroen De Dauw (talk | contribs)   15:17, 25 December 2009

Do you think I should do this instead? Changing the return type to int might be confusing. return preg_match($pattern, $value) == 1;

#Comment by Nikerabbit (talk | contribs)   15:25, 25 December 2009

Or just return (bool) preg_match($pattern, $value);? It's probably insignificant but better not to mislead anybody.

#Comment by Jeroen De Dauw (talk | contribs)   15:40, 25 December 2009

Yeah, ok. Will be done in my next commit.

Status & tagging log