MediaWiki
REL1_24
|
00001 <?php 00030 class ApiQueryFileRepoInfo extends ApiQueryBase { 00031 00032 public function __construct( ApiQuery $query, $moduleName ) { 00033 parent::__construct( $query, $moduleName, 'fri' ); 00034 } 00035 00036 protected function getInitialisedRepoGroup() { 00037 $repoGroup = RepoGroup::singleton(); 00038 $repoGroup->initialiseRepos(); 00039 00040 return $repoGroup; 00041 } 00042 00043 public function execute() { 00044 $params = $this->extractRequestParams(); 00045 $props = array_flip( $params['prop'] ); 00046 00047 $repos = array(); 00048 00049 $repoGroup = $this->getInitialisedRepoGroup(); 00050 00051 $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$repos, $props ) { 00052 $repos[] = array_intersect_key( $repo->getInfo(), $props ); 00053 } ); 00054 00055 $repos[] = array_intersect_key( $repoGroup->getLocalRepo()->getInfo(), $props ); 00056 00057 $result = $this->getResult(); 00058 $result->setIndexedTagName( $repos, 'repo' ); 00059 $result->addValue( array( 'query' ), 'repos', $repos ); 00060 } 00061 00062 public function getCacheMode( $params ) { 00063 return 'public'; 00064 } 00065 00066 public function getAllowedParams() { 00067 $props = $this->getProps(); 00068 00069 return array( 00070 'prop' => array( 00071 ApiBase::PARAM_DFLT => join( '|', $props ), 00072 ApiBase::PARAM_ISMULTI => true, 00073 ApiBase::PARAM_TYPE => $props, 00074 ), 00075 ); 00076 } 00077 00078 public function getProps() { 00079 $props = array(); 00080 $repoGroup = $this->getInitialisedRepoGroup(); 00081 00082 $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$props ) { 00083 $props = array_merge( $props, array_keys( $repo->getInfo() ) ); 00084 } ); 00085 00086 return array_values( array_unique( array_merge( 00087 $props, 00088 array_keys( $repoGroup->getLocalRepo()->getInfo() ) 00089 ) ) ); 00090 } 00091 00092 public function getParamDescription() { 00093 return array( 00094 'prop' => array( 00095 'Which repository properties to get (there may be more available on some wikis):', 00096 ' apiurl - URL to the repository API - helpful for getting image info from the host.', 00097 ' name - The key of the repository - used in e.g. ' . 00098 '$wgForeignFileRepos and imageinfo return values.', 00099 ' displayname - The human-readable name of the repository wiki.', 00100 ' rooturl - Root URL for image paths.', 00101 ' local - Whether that repository is the local one or not.', 00102 ), 00103 ); 00104 } 00105 00106 public function getDescription() { 00107 return 'Return meta information about image repositories configured on the wiki.'; 00108 } 00109 00110 public function getExamples() { 00111 return array( 00112 'api.php?action=query&meta=filerepoinfo&friprop=apiurl|name|displayname', 00113 ); 00114 } 00115 }