X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiImport.php;h=bf5e4ce3b288bed0a793492e2b516ffc5f7db39c;hb=92214baada6e6c5ae061a1034bce51b4342fd021;hp=10106ff02b4e056c8253662992b09e9a47533d0c;hpb=7f91193ef37d534949950c980416b5a921cd5d79;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index 10106ff02b..bf5e4ce3b2 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -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, + ], ]; }