r72507 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72506‎ | r72507 | r72508 >
Date:20:04, 6 September 2010
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Work on ListParameter class
Modified paths:
  • /trunk/extensions/Validator/includes/ListParameter.php (modified) (history)
  • /trunk/extensions/Validator/includes/Parameter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Validator/includes/ListParameter.php
@@ -41,6 +41,15 @@
4242 protected $delimiter;
4343
4444 /**
 45+ * List of criteria the parameter value as a whole needs to hold against.
 46+ *
 47+ * @since 0.4
 48+ *
 49+ * @var array of ListParameterCriterion
 50+ */
 51+ protected $listCriteria;
 52+
 53+ /**
4554 * Constructor.
4655 *
4756 * @since 0.4
@@ -54,8 +63,24 @@
5564 */
5665 public function __construct( $name, $delimiter = ListParameter::DEFAULT_DELIMITER, $type = Parameter::TYPE_STRING,
5766 $default = null, array $aliases = array(), array $criteria = array() ) {
58 - parent::construct( $name, $type, $default, $aliases, $criteria );
 67+ $itemCriteria = array();
 68+ $listCriteria = array();
 69+
 70+ foreach ( $criteria as $criterion ) {
 71+ if ( $criterion instanceof ListParameterCriterion ) {
 72+ $listCriteria[] = $criterion;
 73+ }
 74+ else {
 75+ $itemCriteria[] = $criterion;
 76+ }
 77+ }
 78+
 79+ parent::construct( $name, $type, $default, $aliases, $itemCriteria );
 80+
5981 $this->delimiter = $delimiter;
 82+
 83+ $this->cleanCriteria( $listCriteria );
 84+ $this->listCriteria = $listCriteria;
6085 }
6186
6287 /**
@@ -67,6 +92,73 @@
6893 */
6994 public function isList() {
7095 return true;
71 - }
 96+ }
7297
 98+ /**
 99+ * Validates all items in the list.
 100+ *
 101+ * @since 0.4
 102+ *
 103+ * @return boolean
 104+ */
 105+ public function validate() {
 106+ if ( $this->setCount == 0 ) {
 107+ if ( $this->isRequired() ) {
 108+ // TODO: fatal error
 109+ $success = false;
 110+ }
 111+ else {
 112+ $success = true;
 113+ $this->value = $this->default;
 114+ }
 115+ }
 116+ else {
 117+ $this->validateListCriteria( $this->value );
 118+
 119+ // TODO
 120+
 121+ foreach ( $this->value as $item ) {
 122+ list( $itemSuccess, $itemHasError ) = $this->validateCriteria( $item );
 123+
 124+ // TODO
 125+
 126+ $success = $success && $itemSuccess;
 127+ }
 128+ }
 129+
 130+ return $success;
 131+ }
 132+
 133+ /**
 134+ *
 135+ *
 136+ * @since 0.4
 137+ *
 138+ * @param array $values
 139+ */
 140+ protected function validateListCriteria( array $values ) {
 141+ foreach ( $this->getListCriteria() as $listCriterion ) {
 142+ if ( !$listCriterion->validate( $value ) ) {
 143+ $hasError = true;
 144+
 145+ if ( !self::$accumulateParameterErrors ) {
 146+ break;
 147+ }
 148+ }
 149+ }
 150+
 151+ // TODO
 152+ }
 153+
 154+ /**
 155+ * Returns the parameter list criteria.
 156+ *
 157+ * @since 0.4
 158+ *
 159+ * @return array of ListParameterCriterion
 160+ */
 161+ public function getListCriteria() {
 162+ return $this->listCriteria;
 163+ }
 164+
73165 }
\ No newline at end of file
Index: trunk/extensions/Validator/includes/Parameter.php
@@ -357,7 +357,11 @@
358358 }
359359 }
360360 else {
361 - $success = $this->validateCriteria( $this->originalValue );
 361+ list( $success, $hasError ) = $this->validateCriteria( $this->originalValue );
 362+
 363+ if ( $hasError ) {
 364+ $this->value = $this->default;
 365+ }
362366 }
363367
364368 return $success;
@@ -370,7 +374,7 @@
371375 *
372376 * @param string $value
373377 *
374 - * @return boolean If there where no fatal errors
 378+ * @return array Containing a boolean indicating if there where no fatal errors and one if there where any errors
375379 */
376380 protected function validateCriteria( $value ) {
377381 $success = true;
@@ -386,12 +390,7 @@
387391 }
388392 }
389393
390 - // TODO: move this to a nicer place
391 - if ( $hasError ) {
392 - $this->value = $this->default;
393 - }
394 -
395 - return $success;
 394+ return array( $success, $hasError );
396395 }
397396
398397 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r72585Follow up to r72507jeroendedauw13:51, 8 September 2010
r72588Follow up to r72507jeroendedauw16:14, 8 September 2010

Comments

#Comment by Raymond (talk | contribs)   12:29, 8 September 2010

Notice: Undefined variable: type in D:\F_Programmierung\xampp\htdocs\wiki2\extensions\Validator\includes\Parameter.php on line 202

Fatal error: Call to undefined method Parameter::construct() in D:\F_Programmierung\xampp\htdocs\wiki2\extensions\Validator\includes\ListParameter.php on line 78

#Comment by Raymond (talk | contribs)   14:11, 8 September 2010

Sorry, but you missed to fix the Notice. Now I get:

Notice: Undefined variable: type in D:\F_Programmierung\xampp\htdocs\wiki2\extensions\Validator\includes\Parameter.php on line 202

Catchable fatal error: Argument 1 passed to ListParameter::validateListCriteria() must be an array, string given, called in D:\F_Programmierung\xampp\htdocs\wiki2\extensions\Validator\includes\ListParameter.php on line 116 and defined in D:\F_Programmierung\xampp\htdocs\wiki2\extensions\Validator\includes\ListParameter.php on line 139

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

When is this occurring? Can you paste the #display_map, #display_point and #geocode calls you are making on that page?

#Comment by Raymond (talk | contribs)   14:27, 8 September 2010

I have one call only on this page: {{#display_point:50.94, 6.95|service=osm|height=300|width=300}}

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

Well, I'll fix this as I work on the extension later today, but advise you not to use the trunk stuff for now. I'm doing extensive refactoring in the Validator extension, and can't always immediately make Maps work with it. Unless I have to much other work, the trunk stuff should be usable again in a week or so.

#Comment by Raymond (talk | contribs)   19:18, 8 September 2010

Well, wouldn't it be a better idea to commit half done stuff into a branch instead of breaking trunk so often? You can merge with trunk when your next release is ready for testing.

PS: The next notice:

Notice: Undefined variable: success in D:\F_Programmierung\xampp\htdocs\wiki2\extensions\Validator\includes\ListParameter.php on line 140

#Comment by Simetrical (talk | contribs)   19:21, 8 September 2010

Everything in trunk is supposed to work at all times. It's meant to be usable on production machines by people who are adventurous and willing to fix or report regressions. If something breaks trunk and can't be fixed quickly, it should be reverted, and moved to a branch if necessary.

Status & tagging log