45 parent::__construct( $main, $action );
47 $this->wikiImporterFactory = $wikiImporterFactory;
57 if ( isset( $params[
'interwikisource'] ) ) {
61 if ( !isset( $params[
'interwikipage'] ) ) {
62 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
64 $source = ImportStreamSource::newFromInterwiki(
65 $params[
'interwikisource'],
66 $params[
'interwikipage'],
67 $params[
'fullhistory'],
70 $usernamePrefix = $params[
'interwikisource'];
73 if ( !$this->
getAuthority()->isAllowed(
'importupload' ) ) {
76 $source = ImportStreamSource::newFromUpload(
'xml' );
77 $usernamePrefix = (string)$params[
'interwikiprefix'];
78 if ( $usernamePrefix ===
'' ) {
80 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
88 if ( $params[
'tags'] ) {
90 if ( !$ableToTag->isOK() ) {
95 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value );
96 if ( isset( $params[
'namespace'] ) ) {
97 $importer->setTargetNamespace( $params[
'namespace'] );
98 } elseif ( isset( $params[
'rootpage'] ) ) {
99 $statusRootPage = $importer->setTargetRootPage( $params[
'rootpage'] );
100 if ( !$statusRootPage->isGood() ) {
104 $importer->setUsernamePrefix( $usernamePrefix, $params[
'assignknownusers'] );
108 $params[
'interwikisource'],
111 if ( $params[
'tags'] ) {
112 $reporter->setChangeTags( $params[
'tags'] );
116 $importer->doImport();
117 }
catch ( Exception $e ) {
118 $this->
dieWithException( $e, [
'wrap' =>
'apierror-import-unknownerror' ] );
121 $resultData = $reporter->getData();
123 ApiResult::setIndexedTagName( $resultData,
'page' );
124 $result->addValue(
null, $this->
getModuleName(), $resultData );
135 $importSources = $this->
getConfig()->get( MainConfigNames::ImportSources );
139 foreach ( $importSources as $key => $value ) {
140 if ( is_int( $key ) ) {
143 foreach ( $value as $subproject ) {
144 $result[] =
"$key:$subproject";
163 ParamValidator::PARAM_TYPE =>
'upload',
165 'interwikiprefix' => [
166 ParamValidator::PARAM_TYPE =>
'string',
168 'interwikisource' => [
171 'interwikipage' =>
null,
172 'fullhistory' =>
false,
173 'templates' =>
false,
175 ParamValidator::PARAM_TYPE =>
'namespace'
177 'assignknownusers' =>
false,
180 ParamValidator::PARAM_TYPE =>
'tags',
181 ParamValidator::PARAM_ISMULTI =>
true,
192 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
193 'namespace=100&fullhistory=&token=123ABC'
194 =>
'apihelp-import-example-import',
199 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
requireMaxOneParameter( $params,... $required)
Dies if more than one parameter from a certain set of parameters are set and not false.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
useTransactionalTimeLimit()
Call wfTransactionalTimeLimit() if this request was POSTed.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
dieWithException(Throwable $exception, array $options=[])
Abort execution with an error derived from a throwable.
Import reporter for the API.
API module that imports an XML file like Special:Import does.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
needsToken()
Returns the token type this module requires in order to execute.
isWriteMode()
Indicates whether this module requires write mode.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
mustBePosted()
Indicates whether this module must be called with a POST request.
__construct(ApiMain $main, $action, WikiImporterFactory $wikiImporterFactory)
getAllowedImportSources()
Returns a list of interwiki prefixes corresponding to each defined import source.
getExamplesMessages()
Returns usage examples for this module.
getHelpUrls()
Return links to more detailed help pages about the module.
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
Factory service for WikiImporter instances.