Follow-up r 86041 per CR and IRC:
[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 public function getName() {
29 return 'purge';
30 }
31
32 public function getRestriction() {
33 return null;
34 }
35
36 public function requiresUnblock() {
37 return false;
38 }
39
40 public function getDescription() {
41 return '';
42 }
43
44 /**
45 * Just get an empty form with a single submit button
46 * @return array
47 */
48 protected function getFormFields() {
49 return array();
50 }
51
52 public function onSubmit( $data ) {
53 $this->page->doPurge();
54 return true;
55 }
56
57 /**
58 * purge is slightly wierd because it can be either formed or formless depending
59 * on user permissions
60 */
61 public function show() {
62 $this->setHeaders();
63
64 // This will throw exceptions if there's a problem
65 $this->checkCanExecute( $this->getUser() );
66
67 if ( $this->getUser()->isAllowed( 'purge' ) ) {
68 $this->onSubmit( array() );
69 $this->onSuccess();
70 } else {
71 $form = $this->getForm();
72 if ( $form->show() ) {
73 $this->onSuccess();
74 }
75 }
76 }
77
78 protected function alterForm( HTMLForm $form ) {
79 $form->setSubmitText( wfMsg( 'confirm_purge_button' ) );
80 }
81
82 protected function preText() {
83 return wfMessage( 'confirm-purge-top' )->parse();
84 }
85
86 protected function postText() {
87 return wfMessage( 'confirm-purge-bottom' )->parse();
88 }
89
90 public function onSuccess() {
91 $this->getOutput()->redirect( $this->getTitle() );
92 }
93 }