MediaWiki master
PurgeAction.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Actions;
24
28
34class PurgeAction extends FormAction {
35
37 private $redirectParams;
38
39 public function getName() {
40 return 'purge';
41 }
42
43 public function getDescription() {
44 return '';
45 }
46
47 public function onSubmit( $data ) {
48 $authority = $this->getAuthority();
49 $page = $this->getWikiPage();
50
51 $status = PermissionStatus::newEmpty();
52 if ( !$authority->authorizeAction( 'purge', $status ) ) {
53 return Status::wrap( $status );
54 }
55
56 return $page->doPurge();
57 }
58
59 public function show() {
60 $this->setHeaders();
61
62 // This will throw exceptions if there's a problem
63 $this->checkCanExecute( $this->getUser() );
64
65 if ( $this->getRequest()->wasPosted() ) {
66 $this->redirectParams = wfArrayToCgi( array_diff_key(
67 $this->getRequest()->getQueryValues(),
68 [ 'title' => null, 'action' => null ]
69 ) );
70
71 $result = $this->onSubmit( [] );
72 if ( $result === true ) {
73 $this->onSuccess();
74 } elseif ( $result instanceof Status ) {
75 if ( $result->isOK() ) {
76 $this->onSuccess();
77 } else {
78 $this->getOutput()->addHTML( $result->getHTML() );
79 }
80 }
81 } else {
82 $this->redirectParams = $this->getRequest()->getVal( 'redirectparams', '' );
83 $form = $this->getForm();
84 if ( $form->show() ) {
85 $this->onSuccess();
86 }
87 }
88 }
89
90 protected function usesOOUI() {
91 return true;
92 }
93
94 protected function getFormFields() {
95 return [
96 'intro' => [
97 'type' => 'info',
98 'raw' => true,
99 'default' => $this->msg( 'confirm-purge-top' )->parse()
100 ]
101 ];
102 }
103
104 protected function alterForm( HTMLForm $form ) {
105 $form->setWrapperLegendMsg( 'confirm-purge-title' );
106 $form->setSubmitTextMsg( 'confirm_purge_button' );
107 }
108
109 protected function postText() {
110 return $this->msg( 'confirm-purge-bottom' )->parse();
111 }
112
113 public function onSuccess() {
114 $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) );
115 }
116
117 public function doesWrites() {
118 return true;
119 }
120}
121
123class_alias( PurgeAction::class, 'PurgeAction' );
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:205
setHeaders()
Set output headers for noindexing etc.
Definition Action.php:420
getUser()
Shortcut to get the User being used for this instance.
Definition Action.php:166
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:240
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
Definition Action.php:340
getTitle()
Shortcut to get the Title object from the page.
Definition Action.php:226
getRequest()
Get the WebRequest being used for this instance.
Definition Action.php:146
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:156
getAuthority()
Shortcut to get the Authority executing this instance.
Definition Action.php:176
An action which shows a form and does something based on the input from the form.
getForm()
Get the HTMLForm to control behavior.
User-requested page cache purging.
alterForm(HTMLForm $form)
Play with the HTMLForm if you need to more substantially.
getDescription()
Returns the description that goes below the <h1> element.
show()
The basic pattern for actions is to display some sort of HTMLForm UI, maybe with some stuff underneat...
usesOOUI()
Whether the form should use OOUI.
onSuccess()
Do something exciting on successful processing of the form.
getName()
Return the name of the action this object responds to.
onSubmit( $data)
Process the form on POST submission.
getFormFields()
Get an HTMLForm descriptor array.
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:210
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