Index: branches/preferences-work/phase3/includes/HTMLForm.php |
— | — | @@ -84,6 +84,14 @@ |
85 | 85 | return false; |
86 | 86 | } |
87 | 87 | |
| 88 | + // Check for validation |
| 89 | + foreach( $this->mFlatFields as $fieldname => $field ) { |
| 90 | + if ( !$field->validate( $this->mFieldData[$fieldname] ) ) { |
| 91 | + return isset($this->mValidationErrorMessage) ? |
| 92 | + $this->mValidationErrorMessage : array( 'htmlform-invalid-input' ); |
| 93 | + } |
| 94 | + } |
| 95 | + |
88 | 96 | $callback = $this->mSubmitCallback; |
89 | 97 | |
90 | 98 | $res = call_user_func( $callback, $this->mFieldData ); |
— | — | @@ -95,6 +103,10 @@ |
96 | 104 | $this->mSubmitCallback = $cb; |
97 | 105 | } |
98 | 106 | |
| 107 | + function setValidationErrorMessage( $msg ) { |
| 108 | + $this->mValidationErrorMessage = $msg; |
| 109 | + } |
| 110 | + |
99 | 111 | function displayForm( $submitResult ) { |
100 | 112 | global $wgUser, $wgOut; |
101 | 113 | |
— | — | @@ -133,7 +145,7 @@ |
134 | 146 | $wgOut->addHTML( $errorstr ); |
135 | 147 | } |
136 | 148 | |
137 | | - function formatErrors( $errors ) { |
| 149 | + static function formatErrors( $errors ) { |
138 | 150 | $errorstr = ''; |
139 | 151 | foreach ( $errors as $error ) { |
140 | 152 | if (is_array($error)) { |
— | — | @@ -209,6 +221,14 @@ |
210 | 222 | abstract class HTMLFormField { |
211 | 223 | abstract function getInputHTML( $value ); |
212 | 224 | |
| 225 | + function validate( $value ) { |
| 226 | + if ( isset($this->mValidationCallback) ) { |
| 227 | + return call_user_func( $this->mValidationCallback, $value ); |
| 228 | + } |
| 229 | + |
| 230 | + return true; |
| 231 | + } |
| 232 | + |
213 | 233 | function loadDataFromRequest( $request ) { |
214 | 234 | if ($request->getCheck( $this->mName ) ) { |
215 | 235 | return $request->getText( $this->mName ); |
— | — | @@ -247,16 +267,26 @@ |
248 | 268 | if ( isset( $params['id'] ) ) { |
249 | 269 | $this->mID = $params['id']; |
250 | 270 | } |
| 271 | + |
| 272 | + if ( isset( $params['validation-callback'] ) ) { |
| 273 | + $this->mValidationCallback = $params['validation-callback']; |
| 274 | + } |
251 | 275 | } |
252 | 276 | |
253 | 277 | function getTableRow( $value ) { |
| 278 | + // Check for invalid data. |
| 279 | + $errors = $this->validate( $value ); |
| 280 | + if ( $errors === true ) { |
| 281 | + $errors = ''; |
| 282 | + } |
| 283 | + |
254 | 284 | $html = ''; |
255 | 285 | |
256 | 286 | $html .= Xml::tags( 'td', null, |
257 | 287 | Xml::tags( 'label', array( 'for' => $this->mID ), $this->getLabel() ) |
258 | 288 | ); |
259 | 289 | $html .= Xml::tags( 'td', array( 'class' => 'mw-input' ), |
260 | | - $this->getInputHTML( $value ) ); |
| 290 | + $this->getInputHTML( $value ) ."\n$errors" ); |
261 | 291 | |
262 | 292 | $html = Xml::tags( 'tr', null, $html ) . "\n"; |
263 | 293 | |
Index: branches/preferences-work/phase3/includes/specials/SpecialRecentchangeslinked.php |
— | — | @@ -90,7 +90,7 @@ |
91 | 91 | $conds, |
92 | 92 | $join_conds, |
93 | 93 | $query_options, |
94 | | - $opts['tagfilter'], |
| 94 | + $opts['tagfilter'] |
95 | 95 | ); |
96 | 96 | |
97 | 97 | // XXX: parent class does this, should we too? |