MediaWiki
REL1_22
|
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->setWrapperLegendMsg( 'filerevert-legend' ); 00079 $form->setSubmitTextMsg( '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 $user = $this->getUser(); 00089 $lang = $this->getLanguage(); 00090 $userDate = $lang->userDate( $timestamp, $user ); 00091 $userTime = $lang->userTime( $timestamp, $user ); 00092 $siteDate = $wgContLang->date( $timestamp, false, false ); 00093 $siteTime = $wgContLang->time( $timestamp, false, false ); 00094 00095 return array( 00096 'intro' => array( 00097 'type' => 'info', 00098 'vertical-label' => true, 00099 'raw' => true, 00100 'default' => $this->msg( 'filerevert-intro', 00101 $this->getTitle()->getText(), $userDate, $userTime, 00102 wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ), 00103 PROTO_CURRENT ) )->parseAsBlock() 00104 ), 00105 'comment' => array( 00106 'type' => 'text', 00107 'label-message' => 'filerevert-comment', 00108 'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime 00109 )->inContentLanguage()->text() 00110 ) 00111 ); 00112 } 00113 00114 public function onSubmit( $data ) { 00115 $source = $this->page->getFile()->getArchiveVirtualUrl( $this->getRequest()->getText( 'oldimage' ) ); 00116 $comment = $data['comment']; 00117 // TODO: Preserve file properties from database instead of reloading from file 00118 return $this->page->getFile()->upload( $source, $comment, $comment, 0, false, false, $this->getUser() ); 00119 } 00120 00121 public function onSuccess() { 00122 $timestamp = $this->oldFile->getTimestamp(); 00123 $user = $this->getUser(); 00124 $lang = $this->getLanguage(); 00125 $userDate = $lang->userDate( $timestamp, $user ); 00126 $userTime = $lang->userTime( $timestamp, $user ); 00127 00128 $this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(), 00129 $userDate, $userTime, 00130 wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ), 00131 PROTO_CURRENT 00132 ) ); 00133 $this->getOutput()->returnToMain( false, $this->getTitle() ); 00134 } 00135 00136 protected function getPageTitle() { 00137 return $this->msg( 'filerevert', $this->getTitle()->getText() ); 00138 } 00139 00140 protected function getDescription() { 00141 $this->getOutput()->addBacklinkSubtitle( $this->getTitle() ); 00142 return ''; 00143 } 00144 }