Merge "Title: Use a more proper way of detecting whether interwikis are local"
[lhc/web/wiklou.git] / includes / api / ApiImport.php
index dffd6b2..a0f0a8d 100644 (file)
@@ -53,17 +53,31 @@ 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 );
                }
 
+               // Check if user can add the log entry tags which were requested
+               if ( $params['tags'] ) {
+                       $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
+                       if ( !$ableToTag->isOK() ) {
+                               $this->dieStatus( $ableToTag );
+                       }
+               }
+
                $importer = new WikiImporter( $source->value, $this->getConfig() );
                if ( isset( $params['namespace'] ) ) {
                        $importer->setTargetNamespace( $params['namespace'] );
@@ -73,12 +87,16 @@ class ApiImport extends ApiBase {
                                $this->dieStatus( $statusRootPage );
                        }
                }
+               $importer->setUsernamePrefix( $usernamePrefix, $params['assignknownusers'] );
                $reporter = new ApiImportReporter(
                        $importer,
                        $isUpload,
                        $params['interwikisource'],
                        $params['summary']
                );
+               if ( $params['tags'] ) {
+                       $reporter->setChangeTags( $params['tags'] );
+               }
 
                try {
                        $importer->doImport();
@@ -130,6 +148,9 @@ class ApiImport extends ApiBase {
                        'xml' => [
                                ApiBase::PARAM_TYPE => 'upload',
                        ],
+                       'interwikiprefix' => [
+                               ApiBase::PARAM_TYPE => 'string',
+                       ],
                        'interwikisource' => [
                                ApiBase::PARAM_TYPE => $this->getAllowedImportSources(),
                        ],
@@ -139,7 +160,12 @@ class ApiImport extends ApiBase {
                        'namespace' => [
                                ApiBase::PARAM_TYPE => 'namespace'
                        ],
+                       'assignknownusers' => false,
                        'rootpage' => null,
+                       'tags' => [
+                               ApiBase::PARAM_TYPE => 'tags',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ],
                ];
        }
 
@@ -156,7 +182,7 @@ class ApiImport extends ApiBase {
        }
 
        public function getHelpUrls() {
-               return 'https://www.mediawiki.org/wiki/API:Import';
+               return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
        }
 }