32 parent::__construct( $main, $action );
34 $this->wikiImporterFactory = $wikiImporterFactory;
44 if ( isset( $params[
'interwikisource'] ) ) {
48 if ( !isset( $params[
'interwikipage'] ) ) {
49 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
52 $params[
'interwikisource'],
53 $params[
'interwikipage'],
54 $params[
'fullhistory'],
57 $usernamePrefix = $params[
'interwikisource'];
60 if ( !$this->
getAuthority()->isAllowed(
'importupload' ) ) {
64 $usernamePrefix = (string)$params[
'interwikiprefix'];
65 if ( $usernamePrefix ===
'' ) {
67 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
75 if ( $params[
'tags'] ) {
76 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params[
'tags'], $this->
getAuthority() );
77 if ( !$ableToTag->isOK() ) {
82 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value, $this->getAuthority() );
83 if ( isset( $params[
'namespace'] ) ) {
84 $importer->setTargetNamespace( $params[
'namespace'] );
85 } elseif ( isset( $params[
'rootpage'] ) ) {
86 $statusRootPage = $importer->setTargetRootPage( $params[
'rootpage'] );
87 if ( !$statusRootPage->isGood() ) {
91 $importer->setUsernamePrefix( $usernamePrefix, $params[
'assignknownusers'] );
95 $params[
'interwikisource'],
99 if ( $params[
'tags'] ) {
100 $reporter->setChangeTags( $params[
'tags'] );
104 $importer->doImport();
105 }
catch ( Exception $e ) {
106 $this->
dieWithException( $e, [
'wrap' =>
'apierror-import-unknownerror' ] );
109 $resultData = $reporter->getData();
112 $result->addValue(
null, $this->
getModuleName(), $resultData );
127 foreach ( $importSources as $key => $value ) {
128 if ( is_int( $key ) ) {
131 foreach ( $value as $subproject ) {
132 $result[] =
"$key:$subproject";
154 ParamValidator::PARAM_TYPE =>
'upload',
156 'interwikiprefix' => [
157 ParamValidator::PARAM_TYPE =>
'string',
159 'interwikisource' => [
162 'interwikipage' =>
null,
163 'fullhistory' =>
false,
164 'templates' =>
false,
166 ParamValidator::PARAM_TYPE =>
'namespace'
168 'assignknownusers' =>
false,
171 ParamValidator::PARAM_TYPE =>
'tags',
172 ParamValidator::PARAM_ISMULTI =>
true,
185 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
186 'namespace=100&fullhistory=&token=123ABC'
187 =>
'apihelp-import-example-import',
193 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
198class_alias( ApiImport::class,
'ApiImport' );
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()