MediaWiki master
PurgeAction.php
Go to the documentation of this file.
1<?php
25
31class PurgeAction extends FormAction {
32
33 private $redirectParams;
34
35 public function getName() {
36 return 'purge';
37 }
38
39 public function getDescription() {
40 return '';
41 }
42
43 public function onSubmit( $data ) {
44 $authority = $this->getAuthority();
45 $page = $this->getWikiPage();
46
47 $status = PermissionStatus::newEmpty();
48 if ( !$authority->authorizeAction( 'purge', $status ) ) {
49 return Status::wrap( $status );
50 }
51
52 return $page->doPurge();
53 }
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 if ( $this->getRequest()->wasPosted() ) {
62 $this->redirectParams = wfArrayToCgi( array_diff_key(
63 $this->getRequest()->getQueryValues(),
64 [ 'title' => null, 'action' => null ]
65 ) );
66
67 $result = $this->onSubmit( [] );
68 if ( $result === true ) {
69 $this->onSuccess();
70 } elseif ( $result instanceof Status ) {
71 if ( $result->isOK() ) {
72 $this->onSuccess();
73 } else {
74 $this->getOutput()->addHTML( $result->getHTML() );
75 }
76 }
77 } else {
78 $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' );
79 $form = $this->getForm();
80 if ( $form->show() ) {
81 $this->onSuccess();
82 }
83 }
84 }
85
86 protected function usesOOUI() {
87 return true;
88 }
89
90 protected function getFormFields() {
91 return [
92 'intro' => [
93 'type' => 'info',
94 'raw' => true,
95 'default' => $this->msg( 'confirm-purge-top' )->parse()
96 ]
97 ];
98 }
99
100 protected function alterForm( HTMLForm $form ) {
101 $form->setWrapperLegendMsg( 'confirm-purge-title' );
102 $form->setSubmitTextMsg( 'confirm_purge_button' );
103 }
104
105 protected function postText() {
106 return $this->msg( 'confirm-purge-bottom' )->parse();
107 }
108
109 public function onSuccess() {
110 $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) );
111 }
112
113 public function doesWrites() {
114 return true;
115 }
116}
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
getWikiPage()
Get a WikiPage object.
Definition Action.php:190
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
Definition Action.php:323
getTitle()
Shortcut to get the Title object from the page.
Definition Action.php:211
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:141
getUser()
Shortcut to get the User being used for this instance.
Definition Action.php:151
setHeaders()
Set output headers for noindexing etc.
Definition Action.php:397
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:223
getAuthority()
Shortcut to get the Authority executing this instance.
Definition Action.php:161
getRequest()
Get the WebRequest being used for this instance.
Definition Action.php:131
An action which shows a form and does something based on the input from the form.
getForm()
Get the HTMLForm to control behavior.
A StatusValue for permission errors.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
User-requested page cache purging.
usesOOUI()
Whether the form should use OOUI.
show()
The basic pattern for actions is to display some sort of HTMLForm UI, maybe with some stuff underneat...
getDescription()
Returns the description that goes below the <h1> element.
onSubmit( $data)
Process the form on POST submission.
getFormFields()
Get an HTMLForm descriptor array.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
onSuccess()
Do something exciting on successful processing of the form.
getName()
Return the name of the action this object responds to.