Merge "Don't fallback from uk to ru"
[lhc/web/wiklou.git] / includes / actions / RevertAction.php
index 8a54c39..e466e65 100644 (file)
@@ -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,