46 parent::__construct( $main, $action );
48 $this->wikiImporterFactory = $wikiImporterFactory;
58 if ( isset( $params[
'interwikisource'] ) ) {
62 if ( !isset( $params[
'interwikipage'] ) ) {
63 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
66 $params[
'interwikisource'],
67 $params[
'interwikipage'],
68 $params[
'fullhistory'],
71 $usernamePrefix = $params[
'interwikisource'];
74 if ( !$this->
getAuthority()->isAllowed(
'importupload' ) ) {
78 $usernamePrefix = (string)$params[
'interwikiprefix'];
79 if ( $usernamePrefix ===
'' ) {
81 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
89 if ( $params[
'tags'] ) {
91 if ( !$ableToTag->isOK() ) {
96 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value, $this->getAuthority() );
97 if ( isset( $params[
'namespace'] ) ) {
98 $importer->setTargetNamespace( $params[
'namespace'] );
99 } elseif ( isset( $params[
'rootpage'] ) ) {
100 $statusRootPage = $importer->setTargetRootPage( $params[
'rootpage'] );
101 if ( !$statusRootPage->isGood() ) {
105 $importer->setUsernamePrefix( $usernamePrefix, $params[
'assignknownusers'] );
109 $params[
'interwikisource'],
113 if ( $params[
'tags'] ) {
114 $reporter->setChangeTags( $params[
'tags'] );
118 $importer->doImport();
119 }
catch ( Exception $e ) {
120 $this->
dieWithException( $e, [
'wrap' =>
'apierror-import-unknownerror' ] );
123 $resultData = $reporter->getData();
126 $result->addValue(
null, $this->
getModuleName(), $resultData );
141 foreach ( $importSources as $key => $value ) {
142 if ( is_int( $key ) ) {
145 foreach ( $value as $subproject ) {
146 $result[] =
"$key:$subproject";
165 ParamValidator::PARAM_TYPE =>
'upload',
167 'interwikiprefix' => [
168 ParamValidator::PARAM_TYPE =>
'string',
170 'interwikisource' => [
173 'interwikipage' =>
null,
174 'fullhistory' =>
false,
175 'templates' =>
false,
177 ParamValidator::PARAM_TYPE =>
'namespace'
179 'assignknownusers' =>
false,
182 ParamValidator::PARAM_TYPE =>
'tags',
183 ParamValidator::PARAM_ISMULTI =>
true,
194 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
195 'namespace=100&fullhistory=&token=123ABC'
196 =>
'apihelp-import-example-import',
201 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
206class_alias( ApiImport::class,
'ApiImport' );
Imports a XML dump from a file (either from file upload, files on disk, or HTTP)
static newFromInterwiki( $interwiki, $page, $history=false, $templates=false, $pageLinkDepth=0)
static newFromUpload( $fieldname="xmlimport")
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
const ImportSources
Name constant for the ImportSources setting, for use with Config::get()
Factory service for WikiImporter instances.