43 if ( isset(
$params[
'interwikisource'] ) ) {
44 if ( !$user->isAllowed(
'import' ) ) {
47 if ( !isset(
$params[
'interwikipage'] ) ) {
48 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
58 if ( !$user->isAllowed(
'importupload' ) ) {
70 if ( !$ableToTag->isOK() ) {
76 if ( isset(
$params[
'namespace'] ) ) {
77 $importer->setTargetNamespace(
$params[
'namespace'] );
78 } elseif ( isset(
$params[
'rootpage'] ) ) {
79 $statusRootPage = $importer->setTargetRootPage(
$params[
'rootpage'] );
80 if ( !$statusRootPage->isGood() ) {
91 $reporter->setChangeTags(
$params[
'tags'] );
95 $importer->doImport();
96 }
catch ( Exception
$e ) {
100 $resultData = $reporter->getData();
103 $result->addValue(
null, $this->
getModuleName(), $resultData );
114 $importSources = $this->
getConfig()->get(
'ImportSources' );
115 Hooks::run(
'ImportSources', [ &$importSources ] );
118 foreach ( $importSources as $key =>
$value ) {
119 if ( is_int( $key ) ) {
122 foreach (
$value as $subproject ) {
123 $result[] =
"$key:$subproject";
144 'interwikisource' => [
147 'interwikipage' =>
null,
148 'fullhistory' =>
false,
149 'templates' =>
false,
167 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
168 'namespace=100&fullhistory=&token=123ABC'
169 =>
'apihelp-import-example-import',
174 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
193 public function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
197 if ( $title ===
null ) {
198 # Invalid or non-importable title
199 $r[
'title'] = $pageInfo[
'title'];
200 $r[
'invalid'] =
true;
203 $r[
'revisions'] = intval( $successCount );
206 $this->mResultArr[] = $r;
209 parent::reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo );
This abstract class implements many basic API functions, and is the base of all API classes.
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.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getResult()
Get the result object.
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.
reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo)
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 addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
getUser()
Get the User object.
getConfig()
Get the Config object.
static newFromInterwiki( $interwiki, $page, $history=false, $templates=false, $pageLinkDepth=0)
static newFromUpload( $fieldname="xmlimport")
XML file reader for the page data importer.
namespace being checked & $result
returning false will NOT prevent logging $e