Merge "Avoid master queries in Title::getLinksFrom()"
[lhc/web/wiklou.git] / includes / api / ApiImport.php
index 735cc7f..8574dce 100644 (file)
@@ -45,7 +45,7 @@ class ApiImport extends ApiBase {
                                $this->dieUsageMsg( 'cantimport' );
                        }
                        if ( !isset( $params['interwikipage'] ) ) {
-                               $this->dieUsageMsg( array( 'missingparam', 'interwikipage' ) );
+                               $this->dieUsageMsg( [ 'missingparam', 'interwikipage' ] );
                        }
                        $source = ImportStreamSource::newFromInterwiki(
                                $params['interwikisource'],
@@ -83,7 +83,7 @@ class ApiImport extends ApiBase {
                try {
                        $importer->doImport();
                } catch ( Exception $e ) {
-                       $this->dieUsageMsg( array( 'import-unknownerror', $e->getMessage() ) );
+                       $this->dieUsageMsg( [ 'import-unknownerror', $e->getMessage() ] );
                }
 
                $resultData = $reporter->getData();
@@ -92,6 +92,30 @@ class ApiImport extends ApiBase {
                $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;
        }
@@ -101,22 +125,22 @@ class ApiImport extends ApiBase {
        }
 
        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() {
@@ -124,11 +148,11 @@ class ApiImport extends ApiBase {
        }
 
        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() {
@@ -141,7 +165,7 @@ class ApiImport extends ApiBase {
  * @ingroup API
  */
 class ApiImportReporter extends ImportReporter {
-       private $mResultArr = array();
+       private $mResultArr = [];
 
        /**
         * @param Title $title
@@ -153,7 +177,7 @@ class ApiImportReporter extends ImportReporter {
         */
        function reportPage( $title, $origTitle, $revisionCount, $successCount, $pageInfo ) {
                // Add a result entry
-               $r = array();
+               $r = [];
 
                if ( $title === null ) {
                        # Invalid or non-importable title