r90662 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90661‎ | r90662 | r90663 >
Date:16:05, 23 June 2011
Author:salvatoreingala
Status:deferred
Tags:
Comment:
Removed some code duplication
Modified paths:
  • /branches/salvatoreingala/Gadgets/backend/Gadget.php (modified) (history)

Diff [purge]

Index: branches/salvatoreingala/Gadgets/backend/Gadget.php
@@ -134,22 +134,6 @@
135135 }
136136 }
137137
138 - //$default must pass validation, too
139 - $required = isset( $option['required'] ) ? $option['required'] : true;
140 - $default = $option['default'];
141 -
142 - if ( $required === false && $default === '' ) {
143 - return true; //empty string is good, skip other checks
144 - }
145 -
146 - $len = strlen( $default );
147 - if ( isset( $option['minlength'] ) && $len < $option['minlength'] ) {
148 - return false;
149 - }
150 - if ( isset( $option['maxlength'] ) && $len > $option['maxlength'] ) {
151 - return false;
152 - }
153 -
154138 return true;
155139 }
156140
@@ -163,17 +147,6 @@
164148
165149 //Further checks for 'number' options
166150 private static function checkNumberOptionDefinition( $option ) {
167 -
168 - if ( $option['default'] === null ) {
169 - if ( isset( $option['required'] ) && $option['required'] === false ) {
170 - //Accept null default if "required" is false
171 - return true;
172 - } else {
173 - //Reject null default if "required" is true
174 - return false;
175 - }
176 - }
177 -
178151 if ( isset( $option['integer'] ) && $option['integer'] === true ) {
179152 //Check if 'min', 'max' and 'default' are integers (if given)
180153 if ( intval( $option['default'] ) != $option['default'] ) {
@@ -186,16 +159,6 @@
187160 return false;
188161 }
189162 }
190 -
191 - //validate $option['default']
192 - $default = $option['default'];
193 -
194 - if ( isset( $option['min'] ) && $default < $option['min'] ) {
195 - return false;
196 - }
197 - if ( isset( $option['max'] ) && $default > $option['max'] ) {
198 - return false;
199 - }
200163
201164 return true;
202165 }
@@ -217,13 +180,6 @@
218181
219182 $values = array_values( $options );
220183
221 - $default = $option['default'];
222 -
223 - //Checks that $default is one of the option values
224 - if ( !in_array( $default, $values, true ) ){
225 - return false;
226 - }
227 -
228184 return true;
229185 }
230186
@@ -664,6 +620,16 @@
665621 return false;
666622 }
667623 }
 624+
 625+ //Finally, check that the 'default' fields exists and is valid
 626+ if ( !array_key_exists( 'default', $optionDefinition ) ) {
 627+ return false;
 628+ }
 629+
 630+ $prefs = array( 'dummy' => $optionDefinition['default'] );
 631+ if ( !self::checkSinglePref( $optionDefinition, $prefs, 'dummy' ) ) {
 632+ return false;
 633+ }
668634 }
669635
670636 return true;
@@ -783,7 +749,7 @@
784750 * Checks if $prefs is an array of preferences that passes validation
785751 *
786752 * @param $prefsDescription Array: the preferences description to use.
787 - * @param &$prefs Array: reference of the array of preferences to check.
 753+ * @param $prefs Array: reference of the array of preferences to check.
788754 *
789755 * @return boolean true if $prefs passes validation against $prefsDescription, false otherwise.
790756 */

Status & tagging log