Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 22 |
EntitySchema\MediaWiki\Actions\AbstractRestoreAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 22 |
getRestriction | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
getRevisionFromRequest | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 8 |
|||
checkPermissions | |
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 7 |
|||
showRestoreErrorPage | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 6 |
<?php | |
namespace EntitySchema\MediaWiki\Actions; | |
use EditAction; | |
use Html; | |
use MediaWiki\MediaWikiServices; | |
use MediaWiki\Revision\RevisionRecord; | |
use PermissionsError; | |
use ReadOnlyError; | |
use Status; | |
use UserBlockedError; | |
use WebRequest; | |
/** | |
* @license GPL-2.0-or-later | |
*/ | |
abstract class AbstractRestoreAction extends EditAction { | |
public function getRestriction() { | |
return 'edit'; | |
} | |
protected function getRevisionFromRequest( WebRequest $req ): Status { | |
$restoreID = $req->getText( 'restore' ); | |
$revStore = MediaWikiServices::getInstance()->getRevisionStore(); | |
$revToRestore = $revStore->getRevisionById( $restoreID ); | |
if ( $revToRestore === null || $revToRestore->isDeleted( RevisionRecord::DELETED_TEXT ) ) { | |
return Status::newFatal( $this->msg( 'entityschema-restore-bad-revisions' ) ); | |
} | |
if ( $revToRestore->getPageId() !== $this->getTitle()->getArticleID() ) { | |
return Status::newFatal( $this->msg( 'entityschema-error-wrong-page-revisions' ) ); | |
} | |
return Status::newGood( $revToRestore ); | |
} | |
/** | |
* @throws ReadOnlyError | |
* @throws UserBlockedError | |
* @throws PermissionsError | |
*/ | |
protected function checkPermissions() { | |
if ( $this->getUser()->isBlockedFrom( $this->getTitle() ) ) { | |
throw new UserBlockedError( $this->getUser()->getBlock() ); | |
} | |
if ( wfReadOnly() ) { | |
throw new ReadOnlyError; | |
} | |
if ( !$this->getUser()->isAllowed( $this->getRestriction() ) ) { | |
throw new PermissionsError( $this->getRestriction() ); | |
} | |
} | |
/** | |
* Output an error page showing the given status | |
* | |
* @param Status $status The status to report. | |
*/ | |
protected function showRestoreErrorPage( Status $status ) { | |
$this->getOutput()->prepareErrorPage( | |
$this->msg( 'entityschema-restore-heading-failed' ), | |
$this->msg( 'errorpagetitle' ) | |
); | |
$this->getOutput()->addHTML( Html::errorBox( $status->getMessage()->parse() ) ); | |
$this->getOutput()->returnToMain( null, $this->getTitle() ); | |
} | |
} |