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() {}
45 * Class for pages in NS_FILE
49 class RevertFileAction
extends FormAction
{
52 public function getName() {
56 public function getRestriction() {
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->setWrapperLegend( wfMsgHtml( 'filerevert-legend' ) );
79 $form->setSubmitText( wfMsg( 'filerevert-submit' ) );
80 $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
83 protected function getFormFields() {
86 $timestamp = $this->oldFile
->getTimestamp();
91 'vertical-label' => true,
93 'default' => wfMsgExt( 'filerevert-intro', 'parse', $this->getTitle()->getText(),
94 $this->getLanguage()->date( $timestamp, true ), $this->getLanguage()->time( $timestamp, true ),
95 wfExpandUrl( $this->page
->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
101 'label-message' => 'filerevert-comment',
102 'default' => wfMsgForContent( 'filerevert-defaultcomment',
103 $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ),
108 public function onSubmit( $data ) {
109 $source = $this->page
->getFile()->getArchiveVirtualUrl( $this->getRequest()->getText( 'oldimage' ) );
110 $comment = $data['comment'];
111 // TODO: Preserve file properties from database instead of reloading from file
112 return $this->page
->getFile()->upload( $source, $comment, $comment );
115 public function onSuccess() {
116 $timestamp = $this->oldFile
->getTimestamp();
117 $this->getOutput()->addHTML( wfMsgExt( 'filerevert-success', 'parse', $this->getTitle()->getText(),
118 $this->getLanguage()->date( $timestamp, true ),
119 $this->getLanguage()->time( $timestamp, true ),
120 wfExpandUrl( $this->page
->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
123 $this->getOutput()->returnToMain( false, $this->getTitle() );
126 protected function getPageTitle() {
127 return wfMsg( 'filerevert', $this->getTitle()->getText() );
130 protected function getDescription() {
131 $this->getOutput()->addBacklinkSubtitle( $this->getTitle() );