30 parent::__construct( $main, $action );
40 if ( isset( $params[
'interwikisource'] ) ) {
44 if ( !isset( $params[
'interwikipage'] ) ) {
45 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
48 $params[
'interwikisource'],
49 $params[
'interwikipage'],
50 $params[
'fullhistory'],
53 $usernamePrefix = $params[
'interwikisource'];
56 if ( !$this->
getAuthority()->isAllowed(
'importupload' ) ) {
60 $usernamePrefix = (string)$params[
'interwikiprefix'];
61 if ( $usernamePrefix ===
'' ) {
63 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
71 if ( $params[
'tags'] ) {
72 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params[
'tags'], $this->
getAuthority() );
73 if ( !$ableToTag->isOK() ) {
78 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value, $this->getAuthority() );
79 if ( isset( $params[
'namespace'] ) ) {
80 $importer->setTargetNamespace( $params[
'namespace'] );
81 } elseif ( isset( $params[
'rootpage'] ) ) {
82 $statusRootPage = $importer->setTargetRootPage( $params[
'rootpage'] );
83 if ( !$statusRootPage->isGood() ) {
87 $importer->setUsernamePrefix( $usernamePrefix, $params[
'assignknownusers'] );
91 $params[
'interwikisource'],
95 if ( $params[
'tags'] ) {
96 $reporter->setChangeTags( $params[
'tags'] );
100 $importer->doImport();
101 }
catch ( Exception $e ) {
102 $this->
dieWithException( $e, [
'wrap' =>
'apierror-import-unknownerror' ] );
105 $resultData = $reporter->getData();
108 $result->addValue(
null, $this->
getModuleName(), $resultData );
123 foreach ( $importSources as $key => $value ) {
124 if ( is_int( $key ) ) {
127 foreach ( $value as $subproject ) {
128 $result[] =
"$key:$subproject";
150 ParamValidator::PARAM_TYPE =>
'upload',
152 'interwikiprefix' => [
153 ParamValidator::PARAM_TYPE =>
'string',
155 'interwikisource' => [
158 'interwikipage' =>
null,
159 'fullhistory' =>
false,
160 'templates' =>
false,
162 ParamValidator::PARAM_TYPE =>
'namespace'
164 'assignknownusers' =>
false,
167 ParamValidator::PARAM_TYPE =>
'tags',
168 ParamValidator::PARAM_ISMULTI =>
true,
181 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
182 'namespace=100&fullhistory=&token=123ABC'
183 =>
'apihelp-import-example-import',
189 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
194class_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()