51 parent::__construct( $main, $action );
53 $this->wikiImporterFactory = $wikiImporterFactory;
63 if ( isset(
$params[
'interwikisource'] ) ) {
67 if ( !isset(
$params[
'interwikipage'] ) ) {
68 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
76 $usernamePrefix =
$params[
'interwikisource'];
79 if ( !$this->
getAuthority()->isAllowed(
'importupload' ) ) {
83 $usernamePrefix = (string)
$params[
'interwikiprefix'];
84 if ( $usernamePrefix ===
'' ) {
86 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
96 if ( !$ableToTag->isOK() ) {
101 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value, $this->getAuthority() );
102 if ( isset(
$params[
'namespace'] ) ) {
103 $importer->setTargetNamespace(
$params[
'namespace'] );
104 } elseif ( isset(
$params[
'rootpage'] ) ) {
105 $statusRootPage = $importer->setTargetRootPage(
$params[
'rootpage'] );
106 if ( !$statusRootPage->isGood() ) {
110 $importer->setUsernamePrefix( $usernamePrefix,
$params[
'assignknownusers'] );
119 $reporter->setChangeTags(
$params[
'tags'] );
123 $importer->doImport();
124 }
catch ( Exception $e ) {
125 $this->
dieWithException( $e, [
'wrap' =>
'apierror-import-unknownerror' ] );
128 $resultData = $reporter->getData();
131 $result->addValue(
null, $this->
getModuleName(), $resultData );
146 foreach ( $importSources as $key => $value ) {
147 if ( is_int( $key ) ) {
150 foreach ( $value as $subproject ) {
151 $result[] =
"$key:$subproject";
170 ParamValidator::PARAM_TYPE =>
'upload',
172 'interwikiprefix' => [
173 ParamValidator::PARAM_TYPE =>
'string',
175 'interwikisource' => [
178 'interwikipage' =>
null,
179 'fullhistory' =>
false,
180 'templates' =>
false,
182 ParamValidator::PARAM_TYPE =>
'namespace'
184 'assignknownusers' =>
false,
187 ParamValidator::PARAM_TYPE =>
'tags',
188 ParamValidator::PARAM_ISMULTI =>
true,
199 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
200 'namespace=100&fullhistory=&token=123ABC'
201 =>
'apihelp-import-example-import',
206 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
211class_alias( ApiImport::class,
'ApiImport' );
array $params
The job parameters.
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.