|| 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(
$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() {
$siteTime = $wgContLang->time( $ts, false, false );
$tzMsg = $siteTs->getTimezoneMessage()->inContentLanguage()->text();
- return array(
- 'intro' => array(
+ return [
+ 'intro' => [
'type' => 'info',
'vertical-label' => true,
'raw' => true,
$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,