MediaWiki
REL1_23
|
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 } 00044 00050 class RevertFileAction extends FormAction { 00054 protected $oldFile; 00055 00056 public function getName() { 00057 return 'revert'; 00058 } 00059 00060 public function getRestriction() { 00061 return 'upload'; 00062 } 00063 00064 protected function checkCanExecute( User $user ) { 00065 parent::checkCanExecute( $user ); 00066 00067 $oldimage = $this->getRequest()->getText( 'oldimage' ); 00068 if ( strlen( $oldimage ) < 16 00069 || strpos( $oldimage, '/' ) !== false 00070 || strpos( $oldimage, '\\' ) !== false 00071 ) { 00072 throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) ); 00073 } 00074 00075 $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( 00076 $this->getTitle(), 00077 $oldimage 00078 ); 00079 00080 if ( !$this->oldFile->exists() ) { 00081 throw new ErrorPageError( '', 'filerevert-badversion' ); 00082 } 00083 } 00084 00085 protected function alterForm( HTMLForm $form ) { 00086 $form->setWrapperLegendMsg( 'filerevert-legend' ); 00087 $form->setSubmitTextMsg( 'filerevert-submit' ); 00088 $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) ); 00089 } 00090 00091 protected function getFormFields() { 00092 global $wgContLang; 00093 00094 $timestamp = $this->oldFile->getTimestamp(); 00095 00096 $user = $this->getUser(); 00097 $lang = $this->getLanguage(); 00098 $userDate = $lang->userDate( $timestamp, $user ); 00099 $userTime = $lang->userTime( $timestamp, $user ); 00100 $siteDate = $wgContLang->date( $timestamp, false, false ); 00101 $siteTime = $wgContLang->time( $timestamp, false, false ); 00102 00103 return array( 00104 'intro' => array( 00105 'type' => 'info', 00106 'vertical-label' => true, 00107 'raw' => true, 00108 'default' => $this->msg( 'filerevert-intro', 00109 $this->getTitle()->getText(), $userDate, $userTime, 00110 wfExpandUrl( 00111 $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ), 00112 PROTO_CURRENT 00113 ) )->parseAsBlock() 00114 ), 00115 'comment' => array( 00116 'type' => 'text', 00117 'label-message' => 'filerevert-comment', 00118 'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime 00119 )->inContentLanguage()->text() 00120 ) 00121 ); 00122 } 00123 00124 public function onSubmit( $data ) { 00125 $source = $this->page->getFile()->getArchiveVirtualUrl( 00126 $this->getRequest()->getText( 'oldimage' ) 00127 ); 00128 $comment = $data['comment']; 00129 00130 // TODO: Preserve file properties from database instead of reloading from file 00131 return $this->page->getFile()->upload( 00132 $source, 00133 $comment, 00134 $comment, 00135 0, 00136 false, 00137 false, 00138 $this->getUser() 00139 ); 00140 } 00141 00142 public function onSuccess() { 00143 $timestamp = $this->oldFile->getTimestamp(); 00144 $user = $this->getUser(); 00145 $lang = $this->getLanguage(); 00146 $userDate = $lang->userDate( $timestamp, $user ); 00147 $userTime = $lang->userTime( $timestamp, $user ); 00148 00149 $this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(), 00150 $userDate, $userTime, 00151 wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ), 00152 PROTO_CURRENT 00153 ) ); 00154 $this->getOutput()->returnToMain( false, $this->getTitle() ); 00155 } 00156 00157 protected function getPageTitle() { 00158 return $this->msg( 'filerevert', $this->getTitle()->getText() ); 00159 } 00160 00161 protected function getDescription() { 00162 $this->getOutput()->addBacklinkSubtitle( $this->getTitle() ); 00163 00164 return ''; 00165 } 00166 }