<?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 );
$this->dieStatus( $statusRootPage );
}
}
+ $importer->setUsernamePrefix( $usernamePrefix, $params['assignknownusers'] );
$reporter = new ApiImportReporter(
$importer,
$isUpload,
'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',
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/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;
- }
-}