X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fapi%2FApiImport.php;h=b36045e1f4cd18ba4895d7a2c075ddab4ee0a46b;hp=b46f0b1e5105d46cc2833336c2b7f5bfc0e430f7;hb=3f16fda078025ccf2716f0a6bf10a650244c9d89;hpb=64b83bdb3afd0ee4f8fc1893a865409c198e601e diff --git a/includes/api/ApiImport.php b/includes/api/ApiImport.php index b46f0b1e51..b36045e1f4 100644 --- a/includes/api/ApiImport.php +++ b/includes/api/ApiImport.php @@ -1,9 +1,5 @@ .@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; - } -}