wfMsgForContentNoTrans() was removed
[mediawiki.git] / includes / actions / RevertAction.php
blob4885a31ec168c017cef5fa11230c9fbd8cf07aac
1 <?php
2 /**
3 * File reversion user interface
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 * @file
20 * @ingroup Actions
21 * @ingroup Media
22 * @author Alexandre Emsenhuber
23 * @author Rob Church <robchur@gmail.com>
26 /**
27 * File reversion user interface
29 * @ingroup Actions
31 class RevertAction extends FormAction {
32 /**
33 * @var OldLocalFile
35 protected $oldFile;
37 public function getName() {
38 return 'revert';
41 public function getRestriction() {
42 return 'upload';
45 protected function checkCanExecute( User $user ) {
46 if ( $this->getTitle()->getNamespace() !== NS_FILE ) {
47 throw new ErrorPageError( $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
49 parent::checkCanExecute( $user );
51 $oldimage = $this->getRequest()->getText( 'oldimage' );
52 if ( strlen( $oldimage ) < 16
53 || strpos( $oldimage, '/' ) !== false
54 || strpos( $oldimage, '\\' ) !== false
55 ) {
56 throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) );
59 $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName(
60 $this->getTitle(),
61 $oldimage
64 if ( !$this->oldFile->exists() ) {
65 throw new ErrorPageError( '', 'filerevert-badversion' );
69 protected function alterForm( HTMLForm $form ) {
70 $form->setWrapperLegendMsg( 'filerevert-legend' );
71 $form->setSubmitTextMsg( 'filerevert-submit' );
72 $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
73 $form->setTokenSalt( array( 'revert', $this->getTitle()->getPrefixedDBkey() ) );
76 protected function getFormFields() {
77 global $wgContLang;
79 $timestamp = $this->oldFile->getTimestamp();
81 $user = $this->getUser();
82 $lang = $this->getLanguage();
83 $userDate = $lang->userDate( $timestamp, $user );
84 $userTime = $lang->userTime( $timestamp, $user );
85 $siteTs = MWTimestamp::getLocalInstance( $timestamp );
86 $ts = $siteTs->format( 'YmdHis' );
87 $siteDate = $wgContLang->date( $ts, false, false );
88 $siteTime = $wgContLang->time( $ts, false, false );
89 $tzMsg = $siteTs->getTimezoneMessage()->inContentLanguage()->text();
91 return array(
92 'intro' => array(
93 'type' => 'info',
94 'vertical-label' => true,
95 'raw' => true,
96 'default' => $this->msg( 'filerevert-intro',
97 $this->getTitle()->getText(), $userDate, $userTime,
98 wfExpandUrl(
99 $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
100 PROTO_CURRENT
101 ) )->parseAsBlock()
103 'comment' => array(
104 'type' => 'text',
105 'label-message' => 'filerevert-comment',
106 'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime,
107 $tzMsg )->inContentLanguage()->text()
112 public function onSubmit( $data ) {
113 $this->useTransactionalTimeLimit();
115 $source = $this->page->getFile()->getArchiveVirtualUrl(
116 $this->getRequest()->getText( 'oldimage' )
118 $comment = $data['comment'];
120 // TODO: Preserve file properties from database instead of reloading from file
121 return $this->page->getFile()->upload(
122 $source,
123 $comment,
124 $comment,
126 false,
127 false,
128 $this->getUser()
132 public function onSuccess() {
133 $timestamp = $this->oldFile->getTimestamp();
134 $user = $this->getUser();
135 $lang = $this->getLanguage();
136 $userDate = $lang->userDate( $timestamp, $user );
137 $userTime = $lang->userTime( $timestamp, $user );
139 $this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(),
140 $userDate, $userTime,
141 wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
142 PROTO_CURRENT
143 ) );
144 $this->getOutput()->returnToMain( false, $this->getTitle() );
147 protected function getPageTitle() {
148 return $this->msg( 'filerevert', $this->getTitle()->getText() );
151 protected function getDescription() {
152 return OutputPage::buildBacklinkSubtitle( $this->getTitle() );