Split ApiImport.php to have one class in one file
[lhc/web/wiklou.git] / includes / api / ApiImport.php
index b46f0b1..b36045e 100644 (file)
@@ -1,9 +1,5 @@
 <?php
 /**
- *
- *
- * Created on Feb 4, 2009
- *
  * Copyright © 2009 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
  *
  * This program is free software; you can redistribute it and/or modify
@@ -53,12 +49,18 @@ class ApiImport extends ApiBase {
                                $params['fullhistory'],
                                $params['templates']
                        );
+                       $usernamePrefix = $params['interwikisource'];
                } else {
                        $isUpload = true;
                        if ( !$user->isAllowed( 'importupload' ) ) {
                                $this->dieWithError( 'apierror-cantimport-upload' );
                        }
                        $source = ImportStreamSource::newFromUpload( 'xml' );
+                       $usernamePrefix = (string)$params['interwikiprefix'];
+                       if ( $usernamePrefix === '' ) {
+                               $encParamName = $this->encodeParamName( 'interwikiprefix' );
+                               $this->dieWithError( [ 'apierror-missingparam', $encParamName ] );
+                       }
                }
                if ( !$source->isOK() ) {
                        $this->dieStatus( $source );
@@ -81,6 +83,7 @@ class ApiImport extends ApiBase {
                                $this->dieStatus( $statusRootPage );
                        }
                }
+               $importer->setUsernamePrefix( $usernamePrefix, $params['assignknownusers'] );
                $reporter = new ApiImportReporter(
                        $importer,
                        $isUpload,
@@ -141,6 +144,9 @@ class ApiImport extends ApiBase {
                        'xml' => [
                                ApiBase::PARAM_TYPE => 'upload',
                        ],
+                       'interwikiprefix' => [
+                               ApiBase::PARAM_TYPE => 'string',
+                       ],
                        'interwikisource' => [
                                ApiBase::PARAM_TYPE => $this->getAllowedImportSources(),
                        ],
@@ -150,6 +156,7 @@ class ApiImport extends ApiBase {
                        'namespace' => [
                                ApiBase::PARAM_TYPE => 'namespace'
                        ],
+                       'assignknownusers' => false,
                        'rootpage' => null,
                        'tags' => [
                                ApiBase::PARAM_TYPE => 'tags',
@@ -174,42 +181,3 @@ class ApiImport extends ApiBase {
                return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
        }
 }
-
-/**
- * Import reporter for the API
- * @ingroup API
- */
-class ApiImportReporter extends ImportReporter {
-       private $mResultArr = [];
-
-       /**
-        * @param Title $title
-        * @param Title $origTitle
-        * @param int $revisionCount
-        * @param int $successCount
-        * @param array $pageInfo
-        * @return void
-        */
-       public function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
-               // Add a result entry
-               $r = [];
-
-               if ( $title === null ) {
-                       # Invalid or non-importable title
-                       $r['title'] = $pageInfo['title'];
-                       $r['invalid'] = true;
-               } else {
-                       ApiQueryBase::addTitleInfo( $r, $title );
-                       $r['revisions'] = intval( $successCount );
-               }
-
-               $this->mResultArr[] = $r;
-
-               // Piggyback on the parent to do the logging
-               parent::reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo );
-       }
-
-       public function getData() {
-               return $this->mResultArr;
-       }
-}