32 parent::__construct( $main, $action );
42 if ( isset( $params[
'interwikisource'] ) ) {
46 if ( !isset( $params[
'interwikipage'] ) ) {
47 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
50 $params[
'interwikisource'],
51 $params[
'interwikipage'],
52 $params[
'fullhistory'],
55 $usernamePrefix = $params[
'interwikisource'];
58 if ( !$this->
getAuthority()->isAllowed(
'importupload' ) ) {
62 $usernamePrefix = (string)$params[
'interwikiprefix'];
63 if ( $usernamePrefix ===
'' ) {
65 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
73 if ( $params[
'tags'] ) {
74 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params[
'tags'], $this->
getAuthority() );
75 if ( !$ableToTag->isOK() ) {
80 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value, $this->getAuthority() );
81 if ( isset( $params[
'namespace'] ) ) {
82 $importer->setTargetNamespace( $params[
'namespace'] );
83 } elseif ( isset( $params[
'rootpage'] ) ) {
84 $statusRootPage = $importer->setTargetRootPage( $params[
'rootpage'] );
85 if ( !$statusRootPage->isGood() ) {
89 $importer->setUsernamePrefix( $usernamePrefix, $params[
'assignknownusers'] );
92 $scopedNoRateLimit = $this->permissionManager->addTemporaryUserRights(
96 $importer->setAuthorizeOnly(
true );
97 $importer->doImport();
98 if ( $importer->getReauthOperation() !==
null ) {
100 [
'badaccess-cannotreauthenticate', $importer->getReauthOperation() ],
109 $params[
'interwikisource'],
110 $params[
'interwikipage'],
111 $params[
'fullhistory'],
117 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value, $this->getAuthority() );
118 if ( isset( $params[
'namespace'] ) ) {
119 $importer->setTargetNamespace( $params[
'namespace'] );
120 } elseif ( isset( $params[
'rootpage'] ) ) {
121 $importer->setTargetRootPage( $params[
'rootpage'] );
123 $importer->setUsernamePrefix( $usernamePrefix, $params[
'assignknownusers'] );
124 $importer->setAuthorizeOnly(
false );
129 $params[
'interwikisource'],
133 if ( $params[
'tags'] ) {
134 $reporter->setChangeTags( $params[
'tags'] );
138 $importer->doImport();
139 }
catch ( Exception $e ) {
140 $this->
dieWithException( $e, [
'wrap' =>
'apierror-import-unknownerror' ] );
143 $resultData = $reporter->getData();
146 $result->addValue(
null, $this->
getModuleName(), $resultData );
161 foreach ( $importSources as $key => $value ) {
162 if ( is_int( $key ) ) {
165 foreach ( $value as $subproject ) {
166 $result[] =
"$key:$subproject";
188 ParamValidator::PARAM_TYPE =>
'upload',
190 'interwikiprefix' => [
191 ParamValidator::PARAM_TYPE =>
'string',
193 'interwikisource' => [
196 'interwikipage' =>
null,
197 'fullhistory' =>
false,
198 'templates' =>
false,
200 ParamValidator::PARAM_TYPE =>
'namespace'
202 'assignknownusers' =>
false,
205 ParamValidator::PARAM_TYPE =>
'tags',
206 ParamValidator::PARAM_ISMULTI =>
true,
219 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
220 'namespace=100&fullhistory=&token=123ABC'
221 =>
'apihelp-import-example-import',
227 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
232class_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()