'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',
'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',
--- /dev/null
+<?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
--- /dev/null
+<?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