X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Factions%2FRevertAction.php;h=e466e6549aea9c36f9cedb4ba4914307f2d65bfe;hb=f911bbdb7c015e4c1a3d7b5da0fa28e0f98f364b;hp=4885a31ec168c017cef5fa11230c9fbd8cf07aac;hpb=cb2896f90ebef77c02c9da4067b0e56e37471092;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/actions/RevertAction.php b/includes/actions/RevertAction.php index 4885a31ec1..e466e6549a 100644 --- a/includes/actions/RevertAction.php +++ b/includes/actions/RevertAction.php @@ -53,7 +53,7 @@ class RevertAction extends FormAction { || strpos( $oldimage, '/' ) !== false || strpos( $oldimage, '\\' ) !== false ) { - throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) ); + throw new ErrorPageError( 'internalerror', 'unexpected', [ 'oldimage', $oldimage ] ); } $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( @@ -70,7 +70,7 @@ class RevertAction extends FormAction { $form->setWrapperLegendMsg( 'filerevert-legend' ); $form->setSubmitTextMsg( 'filerevert-submit' ); $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) ); - $form->setTokenSalt( array( 'revert', $this->getTitle()->getPrefixedDBkey() ) ); + $form->setTokenSalt( [ 'revert', $this->getTitle()->getPrefixedDBkey() ] ); } protected function getFormFields() { @@ -88,8 +88,8 @@ class RevertAction extends FormAction { $siteTime = $wgContLang->time( $ts, false, false ); $tzMsg = $siteTs->getTimezoneMessage()->inContentLanguage()->text(); - return array( - 'intro' => array( + return [ + 'intro' => [ 'type' => 'info', 'vertical-label' => true, 'raw' => true, @@ -99,26 +99,32 @@ class RevertAction extends FormAction { $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ), PROTO_CURRENT ) )->parseAsBlock() - ), - 'comment' => array( + ], + 'comment' => [ 'type' => 'text', 'label-message' => 'filerevert-comment', 'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime, $tzMsg )->inContentLanguage()->text() - ) - ); + ] + ]; } public function onSubmit( $data ) { $this->useTransactionalTimeLimit(); - $source = $this->page->getFile()->getArchiveVirtualUrl( - $this->getRequest()->getText( 'oldimage' ) - ); + $old = $this->getRequest()->getText( 'oldimage' ); + $localFile = $this->page->getFile(); + $oldFile = OldLocalFile::newFromArchiveName( $this->getTitle(), $localFile->getRepo(), $old ); + + $source = $localFile->getArchiveVirtualUrl( $old ); $comment = $data['comment']; + if ( $localFile->getSha1() === $oldFile->getSha1() ) { + return Status::newFatal( 'filerevert-identical' ); + } + // TODO: Preserve file properties from database instead of reloading from file - return $this->page->getFile()->upload( + return $localFile->upload( $source, $comment, $comment, @@ -151,4 +157,8 @@ class RevertAction extends FormAction { protected function getDescription() { return OutputPage::buildBacklinkSubtitle( $this->getTitle() ); } + + public function doesWrites() { + return true; + } }