Merge "Pass in ServiceOptions to BlockManager"
[lhc/web/wiklou.git] / includes / api / ApiQueryFileRepoInfo.php
index 057b011..279bc0a 100644 (file)
@@ -41,24 +41,32 @@ class ApiQueryFileRepoInfo extends ApiQueryBase {
        }
 
        public function execute() {
+               $conf = $this->getConfig();
+
                $params = $this->extractRequestParams();
                $props = array_flip( $params['prop'] );
 
-               $repos = array();
+               $repos = [];
 
                $repoGroup = $this->getInitialisedRepoGroup();
+               $foreignTargets = $conf->get( 'ForeignUploadTargets' );
+
+               $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$repos, $props, $foreignTargets ) {
+                       $repoProps = $repo->getInfo();
+                       $repoProps['canUpload'] = in_array( $repoProps['name'], $foreignTargets );
 
-               $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$repos, $props ) {
-                       $repos[] = array_intersect_key( $repo->getInfo(), $props );
+                       $repos[] = array_intersect_key( $repoProps, $props );
                } );
 
-               $repos[] = array_intersect_key( $repoGroup->getLocalRepo()->getInfo(), $props );
+               $localInfo = $repoGroup->getLocalRepo()->getInfo();
+               $localInfo['canUpload'] = $conf->get( 'EnableUploads' );
+               $repos[] = array_intersect_key( $localInfo, $props );
 
                $result = $this->getResult();
                ApiResult::setIndexedTagName( $repos, 'repo' );
                ApiResult::setArrayTypeRecursive( $repos, 'assoc' );
                ApiResult::setArrayType( $repos, 'array' );
-               $result->addValue( array( 'query' ), 'repos', $repos );
+               $result->addValue( [ 'query' ], 'repos', $repos );
        }
 
        public function getCacheMode( $params ) {
@@ -68,37 +76,48 @@ class ApiQueryFileRepoInfo extends ApiQueryBase {
        public function getAllowedParams() {
                $props = $this->getProps();
 
-               return array(
-                       'prop' => array(
-                               ApiBase::PARAM_DFLT => join( '|', $props ),
+               return [
+                       'prop' => [
+                               ApiBase::PARAM_DFLT => implode( '|', $props ),
                                ApiBase::PARAM_ISMULTI => true,
                                ApiBase::PARAM_TYPE => $props,
-                       ),
-               );
+                               ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
+                       ],
+               ];
        }
 
        public function getProps() {
-               $props = array();
+               $props = [];
                $repoGroup = $this->getInitialisedRepoGroup();
 
                $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$props ) {
                        $props = array_merge( $props, array_keys( $repo->getInfo() ) );
                } );
 
-               return array_values( array_unique( array_merge(
+               $propValues = array_values( array_unique( array_merge(
                        $props,
                        array_keys( $repoGroup->getLocalRepo()->getInfo() )
                ) ) );
+
+               $propValues[] = 'canUpload';
+
+               sort( $propValues );
+               return $propValues;
        }
 
        protected function getExamplesMessages() {
-               return array(
-                       'action=query&meta=filerepoinfo&friprop=apiurl|name|displayname'
-                               => 'apihelp-query+filerepoinfo-example-simple',
-               );
+               $examples = [];
+
+               $props = array_intersect( [ 'apiurl', 'name', 'displayname' ], $this->getProps() );
+               if ( $props ) {
+                       $examples['action=query&meta=filerepoinfo&friprop=' . implode( '|', $props )] =
+                               'apihelp-query+filerepoinfo-example-simple';
+               }
+
+               return $examples;
        }
 
        public function getHelpUrls() {
-               return 'https://www.mediawiki.org/wiki/API:Filerepoinfo';
+               return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Filerepoinfo';
        }
 }