]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/api/ApiUndelete.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / api / ApiUndelete.php
index 7205d05ded88314fc21392d87e7ca253a3d1cd98..3aa7b608dca7497ff39550ee562d24070bdf000c 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 /**
- * API for MediaWiki 1.8+
+ *
  *
  * Created on Jul 3, 2007
  *
- * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
+ * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
  *
  * 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
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( "ApiBase.php" );
-}
-
 /**
  * @ingroup API
  */
 class ApiUndelete extends ApiBase {
 
-       public function __construct( $main, $action ) {
-               parent::__construct( $main, $action );
-       }
-
        public function execute() {
-               global $wgUser;
+               $this->useTransactionalTimeLimit();
+
                $params = $this->extractRequestParams();
 
-               if ( !$wgUser->isAllowed( 'undelete' ) ) {
-                       $this->dieUsageMsg( array( 'permdenied-undelete' ) );
+               $user = $this->getUser();
+               if ( $user->isBlocked() ) {
+                       $this->dieBlocked( $user->getBlock() );
                }
 
-               if ( $wgUser->isBlocked() ) {
-                       $this->dieUsageMsg( array( 'blockedtext' ) );
+               $titleObj = Title::newFromText( $params['title'] );
+               if ( !$titleObj || $titleObj->isExternal() ) {
+                       $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] );
                }
 
-               $titleObj = Title::newFromText( $params['title'] );
-               if ( !$titleObj ) {
-                       $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
+               if ( !$titleObj->userCan( 'undelete', $user, 'secure' ) ) {
+                       $this->dieWithError( 'permdenied-undelete' );
+               }
+
+               // Check if user can add tags
+               if ( !is_null( $params['tags'] ) ) {
+                       $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
+                       if ( !$ableToTag->isOK() ) {
+                               $this->dieStatus( $ableToTag );
+                       }
                }
 
                // Convert timestamps
                if ( !isset( $params['timestamps'] ) ) {
-                       $params['timestamps'] = array();
+                       $params['timestamps'] = [];
                }
                if ( !is_array( $params['timestamps'] ) ) {
-                       $params['timestamps'] = array( $params['timestamps'] );
+                       $params['timestamps'] = [ $params['timestamps'] ];
                }
                foreach ( $params['timestamps'] as $i => $ts ) {
                        $params['timestamps'][$i] = wfTimestamp( TS_MW, $ts );
                }
 
-               $pa = new PageArchive( $titleObj );
-               $retval = $pa->undelete( ( isset( $params['timestamps'] ) ? $params['timestamps'] : array() ), $params['reason'] );
+               $pa = new PageArchive( $titleObj, $this->getConfig() );
+               $retval = $pa->undelete(
+                       ( isset( $params['timestamps'] ) ? $params['timestamps'] : [] ),
+                       $params['reason'],
+                       $params['fileids'],
+                       false,
+                       $user,
+                       $params['tags']
+               );
                if ( !is_array( $retval ) ) {
-                       $this->dieUsageMsg( array( 'cannotundelete' ) );
+                       $this->dieWithError( 'apierror-cantundelete' );
                }
 
                if ( $retval[1] ) {
-                       wfRunHooks( 'FileUndeleteComplete',
-                               array( $titleObj, array(), $wgUser, $params['reason'] ) );
+                       Hooks::run( 'FileUndeleteComplete',
+                               [ $titleObj, $params['fileids'], $this->getUser(), $params['reason'] ] );
                }
 
                $this->setWatch( $params['watchlist'], $titleObj );
@@ -82,7 +90,7 @@ class ApiUndelete extends ApiBase {
                $info['title'] = $titleObj->getPrefixedText();
                $info['revisions'] = intval( $retval[0] );
                $info['fileversions'] = intval( $retval[1] );
-               $info['reason'] = intval( $retval[2] );
+               $info['reason'] = $retval[2];
                $this->getResult()->addValue( null, $this->getModuleName(), $info );
        }
 
@@ -95,70 +103,51 @@ class ApiUndelete extends ApiBase {
        }
 
        public function getAllowedParams() {
-               return array(
-                       'title' => array(
+               return [
+                       'title' => [
                                ApiBase::PARAM_TYPE => 'string',
                                ApiBase::PARAM_REQUIRED => true
-                       ),
-                       'token' => null,
+                       ],
                        'reason' => '',
-                       'timestamps' => array(
-                               ApiBase::PARAM_ISMULTI => true
-                       ),
-                       'watchlist' => array(
+                       'tags' => [
+                               ApiBase::PARAM_TYPE => 'tags',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ],
+                       'timestamps' => [
+                               ApiBase::PARAM_TYPE => 'timestamp',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ],
+                       'fileids' => [
+                               ApiBase::PARAM_TYPE => 'integer',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ],
+                       'watchlist' => [
                                ApiBase::PARAM_DFLT => 'preferences',
-                               ApiBase::PARAM_TYPE => array(
+                               ApiBase::PARAM_TYPE => [
                                        'watch',
                                        'unwatch',
                                        'preferences',
                                        'nochange'
-                               ),
-                       ),
-               );
-       }
-
-       public function getParamDescription() {
-               return array(
-                       'title' => 'Title of the page you want to restore',
-                       'token' => 'An undelete token previously retrieved through list=deletedrevs',
-                       'reason' => 'Reason for restoring (optional)',
-                       'timestamps' => 'Timestamps of the revisions to restore. If not set, all revisions will be restored.',
-                       'watchlist' => 'Unconditionally add or remove the page from your watchlist, use preferences or do not change watch',
-               );
-       }
-
-       public function getDescription() {
-               return array(
-                       'Restore certain revisions of a deleted page. A list of deleted revisions (including timestamps) can be',
-                       'retrieved through list=deletedrevs'
-               );
-       }
-
-       public function getPossibleErrors() {
-               return array_merge( parent::getPossibleErrors(), array(
-                       array( 'permdenied-undelete' ),
-                       array( 'blockedtext' ),
-                       array( 'invalidtitle', 'title' ),
-                       array( 'cannotundelete' ),
-               ) );
+                               ],
+                       ],
+               ];
        }
 
        public function needsToken() {
-               return true;
+               return 'csrf';
        }
 
-       public function getTokenSalt() {
-               return '';
-       }
-
-       protected function getExamples() {
-               return array(
-                       'api.php?action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page',
-                       'api.php?action=undelete&title=Main%20Page&token=123ABC&timestamps=20070703220045|20070702194856'
-               );
+       protected function getExamplesMessages() {
+               return [
+                       'action=undelete&title=Main%20Page&token=123ABC&reason=Restoring%20main%20page'
+                               => 'apihelp-undelete-example-page',
+                       'action=undelete&title=Main%20Page&token=123ABC' .
+                               '&timestamps=2007-07-03T22:00:45Z|2007-07-02T19:48:56Z'
+                               => 'apihelp-undelete-example-revisions',
+               ];
        }
 
-       public function getVersion() {
-               return __CLASS__ . ': $Id$';
+       public function getHelpUrls() {
+               return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Undelete';
        }
 }