197e64030bf95a534972afa0a8ac1fe26b5efab6
[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 0.1
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 0.1
34 */
35 public function __construct( $location ) {
36 parent::__construct( $location );
37 }
38
39 /**
40 * @see PackageRepository::findExtenions
41 *
42 * @since 0.1
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 0.1
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 0.1
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::installationHasUpdates
138 *
139 * @since 0.1
140 */
141 public function installationHasUpdates( $coreVersion, array $extensions ) {
142 global $wgRepositoryPackageStates;
143
144 $coreVersion = urlencode( $coreVersion );
145 $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
146
147 $extensionParams = array();
148
149 if ( count( $extensions ) > 0 ) {
150 foreach ( $extensions as $extensionName => $extensionVersion ) {
151 $extensionParams[] = urlencode( $extensionName ) . ';' . urlencode( $extensionVersion );
152 }
153
154 $extensionParams = '&extensions=' . urlencode( implode( '|', $extensionParams ) );
155 }
156
157 $response = Http::get(
158 "$this->location?format=json&action=updates&mediawiki=$coreVersion{$extensionParams}&state=$states",
159 'default',
160 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
161 );
162
163 if ( $response === false ) {
164 return false;
165 }
166
167 $response = FormatJson::decode( $response );
168
169 $updates = array();
170
171 if ( property_exists( $response, 'mediawiki' ) ) {
172 $updates['MediaWiki'] = $response->mediawiki;
173 }
174
175 if ( property_exists( $response, 'extensions' ) ) {
176 foreach ( $extensions as $extensionName => $extensionVersion ) {
177 if ( property_exists( $response->extensions, $extensionName ) ) {
178 $updates[$extensionName] = $response->extensions->$extensionName;
179 }
180 }
181 }
182
183 return count( $updates ) > 0 ? $updates : false;
184 }
185
186 }