MediaWiki master
PurgeAction.php
Go to the documentation of this file.
1<?php
26
32class PurgeAction extends FormAction {
33
34 private $redirectParams;
35
36 public function getName() {
37 return 'purge';
38 }
39
40 public function getDescription() {
41 return '';
42 }
43
44 public function onSubmit( $data ) {
45 $authority = $this->getAuthority();
46 $page = $this->getWikiPage();
47
48 $status = PermissionStatus::newEmpty();
49 if ( !$authority->authorizeAction( 'purge', $status ) ) {
50 return Status::wrap( $status );
51 }
52
53 return $page->doPurge();
54 }
55
56 public function show() {
57 $this->setHeaders();
58
59 // This will throw exceptions if there's a problem
60 $this->checkCanExecute( $this->getUser() );
61
62 if ( $this->getRequest()->wasPosted() ) {
63 $this->redirectParams = wfArrayToCgi( array_diff_key(
64 $this->getRequest()->getQueryValues(),
65 [ 'title' => null, 'action' => null ]
66 ) );
67
68 $result = $this->onSubmit( [] );
69 if ( $result === true ) {
70 $this->onSuccess();
71 } elseif ( $result instanceof Status ) {
72 if ( $result->isOK() ) {
73 $this->onSuccess();
74 } else {
75 $this->getOutput()->addHTML( $result->getHTML() );
76 }
77 }
78 } else {
79 $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' );
80 $form = $this->getForm();
81 if ( $form->show() ) {
82 $this->onSuccess();
83 }
84 }
85 }
86
87 protected function usesOOUI() {
88 return true;
89 }
90
91 protected function getFormFields() {
92 return [
93 'intro' => [
94 'type' => 'info',
95 'raw' => true,
96 'default' => $this->msg( 'confirm-purge-top' )->parse()
97 ]
98 ];
99 }
100
101 protected function alterForm( HTMLForm $form ) {
102 $form->setWrapperLegendMsg( 'confirm-purge-title' );
103 $form->setSubmitTextMsg( 'confirm_purge_button' );
104 }
105
106 protected function postText() {
107 return $this->msg( 'confirm-purge-bottom' )->parse();
108 }
109
110 public function onSuccess() {
111 $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) );
112 }
113
114 public function doesWrites() {
115 return true;
116 }
117}
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:394
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.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:208
setWrapperLegendMsg( $msg)
Prompt the whole form to be wrapped in a "<fieldset>", with this message as its "<legend>" element.
setSubmitTextMsg( $msg)
Set the text for the submit button to a message.
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.