http://www.mediawiki.org/wiki/Special:Code/MediaWiki/71107
Revision: 71107 Author: jeroendedauw Date: 2010-08-15 09:40:16 +0000 (Sun, 15 Aug 2010) Log Message: ----------- Moved in repository interaction classes from Deployment so it's possible to use them in the new installer for update detection Modified Paths: -------------- trunk/phase3/includes/AutoLoader.php Added Paths: ----------- trunk/phase3/includes/DistributionRepository.php trunk/phase3/includes/PackageRepository.php Modified: trunk/phase3/includes/AutoLoader.php =================================================================== --- trunk/phase3/includes/AutoLoader.php 2010-08-15 09:28:26 UTC (rev 71106) +++ trunk/phase3/includes/AutoLoader.php 2010-08-15 09:40:16 UTC (rev 71107) @@ -55,6 +55,7 @@ 'DBABagOStuff' => 'includes/BagOStuff.php', 'DependencyWrapper' => 'includes/CacheDependency.php', 'DiffHistoryBlob' => 'includes/HistoryBlob.php', + 'DistributionRepository' => 'includes/DistributionRepository.php', 'DjVuImage' => 'includes/DjVuImage.php', 'DoubleReplacer' => 'includes/StringUtils.php', 'DublinCoreRdf' => 'includes/Metadata.php', @@ -168,6 +169,7 @@ 'MWNamespace' => 'includes/Namespace.php', 'OldChangesList' => 'includes/ChangesList.php', 'OutputPage' => 'includes/OutputPage.php', + 'PackageRepository' => 'includes/PackageRepository.php', 'PageQueryPage' => 'includes/PageQueryPage.php', 'PageHistory' => 'includes/HistoryPage.php', 'PageHistoryPager' => 'includes/HistoryPage.php', Added: trunk/phase3/includes/DistributionRepository.php =================================================================== --- trunk/phase3/includes/DistributionRepository.php (rev 0) +++ trunk/phase3/includes/DistributionRepository.php 2010-08-15 09:40:16 UTC (rev 71107) @@ -0,0 +1,186 @@ +<?php + +/** + * File holding the DistributionRepository class. + * + * @file DistributionRepository.php + * @ingroup Deployment + * + * @author Jeroen De Dauw + */ + +if ( !defined( 'MEDIAWIKI' ) ) { + die( 'Not an entry point.' ); +} + +/** + * Repository class for interaction with repositories provided by + * the Distirbution extension and the MediaWiki API. + * + * @since 0.1 + * + * @ingroup Deployment + * + * @author Jeroen De Dauw + */ +class DistributionRepository extends PackageRepository { + + /** + * Constructor. + * + * @param $location String: path to the api of the MediaWiki install providing the repository. + * + * @since 0.1 + */ + public function __construct( $location ) { + parent::__construct( $location ); + } + + /** + * @see PackageRepository::findExtenions + * + * @since 0.1 + * + * @param $filterType String + * @param $filterValue String + * + * @return array + */ + public function findExtenions( $filterType, $filterValue ) { + global $wgRepositoryPackageStates; + + $filterType = urlencode( $filterType ); + $filterValue = urlencode( $filterValue ); + $states = urlencode( implode( '|', $wgRepositoryPackageStates ) ); + + $response = Http::get( + "$this->location?format=json&action=query&list=extensions&dstfilter=$filterType&dstvalue=$filterValue&dststate=$states", + 'default', + array( 'sslVerifyHost' => true, 'sslVerifyCert' => true ) + ); + + $extensions = array(); + + if ( $response !== false ) { + $response = FormatJson::decode( $response ); + + if ( property_exists( $response, 'query' ) && property_exists( $response->query, 'extensions' ) ) { + $extensions = $response->query->extensions; + } + } + + return $extensions; + } + + /** + * @see PackageRepository::extensionHasUpdate + * + * @since 0.1 + */ + public function extensionHasUpdate( $extensionName, $currentVersion ) { + global $wgRepositoryPackageStates; + + $extensionName = urlencode( $extensionName ); + $currentVersion = urlencode( $currentVersion ); + $states = urlencode( implode( '|', $wgRepositoryPackageStates ) ); + + $response = Http::get( + "$this->location?format=json&action=updates&extensions=$extensionName;$currentVersion&state=$states", + 'default', + array( 'sslVerifyHost' => true, 'sslVerifyCert' => true ) + ); + + if ( $response === false ) { + return false; + } + + $response = FormatJson::decode( $response ); + + if ( property_exists( $response, 'extensions' ) && property_exists( $response->extensions, $extensionName ) ) { + return $response->extensions->$extensionName; + } + + return false; + } + + /** + * @see PackageRepository::coreHasUpdate + * + * @since 0.1 + */ + public function coreHasUpdate( $currentVersion ) { + global $wgRepositoryPackageStates; + + $currentVersion = urlencode( $currentVersion ); + $states = urlencode( implode( '|', $wgRepositoryPackageStates ) ); + + $response = Http::get( + "$this->location?format=json&action=updates&mediawiki=$currentVersion&state=$states", + 'default', + array( 'sslVerifyHost' => true, 'sslVerifyCert' => true ) + ); + + if ( $response === false ) { + return false; + } + + $response = FormatJson::decode( $response ); + + if ( property_exists( $response, 'mediawiki' ) ) { + return $response->mediawiki; + } + + return false; + } + + /** + * @see PackageRepository::installationHasUpdates + * + * @since 0.1 + */ + public function installationHasUpdates( $coreVersion, array $extensions ) { + global $wgRepositoryPackageStates; + + $coreVersion = urlencode( $coreVersion ); + $states = urlencode( implode( '|', $wgRepositoryPackageStates ) ); + + $extensionParams = array(); + + if ( count( $extensions ) > 0 ) { + foreach ( $extensions as $extensionName => $extensionVersion ) { + $extensionParams[] = urlencode( $extensionName ) . ';' . urlencode( $extensionVersion ); + } + + $extensionParams = '&extensions=' . urlencode( implode( '|', $extensionParams ) ); + } + + $response = Http::get( + "$this->location?format=json&action=updates&mediawiki=$coreVersion{$extensionParams}&state=$states", + 'default', + array( 'sslVerifyHost' => true, 'sslVerifyCert' => true ) + ); + + if ( $response === false ) { + return false; + } + + $response = FormatJson::decode( $response ); + + $updates = array(); + + if ( property_exists( $response, 'mediawiki' ) ) { + $updates['MediaWiki'] = $response->mediawiki; + } + + if ( property_exists( $response, 'extensions' ) ) { + foreach ( $extensions as $extensionName => $extensionVersion ) { + if ( property_exists( $response->extensions, $extensionName ) ) { + $updates[$extensionName] = $response->extensions->$extensionName; + } + } + } + + return count( $updates ) > 0 ? $updates : false; + } + +} \ No newline at end of file Property changes on: trunk/phase3/includes/DistributionRepository.php ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/phase3/includes/PackageRepository.php =================================================================== --- trunk/phase3/includes/PackageRepository.php (rev 0) +++ trunk/phase3/includes/PackageRepository.php 2010-08-15 09:40:16 UTC (rev 71107) @@ -0,0 +1,95 @@ +<?php + +/** + * File holding the PackageRepository class. + * + * @file PackageRepository.php + * @ingroup Deployment + * + * @author Jeroen De Dauw + */ + +if ( !defined( 'MEDIAWIKI' ) ) { + die( 'Not an entry point.' ); +} + +/** + * Base repository class. Deriving classes handle interaction with + * package repositories of the type they support. + * + * @since 0.1 + * + * @ingroup Deployment + * + * @author Jeroen De Dauw + */ +abstract class PackageRepository { + + /** + * Base location of the repository. + * + * @since 0.1 + * + * @var string + */ + protected $location; + + /** + * Returns a list of extensions matching the search criteria. + * + * @since 0.1 + * + * @param $filterType String + * @param $filterValue String + * + * @return array + */ + public abstract function findExtenions( $filterType, $filterValue ); + + /** + * Checks if newer versions of an extension are available. + * + * @since 0.1 + * + * @param $extensionName String + * @param $currentVersion String + * + * @return Mixed: false when there is no update, object with info when there is. + */ + public abstract function extensionHasUpdate( $extensionName, $currentVersion ); + + /** + * Checks if newer versions of MediaWiki is available. + * + * @since 0.1 + * + * @param $currentVersion String + * + * @return Mixed: false when there is no update, object with info when there is. + */ + public abstract function coreHasUpdate( $currentVersion ); + + /** + * Checks if there are any updates for this MediaWiki installation and extensions. + * + * @since 0.1 + * + * @param $coreVersion String + * @param $extensions Array + * + * @return Mixed: false when there is are updates, array with obecjts with info when there are. + */ + public abstract function installationHasUpdates( $coreVersion, array $extensions ); + + /** + * Constructor. + * + * @param $location String + * + * @since 0.1 + */ + public function __construct( $location ) { + $this->location = $location; + } + +} \ No newline at end of file Property changes on: trunk/phase3/includes/PackageRepository.php ___________________________________________________________________ Added: svn:eol-style + native _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs