Merge "Handle missing namespace prefix in XML dumps more gracefully"
[lhc/web/wiklou.git] / includes / api / ApiImport.php
index 10106ff..bf5e4ce 100644 (file)
@@ -42,10 +42,10 @@ class ApiImport extends ApiBase {
                $isUpload = false;
                if ( isset( $params['interwikisource'] ) ) {
                        if ( !$user->isAllowed( 'import' ) ) {
-                               $this->dieUsageMsg( 'cantimport' );
+                               $this->dieWithError( 'apierror-cantimport' );
                        }
                        if ( !isset( $params['interwikipage'] ) ) {
-                               $this->dieUsageMsg( [ 'missingparam', 'interwikipage' ] );
+                               $this->dieWithError( [ 'apierror-missingparam', 'interwikipage' ] );
                        }
                        $source = ImportStreamSource::newFromInterwiki(
                                $params['interwikisource'],
@@ -56,7 +56,7 @@ class ApiImport extends ApiBase {
                } else {
                        $isUpload = true;
                        if ( !$user->isAllowed( 'importupload' ) ) {
-                               $this->dieUsageMsg( 'cantimport-upload' );
+                               $this->dieWithError( 'apierror-cantimport-upload' );
                        }
                        $source = ImportStreamSource::newFromUpload( 'xml' );
                }
@@ -64,6 +64,14 @@ class ApiImport extends ApiBase {
                        $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'] );
@@ -79,11 +87,14 @@ class ApiImport extends ApiBase {
                        $params['interwikisource'],
                        $params['summary']
                );
+               if ( $params['tags'] ) {
+                       $reporter->setChangeTags( $params['tags'] );
+               }
 
                try {
                        $importer->doImport();
                } catch ( Exception $e ) {
-                       $this->dieUsageMsg( [ 'import-unknownerror', $e->getMessage() ] );
+                       $this->dieWithException( $e, [ 'wrap' => 'apierror-import-unknownerror' ] );
                }
 
                $resultData = $reporter->getData();
@@ -140,6 +151,10 @@ class ApiImport extends ApiBase {
                                ApiBase::PARAM_TYPE => 'namespace'
                        ],
                        'rootpage' => null,
+                       'tags' => [
+                               ApiBase::PARAM_TYPE => 'tags',
+                               ApiBase::PARAM_ISMULTI => true,
+                       ],
                ];
        }