3 * Copyright © 2013 Mark Holmquist <mtraceur@member.fsf.org>
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.
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.
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
25 * A query action to return meta information about the foreign file repos
26 * configured on the wiki.
30 class ApiQueryFileRepoInfo
extends ApiQueryBase
{
32 public function __construct( $query, $moduleName ) {
33 parent
::__construct( $query, $moduleName, 'fri' );
36 protected function getInitialisedRepoGroup() {
37 $repoGroup = RepoGroup
::singleton();
39 if ( !$repoGroup->reposInitialised
) {
40 $repoGroup->initialiseRepos();
46 public function execute() {
47 $params = $this->extractRequestParams();
48 $props = array_flip( $params['prop'] );
52 $repoGroup = $this->getInitialisedRepoGroup();
54 $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$repos, $props ) {
55 $repos[] = array_intersect_key( $repo->getInfo(), $props );
58 $repos[] = array_intersect_key( $repoGroup->localRepo
->getInfo(), $props );
60 $result = $this->getResult();
61 $result->setIndexedTagName( $repos, 'repo' );
62 $result->addValue( array( 'query' ), 'repos', $repos );
65 public function getCacheMode( $params ) {
69 public function getAllowedParams() {
70 $props = $this->getProps();
74 ApiBase
::PARAM_DFLT
=> join( '|', $props ),
75 ApiBase
::PARAM_ISMULTI
=> true,
76 ApiBase
::PARAM_TYPE
=> $props,
81 public function getProps() {
83 $repoGroup = $this->getInitialisedRepoGroup();
85 $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$props ) {
86 $props = array_merge( $props, array_keys( $repo->getInfo() ) );
89 return array_values( array_unique( array_merge(
91 array_keys( $repoGroup->localRepo
->getInfo() )
95 public function getParamDescription() {
96 $p = $this->getModulePrefix();
100 'Which repository properties to get (there may be more available on some wikis):',
101 ' apiurl - URL to the repository API - helpful for getting image info from the host.',
102 ' name - The key of the repository - used in e.g. ' .
103 '$wgForeignFileRepos and imageinfo return values.',
104 ' displayname - The human-readable name of the repository wiki.',
105 ' rooturl - Root URL for image paths.',
106 ' local - Whether that repository is the local one or not.',
111 public function getDescription() {
112 return 'Return meta information about image repositories configured on the wiki.';
115 public function getExamples() {
117 'api.php?action=query&meta=filerepoinfo&friprop=apiurl|name|displayname',