X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Factions%2FRevertAction.php;h=6481630e11096576ba8489b8b8dfa88d400b583a;hb=64ca212514d48330ff02fdaed34563e0b75e22c4;hp=a5fc4e173439f1113dd5d3a8f0fb71e52521eb1b;hpb=29ab088e2fb938b0b3330bc4d4891a155e9420d2;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/actions/RevertAction.php b/includes/actions/RevertAction.php index a5fc4e1734..6481630e11 100644 --- a/includes/actions/RevertAction.php +++ b/includes/actions/RevertAction.php @@ -24,29 +24,14 @@ */ /** - * Dummy class for pages not in NS_FILE - * - * @ingroup Actions - */ -class RevertAction extends Action { - - public function getName() { - return 'revert'; - } - - public function show() { - $this->getOutput()->showErrorPage( 'nosuchaction', 'nosuchactiontext' ); - } - - public function execute() {} -} - -/** - * Class for pages in NS_FILE + * File reversion user interface * * @ingroup Actions */ -class RevertFileAction extends FormAction { +class RevertAction extends FormAction { + /** + * @var OldLocalFile + */ protected $oldFile; public function getName() { @@ -58,17 +43,24 @@ class RevertFileAction extends FormAction { } protected function checkCanExecute( User $user ) { + if ( $this->getTitle()->getNamespace() !== NS_FILE ) { + throw new ErrorPageError( $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) ); + } parent::checkCanExecute( $user ); $oldimage = $this->getRequest()->getText( 'oldimage' ); if ( strlen( $oldimage ) < 16 || strpos( $oldimage, '/' ) !== false - || strpos( $oldimage, '\\' ) !== false ) - { + || strpos( $oldimage, '\\' ) !== false + ) { throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) ); } - $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->getTitle(), $oldimage ); + $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( + $this->getTitle(), + $oldimage + ); + if ( !$this->oldFile->exists() ) { throw new ErrorPageError( '', 'filerevert-badversion' ); } @@ -78,6 +70,7 @@ class RevertFileAction extends FormAction { $form->setWrapperLegendMsg( 'filerevert-legend' ); $form->setSubmitTextMsg( 'filerevert-submit' ); $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) ); + $form->setTokenSalt( array( 'revert', $this->getTitle()->getPrefixedDBkey() ) ); } protected function getFormFields() { @@ -99,8 +92,10 @@ class RevertFileAction extends FormAction { 'raw' => true, 'default' => $this->msg( 'filerevert-intro', $this->getTitle()->getText(), $userDate, $userTime, - wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ), - PROTO_CURRENT ) )->parseAsBlock() + wfExpandUrl( + $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ), + PROTO_CURRENT + ) )->parseAsBlock() ), 'comment' => array( 'type' => 'text', @@ -112,10 +107,21 @@ class RevertFileAction extends FormAction { } public function onSubmit( $data ) { - $source = $this->page->getFile()->getArchiveVirtualUrl( $this->getRequest()->getText( 'oldimage' ) ); + $source = $this->page->getFile()->getArchiveVirtualUrl( + $this->getRequest()->getText( 'oldimage' ) + ); $comment = $data['comment']; + // TODO: Preserve file properties from database instead of reloading from file - return $this->page->getFile()->upload( $source, $comment, $comment, 0, false, false, $this->getUser() ); + return $this->page->getFile()->upload( + $source, + $comment, + $comment, + 0, + false, + false, + $this->getUser() + ); } public function onSuccess() { @@ -139,6 +145,7 @@ class RevertFileAction extends FormAction { protected function getDescription() { $this->getOutput()->addBacklinkSubtitle( $this->getTitle() ); + return ''; } }