Merge "Typography update to Vector skin"
[mediawiki.git] / includes / actions / RevertAction.php
blobcdd139e734f1d81f1408c02745e1c95cf1c96f91
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 * Dummy class for pages not in NS_FILE
29 * @ingroup Actions
31 class RevertAction extends Action {
33 public function getName() {
34 return 'revert';
37 public function show() {
38 $this->getOutput()->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
41 public function execute() {
45 /**
46 * Class for pages in NS_FILE
48 * @ingroup Actions
50 class RevertFileAction extends FormAction {
51 /**
52 * @var OldLocalFile
54 protected $oldFile;
56 public function getName() {
57 return 'revert';
60 public function getRestriction() {
61 return 'upload';
64 protected function checkCanExecute( User $user ) {
65 parent::checkCanExecute( $user );
67 $oldimage = $this->getRequest()->getText( 'oldimage' );
68 if ( strlen( $oldimage ) < 16
69 || strpos( $oldimage, '/' ) !== false
70 || strpos( $oldimage, '\\' ) !== false
71 ) {
72 throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) );
75 $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName(
76 $this->getTitle(),
77 $oldimage
80 if ( !$this->oldFile->exists() ) {
81 throw new ErrorPageError( '', 'filerevert-badversion' );
85 protected function alterForm( HTMLForm $form ) {
86 $form->setWrapperLegendMsg( 'filerevert-legend' );
87 $form->setSubmitTextMsg( 'filerevert-submit' );
88 $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
91 protected function getFormFields() {
92 global $wgContLang;
94 $timestamp = $this->oldFile->getTimestamp();
96 $user = $this->getUser();
97 $lang = $this->getLanguage();
98 $userDate = $lang->userDate( $timestamp, $user );
99 $userTime = $lang->userTime( $timestamp, $user );
100 $siteDate = $wgContLang->date( $timestamp, false, false );
101 $siteTime = $wgContLang->time( $timestamp, false, false );
103 return array(
104 'intro' => array(
105 'type' => 'info',
106 'vertical-label' => true,
107 'raw' => true,
108 'default' => $this->msg( 'filerevert-intro',
109 $this->getTitle()->getText(), $userDate, $userTime,
110 wfExpandUrl(
111 $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
112 PROTO_CURRENT
113 ) )->parseAsBlock()
115 'comment' => array(
116 'type' => 'text',
117 'label-message' => 'filerevert-comment',
118 'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime
119 )->inContentLanguage()->text()
124 public function onSubmit( $data ) {
125 $source = $this->page->getFile()->getArchiveVirtualUrl(
126 $this->getRequest()->getText( 'oldimage' )
128 $comment = $data['comment'];
130 // TODO: Preserve file properties from database instead of reloading from file
131 return $this->page->getFile()->upload(
132 $source,
133 $comment,
134 $comment,
136 false,
137 false,
138 $this->getUser()
142 public function onSuccess() {
143 $timestamp = $this->oldFile->getTimestamp();
144 $user = $this->getUser();
145 $lang = $this->getLanguage();
146 $userDate = $lang->userDate( $timestamp, $user );
147 $userTime = $lang->userTime( $timestamp, $user );
149 $this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(),
150 $userDate, $userTime,
151 wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
152 PROTO_CURRENT
153 ) );
154 $this->getOutput()->returnToMain( false, $this->getTitle() );
157 protected function getPageTitle() {
158 return $this->msg( 'filerevert', $this->getTitle()->getText() );
161 protected function getDescription() {
162 $this->getOutput()->addBacklinkSubtitle( $this->getTitle() );
164 return '';