38 if ( isset( $params[
'interwikisource'] ) ) {
42 if ( !isset( $params[
'interwikipage'] ) ) {
43 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
46 $params[
'interwikisource'],
47 $params[
'interwikipage'],
48 $params[
'fullhistory'],
51 $usernamePrefix = $params[
'interwikisource'];
58 $usernamePrefix = (string)$params[
'interwikiprefix'];
59 if ( $usernamePrefix ===
'' ) {
61 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
69 if ( $params[
'tags'] ) {
71 if ( !$ableToTag->isOK() ) {
77 if ( isset( $params[
'namespace'] ) ) {
78 $importer->setTargetNamespace( $params[
'namespace'] );
79 } elseif ( isset( $params[
'rootpage'] ) ) {
80 $statusRootPage = $importer->setTargetRootPage( $params[
'rootpage'] );
81 if ( !$statusRootPage->isGood() ) {
85 $importer->setUsernamePrefix( $usernamePrefix, $params[
'assignknownusers'] );
89 $params[
'interwikisource'],
92 if ( $params[
'tags'] ) {
93 $reporter->setChangeTags( $params[
'tags'] );
97 $importer->doImport();
98 }
catch ( Exception $e ) {
102 $resultData = $reporter->getData();
104 ApiResult::setIndexedTagName( $resultData,
'page' );
105 $result->addValue(
null, $this->
getModuleName(), $resultData );
116 $importSources = $this->
getConfig()->get(
'ImportSources' );
117 Hooks::run(
'ImportSources', [ &$importSources ] );
120 foreach ( $importSources as $key => $value ) {
121 if ( is_int( $key ) ) {
124 foreach ( $value as $subproject ) {
125 $result[] =
"$key:$subproject";
146 'interwikiprefix' => [
149 'interwikisource' => [
152 'interwikipage' =>
null,
153 'fullhistory' =>
false,
154 'templates' =>
false,
158 'assignknownusers' =>
false,
173 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
174 'namespace=100&fullhistory=&token=123ABC'
175 =>
'apihelp-import-example-import',
180 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.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
dieWithException( $exception, array $options=[])
Abort execution with an error derived from an exception.
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.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
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.
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.
static newFromInterwiki( $interwiki, $page, $history=false, $templates=false, $pageLinkDepth=0)
static newFromUpload( $fieldname="xmlimport")
XML file reader for the page data importer.