<?php
/**
- *
- *
- * Created on Feb 4, 2009
- *
* Copyright © 2009 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
$params['fullhistory'],
$params['templates']
);
+ $usernamePrefix = $params['interwikisource'];
} else {
$isUpload = true;
if ( !$user->isAllowed( 'importupload' ) ) {
$this->dieWithError( 'apierror-cantimport-upload' );
}
$source = ImportStreamSource::newFromUpload( 'xml' );
+ $usernamePrefix = (string)$params['interwikiprefix'];
+ if ( $usernamePrefix === '' ) {
+ $encParamName = $this->encodeParamName( 'interwikiprefix' );
+ $this->dieWithError( [ 'apierror-missingparam', $encParamName ] );
+ }
}
if ( !$source->isOK() ) {
$this->dieStatus( $source );
}
+ // Check if user can add the log entry tags which were requested
+ if ( $params['tags'] ) {
+ $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
+ if ( !$ableToTag->isOK() ) {
+ $this->dieStatus( $ableToTag );
+ }
+ }
+
$importer = new WikiImporter( $source->value, $this->getConfig() );
if ( isset( $params['namespace'] ) ) {
$importer->setTargetNamespace( $params['namespace'] );
$this->dieStatus( $statusRootPage );
}
}
+ $importer->setUsernamePrefix( $usernamePrefix, $params['assignknownusers'] );
$reporter = new ApiImportReporter(
$importer,
$isUpload,
$params['interwikisource'],
$params['summary']
);
+ if ( $params['tags'] ) {
+ $reporter->setChangeTags( $params['tags'] );
+ }
try {
$importer->doImport();
'xml' => [
ApiBase::PARAM_TYPE => 'upload',
],
+ 'interwikiprefix' => [
+ ApiBase::PARAM_TYPE => 'string',
+ ],
'interwikisource' => [
ApiBase::PARAM_TYPE => $this->getAllowedImportSources(),
],
'namespace' => [
ApiBase::PARAM_TYPE => 'namespace'
],
+ 'assignknownusers' => false,
'rootpage' => null,
+ 'tags' => [
+ ApiBase::PARAM_TYPE => 'tags',
+ ApiBase::PARAM_ISMULTI => true,
+ ],
];
}
}
public function getHelpUrls() {
- return 'https://www.mediawiki.org/wiki/API:Import';
- }
-}
-
-/**
- * Import reporter for the API
- * @ingroup API
- */
-class ApiImportReporter extends ImportReporter {
- private $mResultArr = [];
-
- /**
- * @param Title $title
- * @param Title $origTitle
- * @param int $revisionCount
- * @param int $successCount
- * @param array $pageInfo
- * @return void
- */
- public function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
- // Add a result entry
- $r = [];
-
- if ( $title === null ) {
- # Invalid or non-importable title
- $r['title'] = $pageInfo['title'];
- $r['invalid'] = true;
- } else {
- ApiQueryBase::addTitleInfo( $r, $title );
- $r['revisions'] = intval( $successCount );
- }
-
- $this->mResultArr[] = $r;
-
- // Piggyback on the parent to do the logging
- parent::reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo );
- }
-
- public function getData() {
- return $this->mResultArr;
+ return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Import';
}
}