$isUpload = false;
if ( isset( $params['interwikisource'] ) ) {
if ( !$user->isAllowed( 'import' ) ) {
- $this->dieUsageMsg( 'cantimport' );
+ $this->dieWithError( 'apierror-cantimport' );
}
if ( !isset( $params['interwikipage'] ) ) {
- $this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) );
+ $this->dieWithError( [ 'apierror-missingparam', 'interwikipage' ] );
}
$source = ImportStreamSource::newFromInterwiki(
$params['interwikisource'],
} else {
$isUpload = true;
if ( !$user->isAllowed( 'importupload' ) ) {
- $this->dieUsageMsg( 'cantimport-upload' );
+ $this->dieWithError( 'apierror-cantimport-upload' );
}
$source = ImportStreamSource::newFromUpload( 'xml' );
}
try {
$importer->doImport();
} catch ( Exception $e ) {
- $this->dieUsageMsg( array( 'import-unknownerror', $e->getMessage() ) );
+ $this->dieWithError( [ 'apierror-import-unknownerror', wfEscapeWikiText( $e->getMessage() ) ] );
}
$resultData = $reporter->getData();
$result->addValue( null, $this->getModuleName(), $resultData );
}
+ /**
+ * Returns a list of interwiki prefixes corresponding to each defined import
+ * source.
+ *
+ * @return array
+ * @since 1.27
+ */
+ public function getAllowedImportSources() {
+ $importSources = $this->getConfig()->get( 'ImportSources' );
+ Hooks::run( 'ImportSources', [ &$importSources ] );
+
+ $result = [];
+ foreach ( $importSources as $key => $value ) {
+ if ( is_int( $key ) ) {
+ $result[] = $value;
+ } else {
+ foreach ( $value as $subproject ) {
+ $result[] = "$key:$subproject";
+ }
+ }
+ }
+ return $result;
+ }
+
public function mustBePosted() {
return true;
}
}
public function getAllowedParams() {
- return array(
+ return [
'summary' => null,
- 'xml' => array(
+ 'xml' => [
ApiBase::PARAM_TYPE => 'upload',
- ),
- 'interwikisource' => array(
- ApiBase::PARAM_TYPE => $this->getConfig()->get( 'ImportSources' ),
- ),
+ ],
+ 'interwikisource' => [
+ ApiBase::PARAM_TYPE => $this->getAllowedImportSources(),
+ ],
'interwikipage' => null,
'fullhistory' => false,
'templates' => false,
- 'namespace' => array(
+ 'namespace' => [
ApiBase::PARAM_TYPE => 'namespace'
- ),
+ ],
'rootpage' => null,
- );
+ ];
}
public function needsToken() {
}
protected function getExamplesMessages() {
- return array(
+ return [
'action=import&interwikisource=meta&interwikipage=Help:ParserFunctions&' .
'namespace=100&fullhistory=&token=123ABC'
=> 'apihelp-import-example-import',
- );
+ ];
}
public function getHelpUrls() {
* @ingroup API
*/
class ApiImportReporter extends ImportReporter {
- private $mResultArr = array();
+ private $mResultArr = [];
/**
* @param Title $title
* @param array $pageInfo
* @return void
*/
- function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
+ public function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
// Add a result entry
- $r = array();
+ $r = [];
if ( $title === null ) {
# Invalid or non-importable title
parent::reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo );
}
- function getData() {
+ public function getData() {
return $this->mResultArr;
}
}