Partial workaround for bug 6220: at least make files on shared repositories show...
[lhc/web/wiklou.git] / includes / DistributionRepository.php
1 <?php
2
3 /**
4 * File holding the DistributionRepository class.
5 *
6 * @file DistributionRepository.php
7 * @ingroup Deployment
8 *
9 * @author Jeroen De Dauw
10 */
11
12 if ( !defined( 'MEDIAWIKI' ) ) {
13 die( 'Not an entry point.' );
14 }
15
16 /**
17 * Repository class for interaction with repositories provided by
18 * the Distirbution extension and the MediaWiki API.
19 *
20 * @since 1.17
21 *
22 * @ingroup Deployment
23 *
24 * @author Jeroen De Dauw
25 */
26 class DistributionRepository extends PackageRepository {
27
28 /**
29 * Constructor.
30 *
31 * @param $location String: path to the api of the MediaWiki install providing the repository.
32 *
33 * @since 1.17
34 */
35 public function __construct( $location ) {
36 parent::__construct( $location );
37 }
38
39 /**
40 * @see PackageRepository::findExtenions
41 *
42 * @since 1.17
43 *
44 * @param $filterType String
45 * @param $filterValue String
46 *
47 * @return array
48 */
49 public function findExtenions( $filterType, $filterValue ) {
50 global $wgRepositoryPackageStates;
51
52 $filterType = urlencode( $filterType );
53 $filterValue = urlencode( $filterValue );
54 $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
55
56 $response = Http::get(
57 "$this->location?format=json&action=query&list=extensions&dstfilter=$filterType&dstvalue=$filterValue&dststate=$states",
58 'default',
59 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
60 );
61
62 $extensions = array();
63
64 if ( $response !== false ) {
65 $response = FormatJson::decode( $response );
66
67 if ( property_exists( $response, 'query' ) && property_exists( $response->query, 'extensions' ) ) {
68 $extensions = $response->query->extensions;
69 }
70 }
71
72 return $extensions;
73 }
74
75 /**
76 * @see PackageRepository::extensionHasUpdate
77 *
78 * @since 1.17
79 */
80 public function extensionHasUpdate( $extensionName, $currentVersion ) {
81 global $wgRepositoryPackageStates;
82
83 $extensionName = urlencode( $extensionName );
84 $currentVersion = urlencode( $currentVersion );
85 $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
86
87 $response = Http::get(
88 "$this->location?format=json&action=updates&extensions=$extensionName;$currentVersion&state=$states",
89 'default',
90 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
91 );
92
93 if ( $response === false ) {
94 return false;
95 }
96
97 $response = FormatJson::decode( $response );
98
99 if ( property_exists( $response, 'extensions' ) && property_exists( $response->extensions, $extensionName ) ) {
100 return $response->extensions->$extensionName;
101 }
102
103 return false;
104 }
105
106 /**
107 * @see PackageRepository::coreHasUpdate
108 *
109 * @since 1.17
110 */
111 public function coreHasUpdate( $currentVersion ) {
112 global $wgRepositoryPackageStates;
113
114 $currentVersion = urlencode( $currentVersion );
115 $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
116
117 $response = Http::get(
118 "$this->location?format=json&action=updates&mediawiki=$currentVersion&state=$states",
119 'default',
120 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
121 );
122
123 if ( $response === false ) {
124 return false;
125 }
126
127 $response = FormatJson::decode( $response );
128
129 if ( property_exists( $response, 'mediawiki' ) ) {
130 return $response->mediawiki;
131 }
132
133 return false;
134 }
135
136 /**
137 * @see PackageRepository::coreHasUpdate
138 *
139 * @since 1.17
140 */
141 public function getLatestCoreVersion() {
142 // TODO: use $states
143 //global $wgRepositoryPackageStates;
144 //$states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
145
146 $response = Http::get(
147 "$this->location?format=json&action=mwreleases",
148 'default',
149 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
150 );
151
152 if ( $response === false ) {
153 return false;
154 }
155
156 $response = FormatJson::decode( $response );
157
158 $current = false;
159
160 if ( property_exists( $response, 'mwreleases' ) ) {
161 foreach ( $response->mwreleases as $release ) {
162 if ( property_exists( $release, 'current' ) && property_exists( $release, 'version') ) {
163 $current = $release->version;
164 }
165 }
166 }
167
168 return $current;
169 }
170
171 /**
172 * @see PackageRepository::installationHasUpdates
173 *
174 * @since 1.17
175 */
176 public function installationHasUpdates( $coreVersion, array $extensions ) {
177 global $wgRepositoryPackageStates;
178
179 $coreVersion = urlencode( $coreVersion );
180 $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
181
182 $extensionParams = array();
183
184 if ( count( $extensions ) > 0 ) {
185 foreach ( $extensions as $extensionName => $extensionVersion ) {
186 $extensionParams[] = urlencode( $extensionName ) . ';' . urlencode( $extensionVersion );
187 }
188
189 $extensionParams = '&extensions=' . urlencode( implode( '|', $extensionParams ) );
190 }
191
192 $response = Http::get(
193 "$this->location?format=json&action=updates&mediawiki=$coreVersion{$extensionParams}&state=$states",
194 'default',
195 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
196 );
197
198 if ( $response === false ) {
199 return false;
200 }
201
202 $response = FormatJson::decode( $response );
203
204 $updates = array();
205
206 if ( property_exists( $response, 'mediawiki' ) ) {
207 $updates['MediaWiki'] = $response->mediawiki;
208 }
209
210 if ( property_exists( $response, 'extensions' ) ) {
211 foreach ( $extensions as $extensionName => $extensionVersion ) {
212 if ( property_exists( $response->extensions, $extensionName ) ) {
213 $updates[$extensionName] = $response->extensions->$extensionName;
214 }
215 }
216 }
217
218 return count( $updates ) > 0 ? $updates : false;
219 }
220
221 }