Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
SpecialRemoveGlobalBlock | |
0.00% |
0 / 47 |
|
0.00% |
0 / 9 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
onSubmit | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
onSuccess | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
alterForm | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getFormFields | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |||
doesWrites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getGroupName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDisplayFormat | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\GlobalBlocking\Special; |
4 | |
5 | use HTMLForm; |
6 | use MediaWiki\Block\BlockUtils; |
7 | use MediaWiki\Extension\GlobalBlocking\GlobalBlocking; |
8 | use MediaWiki\SpecialPage\FormSpecialPage; |
9 | use MediaWiki\SpecialPage\SpecialPage; |
10 | use MediaWiki\Status\Status; |
11 | use MediaWiki\User\UserIdentity; |
12 | use Wikimedia\IPUtils; |
13 | |
14 | class SpecialRemoveGlobalBlock extends FormSpecialPage { |
15 | /** @var string|null */ |
16 | private $ip; |
17 | |
18 | /** @var BlockUtils */ |
19 | private $blockUtils; |
20 | |
21 | /** |
22 | * @param BlockUtils $blockUtils |
23 | */ |
24 | public function __construct( |
25 | BlockUtils $blockUtils |
26 | ) { |
27 | parent::__construct( 'RemoveGlobalBlock', 'globalblock' ); |
28 | $this->blockUtils = $blockUtils; |
29 | } |
30 | |
31 | public function execute( $par ) { |
32 | parent::execute( $par ); |
33 | $this->addHelpLink( 'Extension:GlobalBlocking' ); |
34 | |
35 | $out = $this->getOutput(); |
36 | $out->setPageTitleMsg( $this->msg( 'globalblocking-unblock' ) ); |
37 | $out->setSubtitle( GlobalBlocking::buildSubtitleLinks( $this ) ); |
38 | $out->disableClientCache(); |
39 | |
40 | [ $target ] = $this->blockUtils->parseBlockTarget( $par ); |
41 | |
42 | if ( $target instanceof UserIdentity ) { |
43 | $this->getSkin()->setRelevantUser( $target ); |
44 | } |
45 | } |
46 | |
47 | /** @inheritDoc */ |
48 | public function onSubmit( array $data ) { |
49 | $status = GlobalBlocking::unblock( $data['ipaddress'], $data['reason'], $this->getUser() ); |
50 | |
51 | if ( !$status->isOK() ) { |
52 | return Status::wrap( $status ); |
53 | } |
54 | |
55 | $this->ip = IPUtils::sanitizeIP( $data[ 'ipaddress' ] ); |
56 | |
57 | [ $rangeStart, $rangeEnd ] = IPUtils::parseRange( $this->ip ); |
58 | |
59 | if ( $rangeStart !== $rangeEnd ) { |
60 | $this->ip = IPUtils::sanitizeRange( $this->ip ); |
61 | } |
62 | |
63 | return Status::newGood(); |
64 | } |
65 | |
66 | public function onSuccess() { |
67 | $msg = $this->msg( 'globalblocking-unblock-unblocked', $this->ip )->parseAsBlock(); |
68 | $link = $this->getLinkRenderer()->makeKnownLink( |
69 | SpecialPage::getTitleFor( 'GlobalBlockList' ), |
70 | $this->msg( 'globalblocking-return' )->text() |
71 | ); |
72 | |
73 | $this->getOutput()->addHTML( $msg . $link ); |
74 | } |
75 | |
76 | protected function alterForm( HTMLForm $form ) { |
77 | $form->setWrapperLegendMsg( 'globalblocking-unblock-legend' ); |
78 | $form->setSubmitTextMsg( 'globalblocking-unblock-submit' ); |
79 | $form->setPreHtml( $this->msg( 'globalblocking-unblock-intro' )->parse() ); |
80 | } |
81 | |
82 | protected function getFormFields() { |
83 | return [ |
84 | 'ipaddress' => [ |
85 | 'name' => 'address', |
86 | 'type' => 'text', |
87 | 'id' => 'mw-globalblocking-ipaddress', |
88 | 'label-message' => 'globalblocking-ipaddress', |
89 | 'required' => true, |
90 | 'default' => $this->par, |
91 | ], |
92 | 'reason' => [ |
93 | 'name' => 'wpReason', |
94 | 'type' => 'text', |
95 | 'id' => 'mw-globalblocking-unblock-reason', |
96 | 'label-message' => 'globalblocking-unblock-reason', |
97 | ], |
98 | ]; |
99 | } |
100 | |
101 | public function doesWrites() { |
102 | return true; |
103 | } |
104 | |
105 | protected function getGroupName() { |
106 | return 'users'; |
107 | } |
108 | |
109 | protected function getDisplayFormat() { |
110 | return 'ooui'; |
111 | } |
112 | } |