From fe6cffe9073207cff5c5d7aafb5a3ab738999c9d Mon Sep 17 00:00:00 2001 From: Jeroen De Dauw Date: Sun, 15 Aug 2010 10:51:24 +0000 Subject: [PATCH] Modified the environment check of the core installer to check the current MediaWiki version to work with the new repository classes. --- includes/DistributionRepository.php | 39 ++++++++++++++++++++++++++++- includes/PackageRepository.php | 9 +++++++ includes/installer/Installer.php | 17 +++++-------- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/includes/DistributionRepository.php b/includes/DistributionRepository.php index cd06948223..f9e255f37a 100644 --- a/includes/DistributionRepository.php +++ b/includes/DistributionRepository.php @@ -112,7 +112,7 @@ class DistributionRepository extends PackageRepository { global $wgRepositoryPackageStates; $currentVersion = urlencode( $currentVersion ); - $states = urlencode( implode( '|', $wgRepositoryPackageStates ) ); + $states = urlencode( implode( '|', $wgRepositoryPackageStates ) ); $response = Http::get( "$this->location?format=json&action=updates&mediawiki=$currentVersion&state=$states", @@ -133,6 +133,43 @@ class DistributionRepository extends PackageRepository { return false; } + /** + * @see PackageRepository::coreHasUpdate + * + * @since 1.17 + */ + public function getLatestCoreVersion() { + global $wgRepositoryPackageStates; + + $states = urlencode( implode( '|', $wgRepositoryPackageStates ) ); + + // TODO: use $states + + $response = Http::get( + "$this->location?format=json&action=mwreleases", + 'default', + array( 'sslVerifyHost' => true, 'sslVerifyCert' => true ) + ); + + if ( $response === false ) { + return false; + } + + $response = FormatJson::decode( $response ); + + $current = false; + + if ( property_exists( $response, 'mwreleases' ) ) { + foreach ( $response->mwreleases as $release ) { + if ( property_exists( $release, 'current' ) && property_exists( $release, 'version') ) { + $current = $release->version; + } + } + } + + return $current; + } + /** * @see PackageRepository::installationHasUpdates * diff --git a/includes/PackageRepository.php b/includes/PackageRepository.php index fb21ad199f..e05235cf3b 100644 --- a/includes/PackageRepository.php +++ b/includes/PackageRepository.php @@ -69,6 +69,15 @@ abstract class PackageRepository { */ public abstract function coreHasUpdate( $currentVersion ); + /** + * Returns the latest MediaWiki release, or false when the request fails. + * + * @since 1.17 + * + * @return Mixed: string or false + */ + public abstract function getLatestCoreVersion(); + /** * Checks if there are any updates for this MediaWiki installation and extensions. * diff --git a/includes/installer/Installer.php b/includes/installer/Installer.php index 827a8232b8..3d82dddc60 100644 --- a/includes/installer/Installer.php +++ b/includes/installer/Installer.php @@ -383,30 +383,25 @@ abstract class Installer { public function envLatestVersion() { global $wgVersion; - $latestInfoUrl = 'http://www.mediawiki.org/w/api.php?action=mwreleases&format=json'; - $latestInfo = Http::get( $latestInfoUrl ); - + $repository = wfGetRepository(); + $currentVersion = $repository->getLatestCoreVersion(); + + /* if( !$latestInfo ) { $this->showMessage( 'config-env-latest-can-not-check', $latestInfoUrl ); return; } + */ $this->setVar( '_ExternalHTTP', true ); - $latestInfo = FormatJson::decode($latestInfo); - if ($latestInfo === false || !isset( $latestInfo->mwreleases ) ) { + if ( $currentVersion === false ) { # For when the request is successful but there's e.g. some silly man in # the middle firewall blocking us, e.g. one of those annoying airport ones $this->showMessage( 'config-env-latest-data-invalid', $latestInfoUrl ); return; } - foreach( $latestInfo->mwreleases as $rel ) { - if( isset( $rel->current ) ) { - $currentVersion = $rel->version; - } - } - if( version_compare( $wgVersion, $currentVersion, '<' ) ) { $this->showMessage( 'config-env-latest-old' ); $this->showHelpBox( 'config-env-latest-help', $wgVersion, $currentVersion ); -- 2.20.1