Localisation updates for core and extension messages from translatewiki.net (2010...
[mediawiki.git] / includes / DistributionRepository.php
blob8aabb5116550ac2fb81efa491b0af570d9ca5e75
1 <?php
3 /**
4 * File holding the DistributionRepository class.
6 * @file DistributionRepository.php
7 * @ingroup Deployment
9 * @author Jeroen De Dauw
12 if ( !defined( 'MEDIAWIKI' ) ) {
13 die( 'Not an entry point.' );
16 /**
17 * Repository class for interaction with repositories provided by
18 * the Distirbution extension and the MediaWiki API.
20 * @since 1.17
22 * @ingroup Deployment
24 * @author Jeroen De Dauw
26 class DistributionRepository extends PackageRepository {
28 /**
29 * Constructor.
31 * @param $location String: path to the api of the MediaWiki install providing the repository.
33 * @since 1.17
35 public function __construct( $location ) {
36 parent::__construct( $location );
39 /**
40 * @see PackageRepository::findExtenions
42 * @since 1.17
44 * @param $filterType String
45 * @param $filterValue String
47 * @return array
48 */
49 public function findExtenions( $filterType, $filterValue ) {
50 global $wgRepositoryPackageStates;
52 $filterType = urlencode( $filterType );
53 $filterValue = urlencode( $filterValue );
54 $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
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 )
62 $extensions = array();
64 if ( $response !== false ) {
65 $response = FormatJson::decode( $response );
67 if ( property_exists( $response, 'query' ) && property_exists( $response->query, 'extensions' ) ) {
68 $extensions = $response->query->extensions;
72 return $extensions;
75 /**
76 * @see PackageRepository::extensionHasUpdate
78 * @since 1.17
79 */
80 public function extensionHasUpdate( $extensionName, $currentVersion ) {
81 global $wgRepositoryPackageStates;
83 $extensionName = urlencode( $extensionName );
84 $currentVersion = urlencode( $currentVersion );
85 $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
87 $response = Http::get(
88 "$this->location?format=json&action=updates&extensions=$extensionName;$currentVersion&state=$states",
89 'default',
90 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
93 if ( $response === false ) {
94 return false;
97 $response = FormatJson::decode( $response );
99 if ( property_exists( $response, 'extensions' ) && property_exists( $response->extensions, $extensionName ) ) {
100 return $response->extensions->$extensionName;
103 return false;
107 * @see PackageRepository::coreHasUpdate
109 * @since 1.17
111 public function coreHasUpdate( $currentVersion ) {
112 global $wgRepositoryPackageStates;
114 $currentVersion = urlencode( $currentVersion );
115 $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
117 $response = Http::get(
118 "$this->location?format=json&action=updates&mediawiki=$currentVersion&state=$states",
119 'default',
120 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
123 if ( $response === false ) {
124 return false;
127 $response = FormatJson::decode( $response );
129 if ( property_exists( $response, 'mediawiki' ) ) {
130 return $response->mediawiki;
133 return false;
137 * @see PackageRepository::coreHasUpdate
139 * @since 1.17
141 public function getLatestCoreVersion() {
142 // TODO: use $states
143 //global $wgRepositoryPackageStates;
144 //$states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
146 $response = Http::get(
147 "$this->location?format=json&action=mwreleases",
148 'default',
149 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
152 if ( $response === false ) {
153 return false;
156 $response = FormatJson::decode( $response );
158 $current = false;
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;
168 return $current;
172 * @see PackageRepository::installationHasUpdates
174 * @since 1.17
176 public function installationHasUpdates( $coreVersion, array $extensions ) {
177 global $wgRepositoryPackageStates;
179 $coreVersion = urlencode( $coreVersion );
180 $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
182 $extensionParams = array();
184 if ( count( $extensions ) > 0 ) {
185 foreach ( $extensions as $extensionName => $extensionVersion ) {
186 $extensionParams[] = urlencode( $extensionName ) . ';' . urlencode( $extensionVersion );
189 $extensionParams = '&extensions=' . urlencode( implode( '|', $extensionParams ) );
192 $response = Http::get(
193 "$this->location?format=json&action=updates&mediawiki=$coreVersion{$extensionParams}&state=$states",
194 'default',
195 array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
198 if ( $response === false ) {
199 return false;
202 $response = FormatJson::decode( $response );
204 $updates = array();
206 if ( property_exists( $response, 'mediawiki' ) ) {
207 $updates['MediaWiki'] = $response->mediawiki;
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;
218 return count( $updates ) > 0 ? $updates : false;