Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
PurgeAction | |
0.00% |
0 / 39 |
|
0.00% |
0 / 10 |
272 | |
0.00% |
0 / 1 |
getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onSubmit | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
show | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
42 | |||
usesOOUI | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFormFields | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
alterForm | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
postText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
onSuccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
doesWrites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * User-requested page cache purging. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU General Public License as published by |
7 | * the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU General Public License |
16 | * along with this program; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
18 | * |
19 | * @file |
20 | * @ingroup Actions |
21 | */ |
22 | |
23 | use MediaWiki\HTMLForm\HTMLForm; |
24 | use MediaWiki\Permissions\PermissionStatus; |
25 | use MediaWiki\Status\Status; |
26 | |
27 | /** |
28 | * User-requested page cache purging |
29 | * |
30 | * @ingroup Actions |
31 | */ |
32 | class PurgeAction extends FormAction { |
33 | |
34 | /** @var string */ |
35 | private $redirectParams; |
36 | |
37 | public function getName() { |
38 | return 'purge'; |
39 | } |
40 | |
41 | public function getDescription() { |
42 | return ''; |
43 | } |
44 | |
45 | public function onSubmit( $data ) { |
46 | $authority = $this->getAuthority(); |
47 | $page = $this->getWikiPage(); |
48 | |
49 | $status = PermissionStatus::newEmpty(); |
50 | if ( !$authority->authorizeAction( 'purge', $status ) ) { |
51 | return Status::wrap( $status ); |
52 | } |
53 | |
54 | return $page->doPurge(); |
55 | } |
56 | |
57 | public function show() { |
58 | $this->setHeaders(); |
59 | |
60 | // This will throw exceptions if there's a problem |
61 | $this->checkCanExecute( $this->getUser() ); |
62 | |
63 | if ( $this->getRequest()->wasPosted() ) { |
64 | $this->redirectParams = wfArrayToCgi( array_diff_key( |
65 | $this->getRequest()->getQueryValues(), |
66 | [ 'title' => null, 'action' => null ] |
67 | ) ); |
68 | |
69 | $result = $this->onSubmit( [] ); |
70 | if ( $result === true ) { |
71 | $this->onSuccess(); |
72 | } elseif ( $result instanceof Status ) { |
73 | if ( $result->isOK() ) { |
74 | $this->onSuccess(); |
75 | } else { |
76 | $this->getOutput()->addHTML( $result->getHTML() ); |
77 | } |
78 | } |
79 | } else { |
80 | $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' ); |
81 | $form = $this->getForm(); |
82 | if ( $form->show() ) { |
83 | $this->onSuccess(); |
84 | } |
85 | } |
86 | } |
87 | |
88 | protected function usesOOUI() { |
89 | return true; |
90 | } |
91 | |
92 | protected function getFormFields() { |
93 | return [ |
94 | 'intro' => [ |
95 | 'type' => 'info', |
96 | 'raw' => true, |
97 | 'default' => $this->msg( 'confirm-purge-top' )->parse() |
98 | ] |
99 | ]; |
100 | } |
101 | |
102 | protected function alterForm( HTMLForm $form ) { |
103 | $form->setWrapperLegendMsg( 'confirm-purge-title' ); |
104 | $form->setSubmitTextMsg( 'confirm_purge_button' ); |
105 | } |
106 | |
107 | protected function postText() { |
108 | return $this->msg( 'confirm-purge-bottom' )->parse(); |
109 | } |
110 | |
111 | public function onSuccess() { |
112 | $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) ); |
113 | } |
114 | |
115 | public function doesWrites() { |
116 | return true; |
117 | } |
118 | } |