34 private $wikiImporterFactory;
46 parent::__construct( $main, $action );
48 $this->wikiImporterFactory = $wikiImporterFactory;
58 if ( isset( $params[
'interwikisource'] ) ) {
62 if ( !isset( $params[
'interwikipage'] ) ) {
63 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
66 $params[
'interwikisource'],
67 $params[
'interwikipage'],
68 $params[
'fullhistory'],
71 $usernamePrefix = $params[
'interwikisource'];
74 if ( !$this->
getAuthority()->isAllowed(
'importupload' ) ) {
78 $usernamePrefix = (string)$params[
'interwikiprefix'];
79 if ( $usernamePrefix ===
'' ) {
81 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
89 if ( $params[
'tags'] ) {
91 if ( !$ableToTag->isOK() ) {
96 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value );
97 if ( isset( $params[
'namespace'] ) ) {
98 $importer->setTargetNamespace( $params[
'namespace'] );
99 } elseif ( isset( $params[
'rootpage'] ) ) {
100 $statusRootPage = $importer->setTargetRootPage( $params[
'rootpage'] );
101 if ( !$statusRootPage->isGood() ) {
105 $importer->setUsernamePrefix( $usernamePrefix, $params[
'assignknownusers'] );
109 $params[
'interwikisource'],
112 if ( $params[
'tags'] ) {
113 $reporter->setChangeTags( $params[
'tags'] );
117 $importer->doImport();
118 }
catch ( Exception $e ) {
119 $this->
dieWithException( $e, [
'wrap' =>
'apierror-import-unknownerror' ] );
122 $resultData = $reporter->getData();
124 ApiResult::setIndexedTagName( $resultData,
'page' );
125 $result->addValue(
null, $this->
getModuleName(), $resultData );
136 $importSources = $this->
getConfig()->get( MainConfigNames::ImportSources );
140 foreach ( $importSources as $key => $value ) {
141 if ( is_int( $key ) ) {
144 foreach ( $value as $subproject ) {
145 $result[] =
"$key:$subproject";
164 ParamValidator::PARAM_TYPE =>
'upload',
166 'interwikiprefix' => [
167 ParamValidator::PARAM_TYPE =>
'string',
169 'interwikisource' => [
172 'interwikipage' =>
null,
173 'fullhistory' =>
false,
174 'templates' =>
false,
176 ParamValidator::PARAM_TYPE =>
'namespace'
178 'assignknownusers' =>
false,
181 ParamValidator::PARAM_TYPE =>
'tags',
182 ParamValidator::PARAM_ISMULTI =>
true,
193 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
194 'namespace=100&fullhistory=&token=123ABC'
195 =>
'apihelp-import-example-import',
200 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)
Die if more than one of a certain set of parameters is 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.
static newFromInterwiki( $interwiki, $page, $history=false, $templates=false, $pageLinkDepth=0)
static newFromUpload( $fieldname="xmlimport")
A class containing constants representing the names of configuration variables.
Factory service for WikiImporter instances.