Index: trunk/phase3/includes/HTMLForm.php |
— | — | @@ -184,23 +184,26 @@ |
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
188 | | - * The here's-one-I-made-earlier option: do the submission if |
189 | | - * posted, or display the form with or without funky valiation |
190 | | - * errors |
191 | | - * @return Bool or Status whether submission was successful. |
| 188 | + * Prepare form for submission |
192 | 189 | */ |
193 | | - function show() { |
| 190 | + function prepareForm() { |
194 | 191 | # Check if we have the info we need |
195 | 192 | if ( ! $this->mTitle ) { |
196 | 193 | throw new MWException( "You must call setTitle() on an HTMLForm" ); |
197 | 194 | } |
198 | 195 | |
| 196 | + // FIXME shouldn't this be closer to displayForm() ? |
199 | 197 | self::addJS(); |
200 | 198 | |
201 | 199 | # Load data from the request. |
202 | 200 | $this->loadData(); |
| 201 | + } |
203 | 202 | |
204 | | - # Try a submission |
| 203 | + /** |
| 204 | + * Try submitting, with edit token check first |
| 205 | + * @return Status|boolean |
| 206 | + */ |
| 207 | + function tryAuthorizedSubmit() { |
205 | 208 | global $wgUser, $wgRequest; |
206 | 209 | $editToken = $wgRequest->getVal( 'wpEditToken' ); |
207 | 210 | |
— | — | @@ -208,12 +211,23 @@ |
209 | 212 | if ( $wgUser->matchEditToken( $editToken ) ) { |
210 | 213 | $result = $this->trySubmit(); |
211 | 214 | } |
| 215 | + return $result; |
| 216 | + } |
212 | 217 | |
| 218 | + /** |
| 219 | + * The here's-one-I-made-earlier option: do the submission if |
| 220 | + * posted, or display the form with or without funky valiation |
| 221 | + * errors |
| 222 | + * @return Bool or Status whether submission was successful. |
| 223 | + */ |
| 224 | + function show() { |
| 225 | + $this->prepareForm(); |
| 226 | + |
| 227 | + $result = $this->tryAuthorizedSubmit(); |
213 | 228 | if ( $result === true || ( $result instanceof Status && $result->isGood() ) ){ |
214 | 229 | return $result; |
215 | 230 | } |
216 | 231 | |
217 | | - # Display form. |
218 | 232 | $this->displayForm( $result ); |
219 | 233 | return false; |
220 | 234 | } |
— | — | @@ -528,7 +542,6 @@ |
529 | 543 | $this->mSubmitTooltip = $name; |
530 | 544 | } |
531 | 545 | |
532 | | - |
533 | 546 | /** |
534 | 547 | * Set the id for the submit button. |
535 | 548 | * @param $t String. FIXME: Integrity is *not* validated |