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
22 * @author Alexandre Emsenhuber
23 * @author Rob Church <robchur@gmail.com>
27 * Dummy class for pages not in NS_FILE
31 class RevertAction
extends Action
{
33 public function getName() {
37 public function show() {
38 $this->getOutput()->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
41 public function execute() {
46 * Class for pages in NS_FILE
50 class RevertFileAction
extends FormAction
{
53 public function getName() {
57 public function getRestriction() {
61 protected function checkCanExecute( User
$user ) {
62 parent
::checkCanExecute( $user );
64 $oldimage = $this->getRequest()->getText( 'oldimage' );
65 if ( strlen( $oldimage ) < 16
66 ||
strpos( $oldimage, '/' ) !== false
67 ||
strpos( $oldimage, '\\' ) !== false
69 throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) );
72 $this->oldFile
= RepoGroup
::singleton()->getLocalRepo()->newFromArchiveName(
77 if ( !$this->oldFile
->exists() ) {
78 throw new ErrorPageError( '', 'filerevert-badversion' );
82 protected function alterForm( HTMLForm
$form ) {
83 $form->setWrapperLegendMsg( 'filerevert-legend' );
84 $form->setSubmitTextMsg( 'filerevert-submit' );
85 $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
88 protected function getFormFields() {
91 $timestamp = $this->oldFile
->getTimestamp();
93 $user = $this->getUser();
94 $lang = $this->getLanguage();
95 $userDate = $lang->userDate( $timestamp, $user );
96 $userTime = $lang->userTime( $timestamp, $user );
97 $siteDate = $wgContLang->date( $timestamp, false, false );
98 $siteTime = $wgContLang->time( $timestamp, false, false );
103 'vertical-label' => true,
105 'default' => $this->msg( 'filerevert-intro',
106 $this->getTitle()->getText(), $userDate, $userTime,
108 $this->page
->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
114 'label-message' => 'filerevert-comment',
115 'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime
116 )->inContentLanguage()->text()
121 public function onSubmit( $data ) {
122 $source = $this->page
->getFile()->getArchiveVirtualUrl(
123 $this->getRequest()->getText( 'oldimage' )
125 $comment = $data['comment'];
127 // TODO: Preserve file properties from database instead of reloading from file
128 return $this->page
->getFile()->upload(
139 public function onSuccess() {
140 $timestamp = $this->oldFile
->getTimestamp();
141 $user = $this->getUser();
142 $lang = $this->getLanguage();
143 $userDate = $lang->userDate( $timestamp, $user );
144 $userTime = $lang->userTime( $timestamp, $user );
146 $this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(),
147 $userDate, $userTime,
148 wfExpandUrl( $this->page
->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
151 $this->getOutput()->returnToMain( false, $this->getTitle() );
154 protected function getPageTitle() {
155 return $this->msg( 'filerevert', $this->getTitle()->getText() );
158 protected function getDescription() {
159 $this->getOutput()->addBacklinkSubtitle( $this->getTitle() );