Merge "Http::getProxy() method to get proxy configuration"
[lhc/web/wiklou.git] / includes / actions / PurgeAction.php
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 /**
24 * User-requested page cache purging.
25 *
26 * For users with 'purge', this will directly trigger the cache purging and
27 * for users without that right, it will show a confirmation form.
28 *
29 * @ingroup Actions
30 */
31 class PurgeAction extends FormAction {
32
33 private $redirectParams;
34
35 public function getName() {
36 return 'purge';
37 }
38
39 public function requiresUnblock() {
40 return false;
41 }
42
43 public function getDescription() {
44 return '';
45 }
46
47 public function onSubmit( $data ) {
48 return $this->page->doPurge();
49 }
50
51 /**
52 * purge is slightly weird because it can be either formed or formless depending
53 * on user permissions
54 */
55 public function show() {
56 $this->setHeaders();
57
58 // This will throw exceptions if there's a problem
59 $this->checkCanExecute( $this->getUser() );
60
61 $user = $this->getUser();
62
63 if ( $user->pingLimiter( 'purge' ) ) {
64 // TODO: Display actionthrottledtext
65 return;
66 }
67
68 if ( $user->isAllowed( 'purge' ) ) {
69 $this->redirectParams = wfArrayToCgi( array_diff_key(
70 $this->getRequest()->getQueryValues(),
71 [ 'title' => null, 'action' => null ]
72 ) );
73 if ( $this->onSubmit( [] ) ) {
74 $this->onSuccess();
75 }
76 } else {
77 $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' );
78 $form = $this->getForm();
79 if ( $form->show() ) {
80 $this->onSuccess();
81 }
82 }
83 }
84
85 protected function alterForm( HTMLForm $form ) {
86 $form->setSubmitTextMsg( 'confirm_purge_button' );
87 }
88
89 protected function preText() {
90 return $this->msg( 'confirm-purge-top' )->parse();
91 }
92
93 protected function postText() {
94 return $this->msg( 'confirm-purge-bottom' )->parse();
95 }
96
97 public function onSuccess() {
98 $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) );
99 }
100
101 public function doesWrites() {
102 return true;
103 }
104 }