Merge "Add ss_active_users in SiteStats::isSane"
[mediawiki.git] / includes / actions / RevertAction.php
bloba5fc4e173439f1113dd5d3a8f0fb71e52521eb1b
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() {}
44 /**
45 * Class for pages in NS_FILE
47 * @ingroup Actions
49 class RevertFileAction extends FormAction {
50 protected $oldFile;
52 public function getName() {
53 return 'revert';
56 public function getRestriction() {
57 return 'upload';
60 protected function checkCanExecute( User $user ) {
61 parent::checkCanExecute( $user );
63 $oldimage = $this->getRequest()->getText( 'oldimage' );
64 if ( strlen( $oldimage ) < 16
65 || strpos( $oldimage, '/' ) !== false
66 || strpos( $oldimage, '\\' ) !== false )
68 throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) );
71 $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->getTitle(), $oldimage );
72 if ( !$this->oldFile->exists() ) {
73 throw new ErrorPageError( '', 'filerevert-badversion' );
77 protected function alterForm( HTMLForm $form ) {
78 $form->setWrapperLegendMsg( 'filerevert-legend' );
79 $form->setSubmitTextMsg( 'filerevert-submit' );
80 $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
83 protected function getFormFields() {
84 global $wgContLang;
86 $timestamp = $this->oldFile->getTimestamp();
88 $user = $this->getUser();
89 $lang = $this->getLanguage();
90 $userDate = $lang->userDate( $timestamp, $user );
91 $userTime = $lang->userTime( $timestamp, $user );
92 $siteDate = $wgContLang->date( $timestamp, false, false );
93 $siteTime = $wgContLang->time( $timestamp, false, false );
95 return array(
96 'intro' => array(
97 'type' => 'info',
98 'vertical-label' => true,
99 'raw' => true,
100 'default' => $this->msg( 'filerevert-intro',
101 $this->getTitle()->getText(), $userDate, $userTime,
102 wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
103 PROTO_CURRENT ) )->parseAsBlock()
105 'comment' => array(
106 'type' => 'text',
107 'label-message' => 'filerevert-comment',
108 'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime
109 )->inContentLanguage()->text()
114 public function onSubmit( $data ) {
115 $source = $this->page->getFile()->getArchiveVirtualUrl( $this->getRequest()->getText( 'oldimage' ) );
116 $comment = $data['comment'];
117 // TODO: Preserve file properties from database instead of reloading from file
118 return $this->page->getFile()->upload( $source, $comment, $comment, 0, false, false, $this->getUser() );
121 public function onSuccess() {
122 $timestamp = $this->oldFile->getTimestamp();
123 $user = $this->getUser();
124 $lang = $this->getLanguage();
125 $userDate = $lang->userDate( $timestamp, $user );
126 $userTime = $lang->userTime( $timestamp, $user );
128 $this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(),
129 $userDate, $userTime,
130 wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
131 PROTO_CURRENT
132 ) );
133 $this->getOutput()->returnToMain( false, $this->getTitle() );
136 protected function getPageTitle() {
137 return $this->msg( 'filerevert', $this->getTitle()->getText() );
140 protected function getDescription() {
141 $this->getOutput()->addBacklinkSubtitle( $this->getTitle() );
142 return '';