Index: trunk/phase3/includes/specials/SpecialBlock.php |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | * |
29 | 29 | * @ingroup SpecialPage |
30 | 30 | */ |
31 | | -class SpecialBlock extends SpecialPage { |
| 31 | +class SpecialBlock extends FormSpecialPage { |
32 | 32 | /** The maximum number of edits a user can have and still be hidden |
33 | 33 | * TODO: config setting? */ |
34 | 34 | const HIDEUSER_CONTRIBLIMIT = 1000; |
— | — | @@ -55,10 +55,28 @@ |
56 | 56 | parent::__construct( 'Block', 'block' ); |
57 | 57 | } |
58 | 58 | |
59 | | - public function execute( $par ) { |
60 | | - $this->checkPermissions(); |
61 | | - $this->checkReadOnly(); |
| 59 | + /** |
| 60 | + * Checks that the user can unblock themselves if they are trying to do so |
| 61 | + * |
| 62 | + * @param User $user |
| 63 | + * @throws ErrorPageError |
| 64 | + */ |
| 65 | + protected function checkExecutePermissions( User $user ) { |
| 66 | + parent::checkExecutePermissions( $user ); |
62 | 67 | |
| 68 | + # bug 15810: blocked admins should have limited access here |
| 69 | + $status = self::checkUnblockSelf( $this->target, $user ); |
| 70 | + if ( $status !== true ) { |
| 71 | + throw new ErrorPageError( 'badaccess', $status ); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Handle some magic here |
| 77 | + * |
| 78 | + * @param $par String |
| 79 | + */ |
| 80 | + protected function setParameter( $par ) { |
63 | 81 | # Extract variables from the request. Try not to get into a situation where we |
64 | 82 | # need to extract *every* variable from the form just for processing here, but |
65 | 83 | # there are legitimate uses for some variables |
— | — | @@ -72,39 +90,31 @@ |
73 | 91 | |
74 | 92 | list( $this->previousTarget, /*...*/ ) = Block::parseTarget( $request->getVal( 'wpPreviousTarget' ) ); |
75 | 93 | $this->requestedHideUser = $request->getBool( 'wpHideUser' ); |
| 94 | + } |
76 | 95 | |
77 | | - # bug 15810: blocked admins should have limited access here |
78 | | - $status = self::checkUnblockSelf( $this->target, $user ); |
79 | | - if ( $status !== true ) { |
80 | | - throw new ErrorPageError( 'badaccess', $status ); |
81 | | - } |
82 | | - |
83 | | - $this->setHeaders(); |
84 | | - $this->outputHeader(); |
85 | | - |
86 | | - $out = $this->getOutput(); |
87 | | - $out->setPageTitle( $this->msg( 'blockip-title' ) ); |
88 | | - $out->addModules( array( 'mediawiki.special', 'mediawiki.special.block' ) ); |
89 | | - |
90 | | - $fields = $this->getFormFields(); |
91 | | - $this->maybeAlterFormDefaults( $fields ); |
92 | | - |
93 | | - $form = new HTMLForm( $fields, $this->getContext() ); |
94 | | - $form->setWrapperLegend( wfMsg( 'blockip-legend' ) ); |
| 96 | + /** |
| 97 | + * Customizes the HTMLForm a bit |
| 98 | + * |
| 99 | + * @param $form HTMLForm |
| 100 | + */ |
| 101 | + protected function alterForm( HTMLForm $form ) { |
| 102 | + $form->setWrapperLegendMsg( 'blockip-legend' ); |
| 103 | + $form->setHeaderText( '' ); |
95 | 104 | $form->setSubmitCallback( array( __CLASS__, 'processUIForm' ) ); |
96 | 105 | |
97 | | - $t = $this->alreadyBlocked |
98 | | - ? wfMsg( 'ipb-change-block' ) |
99 | | - : wfMsg( 'ipbsubmit' ); |
100 | | - $form->setSubmitText( $t ); |
| 106 | + $msg = $this->alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit'; |
| 107 | + $form->setSubmitTextMsg( $msg ); |
101 | 108 | |
102 | | - $this->doPreText( $form ); |
103 | | - $this->doHeadertext( $form ); |
104 | | - $this->doPostText( $form ); |
105 | | - |
106 | | - if( $form->show() ){ |
107 | | - $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) ); |
108 | | - $out->addWikiMsg( 'blockipsuccesstext', $this->target ); |
| 109 | + # Don't need to do anything if the form has been posted |
| 110 | + if( !$this->getRequest()->wasPosted() && $this->preErrors ){ |
| 111 | + $s = HTMLForm::formatErrors( $this->preErrors ); |
| 112 | + if( $s ){ |
| 113 | + $form->addHeaderText( Html::rawElement( |
| 114 | + 'div', |
| 115 | + array( 'class' => 'error' ), |
| 116 | + $s |
| 117 | + ) ); |
| 118 | + } |
109 | 119 | } |
110 | 120 | } |
111 | 121 | |
— | — | @@ -205,13 +215,15 @@ |
206 | 216 | 'label-message' => 'ipb-confirm', |
207 | 217 | ); |
208 | 218 | |
| 219 | + $this->maybeAlterFormDefaults( $a ); |
| 220 | + |
209 | 221 | return $a; |
210 | 222 | } |
211 | 223 | |
212 | 224 | /** |
213 | 225 | * If the user has already been blocked with similar settings, load that block |
214 | 226 | * and change the defaults for the form fields to match the existing settings. |
215 | | - * @param &$fields Array HTMLForm descriptor array |
| 227 | + * @param $fields Array HTMLForm descriptor array |
216 | 228 | * @return Bool whether fields were altered (that is, whether the target is |
217 | 229 | * already blocked) |
218 | 230 | */ |
— | — | @@ -285,11 +297,10 @@ |
286 | 298 | |
287 | 299 | /** |
288 | 300 | * Add header elements like block log entries, etc. |
289 | | - * @param $form HTMLForm |
290 | 301 | * @return void |
291 | 302 | */ |
292 | | - protected function doPreText( HTMLForm &$form ){ |
293 | | - $form->addPreText( wfMsgExt( 'blockiptext', 'parse' ) ); |
| 303 | + protected function preText(){ |
| 304 | + $text = $this->msg( 'blockiptext' )->parse(); |
294 | 305 | |
295 | 306 | $otherBlockMessages = array(); |
296 | 307 | if( $this->target !== null ) { |
— | — | @@ -315,36 +326,18 @@ |
316 | 327 | $list |
317 | 328 | ) . "\n"; |
318 | 329 | |
319 | | - $form->addPreText( $s ); |
| 330 | + $text .= $s; |
320 | 331 | } |
321 | 332 | } |
322 | | - } |
323 | 333 | |
324 | | - /** |
325 | | - * Add header text inside the form, just underneath where the errors would go |
326 | | - * @param $form HTMLForm |
327 | | - * @return void |
328 | | - */ |
329 | | - protected function doHeaderText( HTMLForm &$form ){ |
330 | | - # Don't need to do anything if the form has been posted |
331 | | - if( !$this->getRequest()->wasPosted() && $this->preErrors ){ |
332 | | - $s = HTMLForm::formatErrors( $this->preErrors ); |
333 | | - if( $s ){ |
334 | | - $form->addHeaderText( Html::rawElement( |
335 | | - 'div', |
336 | | - array( 'class' => 'error' ), |
337 | | - $s |
338 | | - ) ); |
339 | | - } |
340 | | - } |
| 334 | + return $text; |
341 | 335 | } |
342 | 336 | |
343 | 337 | /** |
344 | 338 | * Add footer elements to the form |
345 | | - * @param $form HTMLForm |
346 | 339 | * @return void |
347 | 340 | */ |
348 | | - protected function doPostText( HTMLForm &$form ){ |
| 341 | + protected function postText(){ |
349 | 342 | # Link to the user's contributions, if applicable |
350 | 343 | if( $this->target instanceof User ){ |
351 | 344 | $contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() ); |
— | — | @@ -382,11 +375,11 @@ |
383 | 376 | ); |
384 | 377 | } |
385 | 378 | |
386 | | - $form->addPostText( Html::rawElement( |
| 379 | + $text = Html::rawElement( |
387 | 380 | 'p', |
388 | 381 | array( 'class' => 'mw-ipb-conveniencelinks' ), |
389 | 382 | $this->getLang()->pipeList( $links ) |
390 | | - ) ); |
| 383 | + ); |
391 | 384 | |
392 | 385 | if( $this->target instanceof User ){ |
393 | 386 | # Get relevant extracts from the block and suppression logs, if possible |
— | — | @@ -404,7 +397,7 @@ |
405 | 398 | 'showIfEmpty' => false |
406 | 399 | ) |
407 | 400 | ); |
408 | | - $form->addPostText( $out ); |
| 401 | + $text .= $out; |
409 | 402 | |
410 | 403 | # Add suppression block entries if allowed |
411 | 404 | if( $user->isAllowed( 'suppressionlog' ) ) { |
— | — | @@ -421,9 +414,11 @@ |
422 | 415 | ) |
423 | 416 | ); |
424 | 417 | |
425 | | - $form->addPostText( $out ); |
| 418 | + $text .= $out; |
426 | 419 | } |
427 | 420 | } |
| 421 | + |
| 422 | + return $text; |
428 | 423 | } |
429 | 424 | |
430 | 425 | /** |
— | — | @@ -482,6 +477,7 @@ |
483 | 478 | * @since 1.18 |
484 | 479 | * @param $value String |
485 | 480 | * @param $alldata Array |
| 481 | + * @param $form HTMLForm |
486 | 482 | * @return Message |
487 | 483 | */ |
488 | 484 | public static function validateTargetField( $value, $alldata, $form ) { |
— | — | @@ -536,6 +532,9 @@ |
537 | 533 | |
538 | 534 | /** |
539 | 535 | * Submit callback for an HTMLForm object, will simply pass |
| 536 | + * @param $data array |
| 537 | + * @param $form HTMLForm |
| 538 | + * @return Bool|String |
540 | 539 | */ |
541 | 540 | public static function processUIForm( array $data, HTMLForm $form ) { |
542 | 541 | return self::processForm( $data, $form->getContext() ); |
— | — | @@ -544,6 +543,7 @@ |
545 | 544 | /** |
546 | 545 | * Given the form data, actually implement a block |
547 | 546 | * @param $data Array |
| 547 | + * @param $context IContextSource |
548 | 548 | * @return Bool|String |
549 | 549 | */ |
550 | 550 | public static function processForm( array $data, IContextSource $context ){ |
— | — | @@ -867,6 +867,26 @@ |
868 | 868 | |
869 | 869 | return implode( ',', $flags ); |
870 | 870 | } |
| 871 | + |
| 872 | + /** |
| 873 | + * Process the form on POST submission. |
| 874 | + * @param $data Array |
| 875 | + * @return Bool|Array true for success, false for didn't-try, array of errors on failure |
| 876 | + */ |
| 877 | + public function onSubmit( array $data ) { |
| 878 | + // This isn't used since we need that HTMLForm that's passed in the |
| 879 | + // second parameter. See alterForm for the real function |
| 880 | + } |
| 881 | + |
| 882 | + /** |
| 883 | + * Do something exciting on successful processing of the form, most likely to show a |
| 884 | + * confirmation message |
| 885 | + */ |
| 886 | + public function onSuccess() { |
| 887 | + $out = $this->getOutput(); |
| 888 | + $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) ); |
| 889 | + $out->addWikiMsg( 'blockipsuccesstext', $this->target ); |
| 890 | + } |
871 | 891 | } |
872 | 892 | |
873 | 893 | # BC @since 1.18 |