MediaWiki master
PurgeAction.php
Go to the documentation of this file.
1<?php
10namespace MediaWiki\Actions;
11
15
21class PurgeAction extends FormAction {
22
24 private $redirectParams;
25
27 public function getName() {
28 return 'purge';
29 }
30
32 public function getDescription() {
33 return '';
34 }
35
37 public function onSubmit( $data ) {
38 $authority = $this->getAuthority();
39 $page = $this->getWikiPage();
40
41 $status = PermissionStatus::newEmpty();
42 if ( !$authority->authorizeAction( 'purge', $status ) ) {
43 return Status::wrap( $status );
44 }
45
46 return $page->doPurge();
47 }
48
50 public function show() {
51 $this->setHeaders();
52
53 // This will throw exceptions if there's a problem
54 $this->checkCanExecute( $this->getUser() );
55
56 if ( $this->getRequest()->wasPosted() ) {
57 $this->redirectParams = wfArrayToCgi( array_diff_key(
58 $this->getRequest()->getQueryValues(),
59 [ 'title' => null, 'action' => null ]
60 ) );
61
62 $result = $this->onSubmit( [] );
63 if ( $result === true ) {
64 $this->onSuccess();
65 } elseif ( $result instanceof Status ) {
66 if ( $result->isOK() ) {
67 $this->onSuccess();
68 } else {
69 $this->getOutput()->addHTML( $result->getHTML() );
70 }
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
82 protected function usesOOUI() {
83 return true;
84 }
85
87 protected function getFormFields() {
88 return [
89 'intro' => [
90 'type' => 'info',
91 'raw' => true,
92 'default' => $this->msg( 'confirm-purge-top' )->parse()
93 ]
94 ];
95 }
96
97 protected function alterForm( HTMLForm $form ) {
98 $form->setWrapperLegendMsg( 'confirm-purge-title' );
99 $form->setSubmitTextMsg( 'confirm_purge_button' );
100 }
101
103 protected function postText() {
104 return $this->msg( 'confirm-purge-bottom' )->parse();
105 }
106
107 public function onSuccess() {
108 $this->getOutput()->redirect( $this->getTitle()->getFullURL( $this->redirectParams ) );
109 }
110
112 public function doesWrites() {
113 return true;
114 }
115}
116
118class_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:192
setHeaders()
Set output headers for noindexing etc.
Definition Action.php:407
getUser()
Shortcut to get the User being used for this instance.
Definition Action.php:153
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
Definition Action.php:227
checkCanExecute(User $user)
Checks if the given user (identified by an object) can perform this action.
Definition Action.php:327
getTitle()
Shortcut to get the Title object from the page.
Definition Action.php:213
getRequest()
Get the WebRequest being used for this instance.
Definition Action.php:133
getOutput()
Get the OutputPage being used for this instance.
Definition Action.php:143
getAuthority()
Shortcut to get the Authority executing this instance.
Definition Action.php:163
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.1.17 to override string HTML
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.to override bool
onSuccess()
Do something exciting on successful processing of the form.
getName()
Return the name of the action this object responds to.1.17string Lowercase name
onSubmit( $data)
Process the form on POST submission.If you don't want to do anything with the form,...
getFormFields()
Get an HTMLForm descriptor array.to override array
postText()
to override string
Object handling generic submission, CSRF protection, layout and other logic for UI forms in a reusabl...
Definition HTMLForm.php:195
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:44