Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 54 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
ApiListExtDistBranches | |
0.00% |
0 / 54 |
|
0.00% |
0 / 8 |
272 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getProvider | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getCacheMode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
execute | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
getInfo | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
isInternal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAllowedParams | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
getExamplesMessages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\ExtensionDistributor\Api; |
4 | |
5 | use ApiBase; |
6 | use ApiQuery; |
7 | use ApiQueryBase; |
8 | use ApiResult; |
9 | use MediaWiki\Extension\ExtensionDistributor\Providers\ExtDistProvider; |
10 | use MediaWiki\Logger\LoggerFactory; |
11 | use Wikimedia\ParamValidator\ParamValidator; |
12 | |
13 | /** |
14 | * @author Legoktm |
15 | */ |
16 | class ApiListExtDistBranches extends ApiQueryBase { |
17 | |
18 | private $providers = []; |
19 | |
20 | public function __construct( ApiQuery $query, $moduleName ) { |
21 | parent::__construct( $query, $moduleName, 'edb' ); |
22 | } |
23 | |
24 | /** |
25 | * @param string $type |
26 | * @return ExtDistProvider |
27 | */ |
28 | protected function getProvider( $type ) { |
29 | if ( !isset( $this->providers[$type] ) ) { |
30 | $this->providers[$type] = ExtDistProvider::getProviderFor( $type ); |
31 | } |
32 | |
33 | return $this->providers[$type]; |
34 | } |
35 | |
36 | public function getCacheMode( $params ) { |
37 | return 'public'; |
38 | } |
39 | |
40 | public function execute() { |
41 | $logger = LoggerFactory::getInstance( 'ExtensionDistributor' ); |
42 | $extProvider = ExtDistProvider::getProviderFor( ExtDistProvider::EXTENSIONS ); |
43 | $extProvider->setLogger( $logger ); |
44 | $skinProvider = ExtDistProvider::getProviderFor( ExtDistProvider::SKINS ); |
45 | $skinProvider->setLogger( $logger ); |
46 | $info = []; |
47 | ApiResult::setArrayType( $info, 'assoc' ); |
48 | $params = $this->extractRequestParams(); |
49 | if ( $params['exts'] ) { |
50 | $info['extensions'] = $this->getInfo( $extProvider, $params['exts'] ); |
51 | } |
52 | if ( $params['skins'] ) { |
53 | $info['skins'] = $this->getInfo( $skinProvider, $params['skins'] ); |
54 | } |
55 | $this->getResult()->addValue( |
56 | 'query', |
57 | $this->getModuleName(), |
58 | $info |
59 | ); |
60 | } |
61 | |
62 | /** |
63 | * Get the info to output for a given provider |
64 | * |
65 | * @param ExtDistProvider $provider |
66 | * @param array $repos |
67 | * @return array |
68 | */ |
69 | private function getInfo( ExtDistProvider $provider, array $repos ) { |
70 | $out = []; |
71 | foreach ( $repos as $repo ) { |
72 | $out[$repo] = []; |
73 | $branches = $provider->getBranches( $repo ); |
74 | foreach ( $branches as $branch => $sha1 ) { |
75 | $out[$repo][$branch] = $provider->getTarballLocation( $repo, $branch ); |
76 | } |
77 | $source = $provider->getSourceURL( $repo ); |
78 | if ( $source !== false ) { |
79 | // As long as 'source' is never added to $wgExtDistSnapshotRefs, |
80 | // we'll be totally fine. |
81 | $out[$repo]['source'] = $source; |
82 | } |
83 | ApiResult::setArrayType( $out[$repo], 'assoc' ); |
84 | } |
85 | |
86 | return $out; |
87 | } |
88 | |
89 | public function isInternal() { |
90 | return true; |
91 | } |
92 | |
93 | public function getAllowedParams() { |
94 | $extensionsProvider = $this->getProvider( ExtDistProvider::EXTENSIONS ); |
95 | $skinsProvider = $this->getProvider( ExtDistProvider::SKINS ); |
96 | return [ |
97 | 'exts' => [ |
98 | ParamValidator::PARAM_ISMULTI => true, |
99 | ParamValidator::PARAM_TYPE => $extensionsProvider |
100 | ? $extensionsProvider->getRepositoryList() |
101 | : [], |
102 | ], |
103 | 'skins' => [ |
104 | ParamValidator::PARAM_ISMULTI => true, |
105 | ParamValidator::PARAM_TYPE => $skinsProvider |
106 | ? $skinsProvider->getRepositoryList() |
107 | : [], |
108 | ] |
109 | ]; |
110 | } |
111 | |
112 | /** |
113 | * @see ApiBase::getExamplesMessages() |
114 | * @return array |
115 | */ |
116 | protected function getExamplesMessages() { |
117 | return [ |
118 | 'action=query&list=extdistbranches&edbexts=ExtensionDistributor' |
119 | => 'apihelp-query+extdistbranches-example-1', |
120 | ]; |
121 | } |
122 | } |