summaryrefslogtreecommitdiff
path: root/includes/actions/RevertAction.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
committerPierre Schmitz <pierre@archlinux.de>2011-12-03 13:29:22 +0100
commitca32f08966f1b51fcb19460f0996bb0c4048e6fe (patch)
treeec04cc15b867bc21eedca904cea9af0254531a11 /includes/actions/RevertAction.php
parenta22fbfc60f36f5f7ee10d5ae6fe347340c2ee67c (diff)
Update to MediaWiki 1.18.0
* also update ArchLinux skin to chagnes in MonoBook * Use only css to hide our menu bar when printing
Diffstat (limited to 'includes/actions/RevertAction.php')
-rw-r--r--includes/actions/RevertAction.php140
1 files changed, 140 insertions, 0 deletions
diff --git a/includes/actions/RevertAction.php b/includes/actions/RevertAction.php
new file mode 100644
index 00000000..bcb8cd8b
--- /dev/null
+++ b/includes/actions/RevertAction.php
@@ -0,0 +1,140 @@
+<?php
+/**
+ * File reversion user interface
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ * @file
+ * @ingroup Action
+ * @ingroup Media
+ * @author Alexandre Emsenhuber
+ * @author Rob Church <robchur@gmail.com>
+ */
+
+/**
+ * Dummy class for pages not in NS_FILE
+ *
+ * @ingroup Action
+ */
+class RevertAction extends Action {
+
+ public function getName() {
+ return 'revert';
+ }
+
+ public function getRestriction() {
+ return 'read';
+ }
+
+ public function show() {
+ $this->getOutput()->showErrorPage( 'nosuchaction', 'nosuchactiontext' );
+ }
+
+ public function execute() {}
+}
+
+/**
+ * Class for pages in NS_FILE
+ *
+ * @ingroup Action
+ */
+class RevertFileAction extends FormAction {
+ protected $oldFile;
+
+ public function getName() {
+ return 'revert';
+ }
+
+ public function getRestriction() {
+ return 'upload';
+ }
+
+ protected function checkCanExecute( User $user ) {
+ parent::checkCanExecute( $user );
+
+ $oldimage = $this->getRequest()->getText( 'oldimage' );
+ if ( strlen( $oldimage ) < 16
+ || strpos( $oldimage, '/' ) !== false
+ || strpos( $oldimage, '\\' ) !== false )
+ {
+ throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) );
+ }
+
+ $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $this->getTitle(), $oldimage );
+ if ( !$this->oldFile->exists() ) {
+ throw new ErrorPageError( '', 'filerevert-badversion' );
+ }
+ }
+
+ protected function alterForm( HTMLForm $form ) {
+ $form->setWrapperLegend( wfMsgHtml( 'filerevert-legend' ) );
+ $form->setSubmitText( wfMsg( 'filerevert-submit' ) );
+ $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
+ }
+
+ protected function getFormFields() {
+ global $wgContLang;
+
+ $timestamp = $this->oldFile->getTimestamp();
+
+ return array(
+ 'intro' => array(
+ 'type' => 'info',
+ 'vertical-label' => true,
+ 'raw' => true,
+ 'default' => wfMsgExt( 'filerevert-intro', 'parse', $this->getTitle()->getText(),
+ $this->getLang()->date( $timestamp, true ), $this->getLang()->time( $timestamp, true ),
+ wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
+ PROTO_CURRENT
+ ) )
+ ),
+ 'comment' => array(
+ 'type' => 'text',
+ 'label-message' => 'filerevert-comment',
+ 'default' => wfMsgForContent( 'filerevert-defaultcomment',
+ $wgContLang->date( $timestamp, false, false ), $wgContLang->time( $timestamp, false, false ) ),
+ )
+ );
+ }
+
+ public function onSubmit( $data ) {
+ $source = $this->page->getFile()->getArchiveVirtualUrl( $this->getRequest()->getText( 'oldimage' ) );
+ $comment = $data['comment'];
+ // TODO: Preserve file properties from database instead of reloading from file
+ return $this->page->getFile()->upload( $source, $comment, $comment );
+ }
+
+ public function onSuccess() {
+ $timestamp = $this->oldFile->getTimestamp();
+ $this->getOutput()->addHTML( wfMsgExt( 'filerevert-success', 'parse', $this->getTitle()->getText(),
+ $this->getLang()->date( $timestamp, true ),
+ $this->getLang()->time( $timestamp, true ),
+ wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
+ PROTO_CURRENT
+ ) ) );
+ $this->getOutput()->returnToMain( false, $this->getTitle() );
+ }
+
+ protected function getPageTitle() {
+ return wfMsg( 'filerevert', $this->getTitle()->getText() );
+ }
+
+ protected function getDescription() {
+ return wfMsg(
+ 'filerevert-backlink',
+ Linker::linkKnown( $this->getTitle() )
+ );
+ }
+}