Tweaked TempFSFile::bind() param type docs
[lhc/web/wiklou.git] / includes / api / ApiQueryFileRepoInfo.php
1 <?php
2 /**
3 * Copyright © 2013 Mark Holmquist <mtraceur@member.fsf.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @since 1.22
22 */
23
24 /**
25 * A query action to return meta information about the foreign file repos
26 * configured on the wiki.
27 *
28 * @ingroup API
29 */
30 class ApiQueryFileRepoInfo extends ApiQueryBase {
31
32 public function __construct( ApiQuery $query, $moduleName ) {
33 parent::__construct( $query, $moduleName, 'fri' );
34 }
35
36 protected function getInitialisedRepoGroup() {
37 $repoGroup = RepoGroup::singleton();
38 $repoGroup->initialiseRepos();
39
40 return $repoGroup;
41 }
42
43 public function execute() {
44 $params = $this->extractRequestParams();
45 $props = array_flip( $params['prop'] );
46
47 $repos = array();
48
49 $repoGroup = $this->getInitialisedRepoGroup();
50
51 $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$repos, $props ) {
52 $repos[] = array_intersect_key( $repo->getInfo(), $props );
53 } );
54
55 $repos[] = array_intersect_key( $repoGroup->getLocalRepo()->getInfo(), $props );
56
57 $result = $this->getResult();
58 ApiResult::setIndexedTagName( $repos, 'repo' );
59 ApiResult::setArrayTypeRecursive( $repos, 'assoc' );
60 ApiResult::setArrayType( $repos, 'array' );
61 $result->addValue( array( 'query' ), 'repos', $repos );
62 }
63
64 public function getCacheMode( $params ) {
65 return 'public';
66 }
67
68 public function getAllowedParams() {
69 $props = $this->getProps();
70
71 return array(
72 'prop' => array(
73 ApiBase::PARAM_DFLT => join( '|', $props ),
74 ApiBase::PARAM_ISMULTI => true,
75 ApiBase::PARAM_TYPE => $props,
76 ),
77 );
78 }
79
80 public function getProps() {
81 $props = array();
82 $repoGroup = $this->getInitialisedRepoGroup();
83
84 $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$props ) {
85 $props = array_merge( $props, array_keys( $repo->getInfo() ) );
86 } );
87
88 return array_values( array_unique( array_merge(
89 $props,
90 array_keys( $repoGroup->getLocalRepo()->getInfo() )
91 ) ) );
92 }
93
94 protected function getExamplesMessages() {
95 return array(
96 'action=query&meta=filerepoinfo&friprop=apiurl|name|displayname'
97 => 'apihelp-query+filerepoinfo-example-simple',
98 );
99 }
100 }