[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Copyright © 2013 Mark Holmquist <[email protected]> 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 $result->setIndexedTagName( $repos, 'repo' ); 59 $result->addValue( array( 'query' ), 'repos', $repos ); 60 } 61 62 public function getCacheMode( $params ) { 63 return 'public'; 64 } 65 66 public function getAllowedParams() { 67 $props = $this->getProps(); 68 69 return array( 70 'prop' => array( 71 ApiBase::PARAM_DFLT => join( '|', $props ), 72 ApiBase::PARAM_ISMULTI => true, 73 ApiBase::PARAM_TYPE => $props, 74 ), 75 ); 76 } 77 78 public function getProps() { 79 $props = array(); 80 $repoGroup = $this->getInitialisedRepoGroup(); 81 82 $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$props ) { 83 $props = array_merge( $props, array_keys( $repo->getInfo() ) ); 84 } ); 85 86 return array_values( array_unique( array_merge( 87 $props, 88 array_keys( $repoGroup->getLocalRepo()->getInfo() ) 89 ) ) ); 90 } 91 92 public function getParamDescription() { 93 return array( 94 'prop' => array( 95 'Which repository properties to get (there may be more available on some wikis):', 96 ' apiurl - URL to the repository API - helpful for getting image info from the host.', 97 ' name - The key of the repository - used in e.g. ' . 98 '$wgForeignFileRepos and imageinfo return values.', 99 ' displayname - The human-readable name of the repository wiki.', 100 ' rooturl - Root URL for image paths.', 101 ' local - Whether that repository is the local one or not.', 102 ), 103 ); 104 } 105 106 public function getDescription() { 107 return 'Return meta information about image repositories configured on the wiki.'; 108 } 109 110 public function getExamples() { 111 return array( 112 'api.php?action=query&meta=filerepoinfo&friprop=apiurl|name|displayname', 113 ); 114 } 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |