Merge "Added deprecation comment to constant that when used throws deprecation exception"
[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 requiresUnblock() {
35 return false;
36 }
37
38 public function getDescription() {
39 return '';
40 }
41
42 /**
43 * Just get an empty form with a single submit button
44 * @return array
45 */
46 protected function getFormFields() {
47 return array();
48 }
49
50 public function onSubmit( $data ) {
51 return $this->page->doPurge();
52 }
53
54 /**
55 * purge is slightly weird because it can be either formed or formless depending
56 * on user permissions
57 */
58 public function show() {
59 $this->setHeaders();
60
61 // This will throw exceptions if there's a problem
62 $this->checkCanExecute( $this->getUser() );
63
64 if ( $this->getUser()->isAllowed( 'purge' ) ) {
65 $this->redirectParams = wfArrayToCgi( array_diff_key(
66 $this->getRequest()->getQueryValues(),
67 array( 'title' => null, 'action' => null )
68 ) );
69 if( $this->onSubmit( array() ) ) {
70 $this->onSuccess();
71 }
72 } else {
73 $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' );
74 $form = $this->getForm();
75 if ( $form->show() ) {
76 $this->onSuccess();
77 }
78 }
79 }
80
81 protected function alterForm( HTMLForm $form ) {
82 $form->setSubmitTextMsg( 'confirm_purge_button' );
83 }
84
85 protected function preText() {
86 return $this->msg( 'confirm-purge-top' )->parse();
87 }
88
89 protected function postText() {
90 return $this->msg( 'confirm-purge-bottom' )->parse();
91 }
92
93 public function onSuccess() {
94 $this->getOutput()->redirect( $this->getTitle()->getFullUrl( $this->redirectParams ) );
95 }
96 }