39 if ( isset(
$params[
'interwikisource'] ) ) {
40 if ( !$user->isAllowed(
'import' ) ) {
43 if ( !isset(
$params[
'interwikipage'] ) ) {
44 $this->
dieWithError( [
'apierror-missingparam',
'interwikipage' ] );
52 $usernamePrefix =
$params[
'interwikisource'];
55 if ( !$user->isAllowed(
'importupload' ) ) {
60 if ( $usernamePrefix ===
'' ) {
62 $this->
dieWithError( [
'apierror-missingparam', $encParamName ] );
72 if ( !$ableToTag->isOK() ) {
78 if ( isset(
$params[
'namespace'] ) ) {
79 $importer->setTargetNamespace(
$params[
'namespace'] );
80 } elseif ( isset(
$params[
'rootpage'] ) ) {
81 $statusRootPage = $importer->setTargetRootPage(
$params[
'rootpage'] );
82 if ( !$statusRootPage->isGood() ) {
86 $importer->setUsernamePrefix( $usernamePrefix,
$params[
'assignknownusers'] );
94 $reporter->setChangeTags(
$params[
'tags'] );
98 $importer->doImport();
99 }
catch ( Exception
$e ) {
100 $this->
dieWithException( $e, [
'wrap' =>
'apierror-import-unknownerror' ] );
103 $resultData = $reporter->getData();
106 $result->addValue(
null, $this->
getModuleName(), $resultData );
117 $importSources = $this->
getConfig()->get(
'ImportSources' );
118 Hooks::run(
'ImportSources', [ &$importSources ] );
121 foreach ( $importSources as $key =>
$value ) {
122 if ( is_int( $key ) ) {
125 foreach (
$value as $subproject ) {
126 $result[] =
"$key:$subproject";
147 'interwikiprefix' => [
150 'interwikisource' => [
153 'interwikipage' =>
null,
154 'fullhistory' =>
false,
155 'templates' =>
false,
159 'assignknownusers' =>
false,
174 'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
175 'namespace=100&fullhistory=&token=123ABC'
176 =>
'apihelp-import-example-import',
181 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
200 public function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
204 if ( $title ===
null ) {
205 # Invalid or non-importable title
206 $r[
'title'] = $pageInfo[
'title'];
207 $r[
'invalid'] =
true;
210 $r[
'revisions'] = intval( $successCount );
213 $this->mResultArr[] = $r;
216 parent::reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo );
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.
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.
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
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
returning false will NOT prevent logging $e