[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/includes/actions/ -> RevertAction.php (source)

   1  <?php
   2  /**
   3   * File reversion user interface
   4   *
   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.
   9   *
  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.
  14   *
  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
  18   *
  19   * @file
  20   * @ingroup Actions
  21   * @ingroup Media
  22   * @author Alexandre Emsenhuber
  23   * @author Rob Church <[email protected]>
  24   */
  25  
  26  /**
  27   * File reversion user interface
  28   *
  29   * @ingroup Actions
  30   */
  31  class RevertAction extends FormAction {
  32      /**
  33       * @var OldLocalFile
  34       */
  35      protected $oldFile;
  36  
  37  	public function getName() {
  38          return 'revert';
  39      }
  40  
  41  	public function getRestriction() {
  42          return 'upload';
  43      }
  44  
  45  	protected function checkCanExecute( User $user ) {
  46          if ( $this->getTitle()->getNamespace() !== NS_FILE ) {
  47              throw new ErrorPageError( $this->msg( 'nosuchaction' ), $this->msg( 'nosuchactiontext' ) );
  48          }
  49          parent::checkCanExecute( $user );
  50  
  51          $oldimage = $this->getRequest()->getText( 'oldimage' );
  52          if ( strlen( $oldimage ) < 16
  53              || strpos( $oldimage, '/' ) !== false
  54              || strpos( $oldimage, '\\' ) !== false
  55          ) {
  56              throw new ErrorPageError( 'internalerror', 'unexpected', array( 'oldimage', $oldimage ) );
  57          }
  58  
  59          $this->oldFile = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName(
  60              $this->getTitle(),
  61              $oldimage
  62          );
  63  
  64          if ( !$this->oldFile->exists() ) {
  65              throw new ErrorPageError( '', 'filerevert-badversion' );
  66          }
  67      }
  68  
  69  	protected function alterForm( HTMLForm $form ) {
  70          $form->setWrapperLegendMsg( 'filerevert-legend' );
  71          $form->setSubmitTextMsg( 'filerevert-submit' );
  72          $form->addHiddenField( 'oldimage', $this->getRequest()->getText( 'oldimage' ) );
  73          $form->setTokenSalt( array( 'revert', $this->getTitle()->getPrefixedDBkey() ) );
  74      }
  75  
  76  	protected function getFormFields() {
  77          global $wgContLang;
  78  
  79          $timestamp = $this->oldFile->getTimestamp();
  80  
  81          $user = $this->getUser();
  82          $lang = $this->getLanguage();
  83          $userDate = $lang->userDate( $timestamp, $user );
  84          $userTime = $lang->userTime( $timestamp, $user );
  85          $siteDate = $wgContLang->date( $timestamp, false, false );
  86          $siteTime = $wgContLang->time( $timestamp, false, false );
  87  
  88          return array(
  89              'intro' => array(
  90                  'type' => 'info',
  91                  'vertical-label' => true,
  92                  'raw' => true,
  93                  'default' => $this->msg( 'filerevert-intro',
  94                      $this->getTitle()->getText(), $userDate, $userTime,
  95                      wfExpandUrl(
  96                          $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
  97                          PROTO_CURRENT
  98                      ) )->parseAsBlock()
  99              ),
 100              'comment' => array(
 101                  'type' => 'text',
 102                  'label-message' => 'filerevert-comment',
 103                  'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime
 104                      )->inContentLanguage()->text()
 105              )
 106          );
 107      }
 108  
 109  	public function onSubmit( $data ) {
 110          $source = $this->page->getFile()->getArchiveVirtualUrl(
 111              $this->getRequest()->getText( 'oldimage' )
 112          );
 113          $comment = $data['comment'];
 114  
 115          // TODO: Preserve file properties from database instead of reloading from file
 116          return $this->page->getFile()->upload(
 117              $source,
 118              $comment,
 119              $comment,
 120              0,
 121              false,
 122              false,
 123              $this->getUser()
 124          );
 125      }
 126  
 127  	public function onSuccess() {
 128          $timestamp = $this->oldFile->getTimestamp();
 129          $user = $this->getUser();
 130          $lang = $this->getLanguage();
 131          $userDate = $lang->userDate( $timestamp, $user );
 132          $userTime = $lang->userTime( $timestamp, $user );
 133  
 134          $this->getOutput()->addWikiMsg( 'filerevert-success', $this->getTitle()->getText(),
 135              $userDate, $userTime,
 136              wfExpandUrl( $this->page->getFile()->getArchiveUrl( $this->getRequest()->getText( 'oldimage' ) ),
 137                  PROTO_CURRENT
 138          ) );
 139          $this->getOutput()->returnToMain( false, $this->getTitle() );
 140      }
 141  
 142  	protected function getPageTitle() {
 143          return $this->msg( 'filerevert', $this->getTitle()->getText() );
 144      }
 145  
 146  	protected function getDescription() {
 147          $this->getOutput()->addBacklinkSubtitle( $this->getTitle() );
 148  
 149          return '';
 150      }
 151  }


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1