Modified the environment check of the core installer to check the current MediaWiki...
authorJeroen De Dauw <jeroendedauw@users.mediawiki.org>
Sun, 15 Aug 2010 10:51:24 +0000 (10:51 +0000)
committerJeroen De Dauw <jeroendedauw@users.mediawiki.org>
Sun, 15 Aug 2010 10:51:24 +0000 (10:51 +0000)
includes/DistributionRepository.php
includes/PackageRepository.php
includes/installer/Installer.php

index cd06948..f9e255f 100644 (file)
@@ -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
         * 
index fb21ad1..e05235c 100644 (file)
@@ -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.
         * 
index 827a823..3d82ddd 100644 (file)
@@ -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 );