43 parent::__construct( $main, $action );
56 if ( isset( $params[
'interwikisource'] ) ) {
60 if ( !isset( $params[
'interwikipage'] ) ) {
61 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
64 $params[
'interwikisource'],
65 $params[
'interwikipage'],
66 $params[
'fullhistory'],
69 $usernamePrefix = $params[
'interwikisource'];
72 if ( !$this->
getAuthority()->isAllowed(
'importupload' ) ) {
76 $usernamePrefix = (string)$params[
'interwikiprefix'];
77 if ( $usernamePrefix ===
'' ) {
79 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
87 if ( $params[
'tags'] ) {
89 if ( !$ableToTag->isOK() ) {
94 $importer = $this->wikiImporterFactory->getWikiImporter(
$source->value );
95 if ( isset( $params[
'namespace'] ) ) {
96 $importer->setTargetNamespace( $params[
'namespace'] );
97 } elseif ( isset( $params[
'rootpage'] ) ) {
98 $statusRootPage = $importer->setTargetRootPage( $params[
'rootpage'] );
99 if ( !$statusRootPage->isGood() ) {
103 $importer->setUsernamePrefix( $usernamePrefix, $params[
'assignknownusers'] );
107 $params[
'interwikisource'],
110 if ( $params[
'tags'] ) {
111 $reporter->setChangeTags( $params[
'tags'] );
115 $importer->doImport();
116 }
catch ( Exception $e ) {
117 $this->
dieWithException( $e, [
'wrap' =>
'apierror-import-unknownerror' ] );
120 $resultData = $reporter->getData();
122 ApiResult::setIndexedTagName( $resultData,
'page' );
123 $result->addValue(
null, $this->
getModuleName(), $resultData );
134 $importSources = $this->
getConfig()->get(
'ImportSources' );
138 foreach ( $importSources as $key => $value ) {
139 if ( is_int( $key ) ) {
142 foreach ( $value as $subproject ) {
143 $result[] =
"$key:$subproject";
164 'interwikiprefix' => [
167 'interwikisource' => [
170 'interwikipage' =>
null,
171 'fullhistory' =>
false,
172 'templates' =>
false,
176 'assignknownusers' =>
false,
191 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
192 'namespace=100&fullhistory=&token=123ABC'
193 =>
'apihelp-import-example-import',
198 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.
WikiImporterFactory $wikiImporterFactory
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")
Factory service for WikiImporter instances.