Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 40 |
|
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 | namespace MediaWiki\Actions; |
24 | |
25 | use MediaWiki\HTMLForm\HTMLForm; |
26 | use MediaWiki\Permissions\PermissionStatus; |
27 | use MediaWiki\Status\Status; |
28 | |
29 | /** |
30 | * User-requested page cache purging |
31 | * |
32 | * @ingroup Actions |
33 | */ |
34 | class PurgeAction extends FormAction { |
35 | |
36 | /** @var string */ |
37 | private $redirectParams; |
38 | |
39 | /** @inheritDoc */ |
40 | public function getName() { |
41 | return 'purge'; |
42 | } |
43 | |
44 | /** @inheritDoc */ |
45 | public function getDescription() { |
46 | return ''; |
47 | } |
48 | |
49 | /** @inheritDoc */ |
50 | public function onSubmit( $data ) { |
51 | $authority = $this->getAuthority(); |
52 | $page = $this->getWikiPage(); |
53 | |
54 | $status = PermissionStatus::newEmpty(); |
55 | if ( !$authority->authorizeAction( 'purge', $status ) ) { |
56 | return Status::wrap( $status ); |
57 | } |
58 | |
59 | return $page->doPurge(); |
60 | } |
61 | |
62 | /** @inheritDoc */ |
63 | public function show() { |
64 | $this->setHeaders(); |
65 | |
66 | // This will throw exceptions if there's a problem |
67 | $this->checkCanExecute( $this->getUser() ); |
68 | |
69 | if ( $this->getRequest()->wasPosted() ) { |
70 | $this->redirectParams = wfArrayToCgi( array_diff_key( |
71 | $this->getRequest()->getQueryValues(), |
72 | [ 'title' => null, 'action' => null ] |
73 | ) ); |
74 | |
75 | $result = $this->onSubmit( [] ); |
76 | if ( $result === true ) { |
77 | $this->onSuccess(); |
78 | } elseif ( $result instanceof Status ) { |
79 | if ( $result->isOK() ) { |
80 | $this->onSuccess(); |
81 | } else { |
82 | $this->getOutput()->addHTML( $result->getHTML() ); |
83 | } |
84 | } |
85 | } else { |
86 | $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' ); |
87 | $form = $this->getForm(); |
88 | if ( $form->show() ) { |
89 | $this->onSuccess(); |
90 | } |
91 | } |
92 | } |
93 | |
94 | /** @inheritDoc */ |
95 | protected function usesOOUI() { |
96 | return true; |
97 | } |
98 | |
99 | /** @inheritDoc */ |
100 | protected function getFormFields() { |
101 | return [ |
102 | 'intro' => [ |
103 | 'type' => 'info', |
104 | 'raw' => true, |
105 | 'default' => $this->msg( 'confirm-purge-top' )->parse() |
106 | ] |
107 | ]; |
108 | } |
109 | |
110 | protected function alterForm( HTMLForm $form ) { |
111 | $form->setWrapperLegendMsg( 'confirm-purge-title' ); |
112 | $form->setSubmitTextMsg( 'confirm_purge_button' ); |
113 | } |
114 | |
115 | /** @inheritDoc */ |
116 | protected function postText() { |
117 | return $this->msg( 'confirm-purge-bottom' )->parse(); |
118 | } |
119 | |
120 | public function onSuccess() { |
121 | $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) ); |
122 | } |
123 | |
124 | /** @inheritDoc */ |
125 | public function doesWrites() { |
126 | return true; |
127 | } |
128 | } |
129 | |
130 | /** @deprecated class alias since 1.44 */ |
131 | class_alias( PurgeAction::class, 'PurgeAction' ); |