MediaWiki  REL1_19
RevertAction.php
Go to the documentation of this file.
00001 <?php
00031 class RevertAction extends Action {
00032 
00033         public function getName() {
00034                 return 'revert';
00035         }
00036 
00037         public function show() {
00038                 $this->getOutput()->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
00039         }
00040 
00041         public function execute() {}
00042 }
00043 
00049 class RevertFileAction extends FormAction {
00050         protected $oldFile;
00051 
00052         public function getName() {
00053                 return 'revert';
00054         }
00055 
00056         public function getRestriction() {
00057                 return 'upload';
00058         }
00059 
00060         protected function checkCanExecute( User $user ) {
00061                 parent::checkCanExecute( $user );
00062 
00063                 $oldimage = $this->getRequest()->getText( 'oldimage' );
00064                 if ( strlen( $oldimage ) < 16
00065                         || strpos( $oldimage, '/' ) !== false
00066                         || strpos( $oldimage, '\\' ) !== false )
00067                 {
00068                         throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) );
00069                 }
00070 
00071                 $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->getTitle(), $oldimage );
00072                 if ( !$this->oldFile->exists() ) {
00073                         throw new ErrorPageError( '', 'filerevert-badversion' );
00074                 }
00075         }
00076 
00077         protected function alterForm( HTMLForm $form ) {
00078                 $form->setWrapperLegend( wfMsgHtml( 'filerevert-legend' ) );
00079                 $form->setSubmitText( wfMsg( 'filerevert-submit' ) );
00080                 $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
00081         }
00082 
00083         protected function getFormFields() {
00084                 global $wgContLang;
00085 
00086                 $timestamp = $this->oldFile->getTimestamp();
00087 
00088                 return array(
00089                         'intro' => array(
00090                                 'type' => 'info',
00091                                 'vertical-label' => true,
00092                                 'raw' => true,
00093                                 'default' => wfMsgExt( 'filerevert-intro', 'parse', $this->getTitle()->getText(),
00094                                         $this->getLanguage()->date( $timestamp, true ), $this->getLanguage()->time( $timestamp, true ),
00095                                         wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
00096                                                 PROTO_CURRENT
00097                                 ) )
00098                         ),
00099                         'comment' => array(
00100                                 'type' => 'text',
00101                                 'label-message' => 'filerevert-comment',
00102                                 'default' => wfMsgForContent( 'filerevert-defaultcomment',
00103                                         $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ),
00104                         )
00105                 );
00106         }
00107 
00108         public function onSubmit( $data ) {
00109                 $source = $this->page->getFile()->getArchiveVirtualUrl( $this->getRequest()->getText( 'oldimage' ) );
00110                 $comment = $data['comment'];
00111                 // TODO: Preserve file properties from database instead of reloading from file
00112                 return $this->page->getFile()->upload( $source, $comment, $comment );
00113         }
00114 
00115         public function onSuccess() {
00116                 $timestamp = $this->oldFile->getTimestamp();
00117                 $this->getOutput()->addHTML( wfMsgExt( 'filerevert-success', 'parse', $this->getTitle()->getText(),
00118                         $this->getLanguage()->date( $timestamp, true ),
00119                         $this->getLanguage()->time( $timestamp, true ),
00120                         wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
00121                                 PROTO_CURRENT
00122                 ) ) );
00123                 $this->getOutput()->returnToMain( false, $this->getTitle() );
00124         }
00125 
00126         protected function getPageTitle() {
00127                 return wfMsg( 'filerevert', $this->getTitle()->getText() );
00128         }
00129         
00130         protected function getDescription() {
00131                 $this->getOutput()->addBacklinkSubtitle( $this->getTitle() );
00132                 return '';
00133         }
00134 }