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 | private $redirectParams; |
35 | |
36 | public function getName() { |
37 | return 'purge'; |
38 | } |
39 | |
40 | public function getDescription() { |
41 | return ''; |
42 | } |
43 | |
44 | public function onSubmit( $data ) { |
45 | $authority = $this->getAuthority(); |
46 | $page = $this->getWikiPage(); |
47 | |
48 | $status = PermissionStatus::newEmpty(); |
49 | if ( !$authority->authorizeAction( 'purge', $status ) ) { |
50 | return Status::wrap( $status ); |
51 | } |
52 | |
53 | return $page->doPurge(); |
54 | } |
55 | |
56 | public function show() { |
57 | $this->setHeaders(); |
58 | |
59 | // This will throw exceptions if there's a problem |
60 | $this->checkCanExecute( $this->getUser() ); |
61 | |
62 | if ( $this->getRequest()->wasPosted() ) { |
63 | $this->redirectParams = wfArrayToCgi( array_diff_key( |
64 | $this->getRequest()->getQueryValues(), |
65 | [ 'title' => null, 'action' => null ] |
66 | ) ); |
67 | |
68 | $result = $this->onSubmit( [] ); |
69 | if ( $result === true ) { |
70 | $this->onSuccess(); |
71 | } elseif ( $result instanceof Status ) { |
72 | if ( $result->isOK() ) { |
73 | $this->onSuccess(); |
74 | } else { |
75 | $this->getOutput()->addHTML( $result->getHTML() ); |
76 | } |
77 | } |
78 | } else { |
79 | $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' ); |
80 | $form = $this->getForm(); |
81 | if ( $form->show() ) { |
82 | $this->onSuccess(); |
83 | } |
84 | } |
85 | } |
86 | |
87 | protected function usesOOUI() { |
88 | return true; |
89 | } |
90 | |
91 | protected function getFormFields() { |
92 | return [ |
93 | 'intro' => [ |
94 | 'type' => 'info', |
95 | 'raw' => true, |
96 | 'default' => $this->msg( 'confirm-purge-top' )->parse() |
97 | ] |
98 | ]; |
99 | } |
100 | |
101 | protected function alterForm( HTMLForm $form ) { |
102 | $form->setWrapperLegendMsg( 'confirm-purge-title' ); |
103 | $form->setSubmitTextMsg( 'confirm_purge_button' ); |
104 | } |
105 | |
106 | protected function postText() { |
107 | return $this->msg( 'confirm-purge-bottom' )->parse(); |
108 | } |
109 | |
110 | public function onSuccess() { |
111 | $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) ); |
112 | } |
113 | |
114 | public function doesWrites() { |
115 | return true; |
116 | } |
117 | } |