MediaWiki REL1_37
ApiQueryFileRepoInfo.php
Go to the documentation of this file.
1<?php
31
33 private $repoGroup;
34
40 public function __construct(
41 ApiQuery $query,
42 $moduleName,
44 ) {
45 parent::__construct( $query, $moduleName, 'fri' );
46 $this->repoGroup = $repoGroup;
47 }
48
49 public function execute() {
50 $conf = $this->getConfig();
51
52 $params = $this->extractRequestParams();
53 $props = array_fill_keys( $params['prop'], true );
54
55 $repos = [];
56
57 $foreignTargets = $conf->get( 'ForeignUploadTargets' );
58
59 $this->repoGroup->forEachForeignRepo(
60 static function ( FileRepo $repo ) use ( &$repos, $props, $foreignTargets ) {
61 $repoProps = $repo->getInfo();
62 $repoProps['canUpload'] = in_array( $repoProps['name'], $foreignTargets );
63
64 $repos[] = array_intersect_key( $repoProps, $props );
65 }
66 );
67
68 $localInfo = $this->repoGroup->getLocalRepo()->getInfo();
69 $localInfo['canUpload'] = $conf->get( 'EnableUploads' );
70 $repos[] = array_intersect_key( $localInfo, $props );
71
72 $result = $this->getResult();
73 ApiResult::setIndexedTagName( $repos, 'repo' );
74 ApiResult::setArrayTypeRecursive( $repos, 'assoc' );
75 ApiResult::setArrayType( $repos, 'array' );
76 $result->addValue( [ 'query' ], 'repos', $repos );
77 }
78
79 public function getCacheMode( $params ) {
80 return 'public';
81 }
82
83 public function getAllowedParams() {
84 $props = $this->getProps();
85
86 return [
87 'prop' => [
88 ApiBase::PARAM_DFLT => implode( '|', $props ),
90 ApiBase::PARAM_TYPE => $props,
92 ],
93 ];
94 }
95
96 public function getProps() {
97 $props = [];
98 $this->repoGroup->forEachForeignRepo( static function ( FileRepo $repo ) use ( &$props ) {
99 $props = array_merge( $props, array_keys( $repo->getInfo() ) );
100 } );
101
102 $propValues = array_values( array_unique( array_merge(
103 $props,
104 array_keys( $this->repoGroup->getLocalRepo()->getInfo() )
105 ) ) );
106
107 $propValues[] = 'canUpload';
108
109 sort( $propValues );
110 return $propValues;
111 }
112
113 protected function getExamplesMessages() {
114 $examples = [];
115
116 $props = array_intersect( [ 'apiurl', 'name', 'displayname' ], $this->getProps() );
117 if ( $props ) {
118 $examples['action=query&meta=filerepoinfo&friprop=' . implode( '|', $props )] =
119 'apihelp-query+filerepoinfo-example-simple';
120 }
121
122 return $examples;
123 }
124
125 public function getHelpUrls() {
126 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Filerepoinfo';
127 }
128}
const PARAM_TYPE
Definition ApiBase.php:81
const PARAM_DFLT
Definition ApiBase.php:73
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
Definition ApiBase.php:195
getResult()
Get the result object.
Definition ApiBase.php:628
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
Definition ApiBase.php:764
const PARAM_ISMULTI
Definition ApiBase.php:77
This is a base class for all Query modules.
A query action to return meta information about the foreign file repos configured on the wiki.
__construct(ApiQuery $query, $moduleName, RepoGroup $repoGroup)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getExamplesMessages()
Returns usage examples for this module.
getHelpUrls()
Return links to more detailed help pages about the module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
This is the main query class.
Definition ApiQuery.php:37
Base class for file repositories.
Definition FileRepo.php:45
getInfo()
Return information about the repository.
Prioritized list of file repositories.
Definition RepoGroup.php:33