MediaWiki
REL1_22
|
00001 <?php 00030 class ApiQueryFileRepoInfo extends ApiQueryBase { 00031 00032 public function __construct( $query, $moduleName ) { 00033 parent::__construct( $query, $moduleName, 'fri' ); 00034 } 00035 00036 protected function getInitialisedRepoGroup() { 00037 $repoGroup = RepoGroup::singleton(); 00038 00039 if ( !$repoGroup->reposInitialised ) { 00040 $repoGroup->initialiseRepos(); 00041 } 00042 00043 return $repoGroup; 00044 } 00045 00046 public function execute() { 00047 $params = $this->extractRequestParams(); 00048 $props = array_flip( $params['prop'] ); 00049 00050 $repos = array(); 00051 00052 $repoGroup = $this->getInitialisedRepoGroup(); 00053 00054 $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$repos, $props ) { 00055 $repos[] = array_intersect_key( $repo->getInfo(), $props ); 00056 } ); 00057 00058 $repos[] = array_intersect_key( $repoGroup->localRepo->getInfo(), $props ); 00059 00060 $result = $this->getResult(); 00061 $result->setIndexedTagName( $repos, 'repo' ); 00062 $result->addValue( array( 'query' ), 'repos', $repos ); 00063 } 00064 00065 public function getCacheMode( $params ) { 00066 return 'public'; 00067 } 00068 00069 public function getAllowedParams() { 00070 $props = $this->getProps(); 00071 00072 return array( 00073 'prop' => array( 00074 ApiBase::PARAM_DFLT => join( '|', $props ), 00075 ApiBase::PARAM_ISMULTI => true, 00076 ApiBase::PARAM_TYPE => $props, 00077 ), 00078 ); 00079 } 00080 00081 public function getProps() { 00082 $props = array(); 00083 $repoGroup = $this->getInitialisedRepoGroup(); 00084 00085 $repoGroup->forEachForeignRepo( function ( $repo ) use ( &$props ) { 00086 $props = array_merge( $props, array_keys( $repo->getInfo() ) ); 00087 } ); 00088 00089 return array_values( array_unique( array_merge( $props, array_keys( $repoGroup->localRepo->getInfo() ) ) ) ); 00090 } 00091 00092 public function getParamDescription() { 00093 $p = $this->getModulePrefix(); 00094 return array( 00095 'prop' => array( 00096 'Which repository properties to get (there may be more available on some wikis):', 00097 ' apiurl - URL to the repository API - helpful for getting image info from the host.', 00098 ' name - The key of the repository - used in e.g. $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 }