Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 10 |
CRAP | |
0.00% |
0 / 1 |
| PurgeAction | |
0.00% |
0 / 39 |
|
0.00% |
0 / 10 |
272 | |
0.00% |
0 / 1 |
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDescription | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onSubmit | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| show | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
42 | |||
| usesOOUI | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFormFields | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| alterForm | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| postText | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| onSuccess | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| doesWrites | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * User-requested page cache purging. |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup Actions |
| 8 | */ |
| 9 | |
| 10 | namespace MediaWiki\Actions; |
| 11 | |
| 12 | use MediaWiki\HTMLForm\HTMLForm; |
| 13 | use MediaWiki\Permissions\PermissionStatus; |
| 14 | use MediaWiki\Status\Status; |
| 15 | |
| 16 | /** |
| 17 | * User-requested page cache purging |
| 18 | * |
| 19 | * @ingroup Actions |
| 20 | */ |
| 21 | class PurgeAction extends FormAction { |
| 22 | |
| 23 | /** @var string */ |
| 24 | private $redirectParams; |
| 25 | |
| 26 | /** @inheritDoc */ |
| 27 | public function getName() { |
| 28 | return 'purge'; |
| 29 | } |
| 30 | |
| 31 | /** @inheritDoc */ |
| 32 | public function getDescription() { |
| 33 | return ''; |
| 34 | } |
| 35 | |
| 36 | /** @inheritDoc */ |
| 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 | |
| 49 | /** @inheritDoc */ |
| 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 | |
| 81 | /** @inheritDoc */ |
| 82 | protected function usesOOUI() { |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | /** @inheritDoc */ |
| 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 | |
| 102 | /** @inheritDoc */ |
| 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 | |
| 111 | /** @inheritDoc */ |
| 112 | public function doesWrites() { |
| 113 | return true; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /** @deprecated class alias since 1.44 */ |
| 118 | class_alias( PurgeAction::class, 'PurgeAction' ); |