X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryFileRepoInfo.php;h=279bc0a2f3eb2cd2277ffa37fea896f2ac302097;hb=d72f24589b3eece35b334d080e6e609b048fc22f;hp=057b011790ba1ca0a0e9651314b0019a67fe57b6;hpb=3368cccde53732c1278f51632e69b9865c4ee6ba;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryFileRepoInfo.php b/includes/api/ApiQueryFileRepoInfo.php index 057b011790..279bc0a2f3 100644 --- a/includes/api/ApiQueryFileRepoInfo.php +++ b/includes/api/ApiQueryFileRepoInfo.php @@ -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'; } }