e288785f3d081323fd8a63f44caa6735dd8878f8
[lhc/web/wiklou.git] / includes / actions / PurgeAction.php
1 <?php
2 /**
3 * Formats credits for articles
4 *
5 * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 * @file
22 * @ingroup Actions
23 * @author <evan@wikitravel.org>
24 */
25
26 class PurgeAction extends FormAction {
27
28 private $redirectParams;
29
30 public function getName() {
31 return 'purge';
32 }
33
34 public function getRestriction() {
35 return null;
36 }
37
38 public function requiresUnblock() {
39 return false;
40 }
41
42 public function getDescription() {
43 return '';
44 }
45
46 /**
47 * Just get an empty form with a single submit button
48 * @return array
49 */
50 protected function getFormFields() {
51 return array();
52 }
53
54 public function onSubmit( $data ) {
55 return $this->page->doPurge();
56 }
57
58 /**
59 * purge is slightly weird because it can be either formed or formless depending
60 * on user permissions
61 */
62 public function show() {
63 $this->setHeaders();
64
65 // This will throw exceptions if there's a problem
66 $this->checkCanExecute( $this->getUser() );
67
68 if ( $this->getUser()->isAllowed( 'purge' ) ) {
69 $this->redirectParams = wfArrayToCGI( array_diff_key(
70 $this->getRequest()->getQueryValues(),
71 array( 'title' => null, 'action' => null )
72 ) );
73 if( $this->onSubmit( array() ) ) {
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->setSubmitText( wfMsg( 'confirm_purge_button' ) );
87 }
88
89 protected function preText() {
90 return wfMessage( 'confirm-purge-top' )->parse();
91 }
92
93 protected function postText() {
94 return wfMessage( 'confirm-purge-bottom' )->parse();
95 }
96
97 public function onSuccess() {
98 $this->getOutput()->redirect( $this->getTitle()->getFullUrl( $this->redirectParams ) );
99 }
100 }