r71107 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71106‎ | r71107 | r71108 >
Date:09:40, 15 August 2010
Author:jeroendedauw
Status:reverted (Comments)
Tags:
Comment:
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 (modified) (history)
  • /trunk/phase3/includes/DistributionRepository.php (added) (history)
  • /trunk/phase3/includes/PackageRepository.php (added) (history)

Diff [purge]

Index: trunk/phase3/includes/DistributionRepository.php
@@ -0,0 +1,186 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the DistributionRepository class.
 6+ *
 7+ * @file DistributionRepository.php
 8+ * @ingroup Deployment
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+/**
 18+ * Repository class for interaction with repositories provided by
 19+ * the Distirbution extension and the MediaWiki API.
 20+ *
 21+ * @since 0.1
 22+ *
 23+ * @ingroup Deployment
 24+ *
 25+ * @author Jeroen De Dauw
 26+ */
 27+class DistributionRepository extends PackageRepository {
 28+
 29+ /**
 30+ * Constructor.
 31+ *
 32+ * @param $location String: path to the api of the MediaWiki install providing the repository.
 33+ *
 34+ * @since 0.1
 35+ */
 36+ public function __construct( $location ) {
 37+ parent::__construct( $location );
 38+ }
 39+
 40+ /**
 41+ * @see PackageRepository::findExtenions
 42+ *
 43+ * @since 0.1
 44+ *
 45+ * @param $filterType String
 46+ * @param $filterValue String
 47+ *
 48+ * @return array
 49+ */
 50+ public function findExtenions( $filterType, $filterValue ) {
 51+ global $wgRepositoryPackageStates;
 52+
 53+ $filterType = urlencode( $filterType );
 54+ $filterValue = urlencode( $filterValue );
 55+ $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
 56+
 57+ $response = Http::get(
 58+ "$this->location?format=json&action=query&list=extensions&dstfilter=$filterType&dstvalue=$filterValue&dststate=$states",
 59+ 'default',
 60+ array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
 61+ );
 62+
 63+ $extensions = array();
 64+
 65+ if ( $response !== false ) {
 66+ $response = FormatJson::decode( $response );
 67+
 68+ if ( property_exists( $response, 'query' ) && property_exists( $response->query, 'extensions' ) ) {
 69+ $extensions = $response->query->extensions;
 70+ }
 71+ }
 72+
 73+ return $extensions;
 74+ }
 75+
 76+ /**
 77+ * @see PackageRepository::extensionHasUpdate
 78+ *
 79+ * @since 0.1
 80+ */
 81+ public function extensionHasUpdate( $extensionName, $currentVersion ) {
 82+ global $wgRepositoryPackageStates;
 83+
 84+ $extensionName = urlencode( $extensionName );
 85+ $currentVersion = urlencode( $currentVersion );
 86+ $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
 87+
 88+ $response = Http::get(
 89+ "$this->location?format=json&action=updates&extensions=$extensionName;$currentVersion&state=$states",
 90+ 'default',
 91+ array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
 92+ );
 93+
 94+ if ( $response === false ) {
 95+ return false;
 96+ }
 97+
 98+ $response = FormatJson::decode( $response );
 99+
 100+ if ( property_exists( $response, 'extensions' ) && property_exists( $response->extensions, $extensionName ) ) {
 101+ return $response->extensions->$extensionName;
 102+ }
 103+
 104+ return false;
 105+ }
 106+
 107+ /**
 108+ * @see PackageRepository::coreHasUpdate
 109+ *
 110+ * @since 0.1
 111+ */
 112+ public function coreHasUpdate( $currentVersion ) {
 113+ global $wgRepositoryPackageStates;
 114+
 115+ $currentVersion = urlencode( $currentVersion );
 116+ $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
 117+
 118+ $response = Http::get(
 119+ "$this->location?format=json&action=updates&mediawiki=$currentVersion&state=$states",
 120+ 'default',
 121+ array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
 122+ );
 123+
 124+ if ( $response === false ) {
 125+ return false;
 126+ }
 127+
 128+ $response = FormatJson::decode( $response );
 129+
 130+ if ( property_exists( $response, 'mediawiki' ) ) {
 131+ return $response->mediawiki;
 132+ }
 133+
 134+ return false;
 135+ }
 136+
 137+ /**
 138+ * @see PackageRepository::installationHasUpdates
 139+ *
 140+ * @since 0.1
 141+ */
 142+ public function installationHasUpdates( $coreVersion, array $extensions ) {
 143+ global $wgRepositoryPackageStates;
 144+
 145+ $coreVersion = urlencode( $coreVersion );
 146+ $states = urlencode( implode( '|', $wgRepositoryPackageStates ) );
 147+
 148+ $extensionParams = array();
 149+
 150+ if ( count( $extensions ) > 0 ) {
 151+ foreach ( $extensions as $extensionName => $extensionVersion ) {
 152+ $extensionParams[] = urlencode( $extensionName ) . ';' . urlencode( $extensionVersion );
 153+ }
 154+
 155+ $extensionParams = '&extensions=' . urlencode( implode( '|', $extensionParams ) );
 156+ }
 157+
 158+ $response = Http::get(
 159+ "$this->location?format=json&action=updates&mediawiki=$coreVersion{$extensionParams}&state=$states",
 160+ 'default',
 161+ array( 'sslVerifyHost' => true, 'sslVerifyCert' => true )
 162+ );
 163+
 164+ if ( $response === false ) {
 165+ return false;
 166+ }
 167+
 168+ $response = FormatJson::decode( $response );
 169+
 170+ $updates = array();
 171+
 172+ if ( property_exists( $response, 'mediawiki' ) ) {
 173+ $updates['MediaWiki'] = $response->mediawiki;
 174+ }
 175+
 176+ if ( property_exists( $response, 'extensions' ) ) {
 177+ foreach ( $extensions as $extensionName => $extensionVersion ) {
 178+ if ( property_exists( $response->extensions, $extensionName ) ) {
 179+ $updates[$extensionName] = $response->extensions->$extensionName;
 180+ }
 181+ }
 182+ }
 183+
 184+ return count( $updates ) > 0 ? $updates : false;
 185+ }
 186+
 187+}
\ No newline at end of file
Property changes on: trunk/phase3/includes/DistributionRepository.php
___________________________________________________________________
Added: svn:eol-style
1188 + native
Index: trunk/phase3/includes/PackageRepository.php
@@ -0,0 +1,95 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the PackageRepository class.
 6+ *
 7+ * @file PackageRepository.php
 8+ * @ingroup Deployment
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+/**
 18+ * Base repository class. Deriving classes handle interaction with
 19+ * package repositories of the type they support.
 20+ *
 21+ * @since 0.1
 22+ *
 23+ * @ingroup Deployment
 24+ *
 25+ * @author Jeroen De Dauw
 26+ */
 27+abstract class PackageRepository {
 28+
 29+ /**
 30+ * Base location of the repository.
 31+ *
 32+ * @since 0.1
 33+ *
 34+ * @var string
 35+ */
 36+ protected $location;
 37+
 38+ /**
 39+ * Returns a list of extensions matching the search criteria.
 40+ *
 41+ * @since 0.1
 42+ *
 43+ * @param $filterType String
 44+ * @param $filterValue String
 45+ *
 46+ * @return array
 47+ */
 48+ public abstract function findExtenions( $filterType, $filterValue );
 49+
 50+ /**
 51+ * Checks if newer versions of an extension are available.
 52+ *
 53+ * @since 0.1
 54+ *
 55+ * @param $extensionName String
 56+ * @param $currentVersion String
 57+ *
 58+ * @return Mixed: false when there is no update, object with info when there is.
 59+ */
 60+ public abstract function extensionHasUpdate( $extensionName, $currentVersion );
 61+
 62+ /**
 63+ * Checks if newer versions of MediaWiki is available.
 64+ *
 65+ * @since 0.1
 66+ *
 67+ * @param $currentVersion String
 68+ *
 69+ * @return Mixed: false when there is no update, object with info when there is.
 70+ */
 71+ public abstract function coreHasUpdate( $currentVersion );
 72+
 73+ /**
 74+ * Checks if there are any updates for this MediaWiki installation and extensions.
 75+ *
 76+ * @since 0.1
 77+ *
 78+ * @param $coreVersion String
 79+ * @param $extensions Array
 80+ *
 81+ * @return Mixed: false when there is are updates, array with obecjts with info when there are.
 82+ */
 83+ public abstract function installationHasUpdates( $coreVersion, array $extensions );
 84+
 85+ /**
 86+ * Constructor.
 87+ *
 88+ * @param $location String
 89+ *
 90+ * @since 0.1
 91+ */
 92+ public function __construct( $location ) {
 93+ $this->location = $location;
 94+ }
 95+
 96+}
\ No newline at end of file
Property changes on: trunk/phase3/includes/PackageRepository.php
___________________________________________________________________
Added: svn:eol-style
197 + native
Index: trunk/phase3/includes/AutoLoader.php
@@ -55,6 +55,7 @@
5656 'DBABagOStuff' => 'includes/BagOStuff.php',
5757 'DependencyWrapper' => 'includes/CacheDependency.php',
5858 'DiffHistoryBlob' => 'includes/HistoryBlob.php',
 59+ 'DistributionRepository' => 'includes/DistributionRepository.php',
5960 'DjVuImage' => 'includes/DjVuImage.php',
6061 'DoubleReplacer' => 'includes/StringUtils.php',
6162 'DublinCoreRdf' => 'includes/Metadata.php',
@@ -168,6 +169,7 @@
169170 'MWNamespace' => 'includes/Namespace.php',
170171 'OldChangesList' => 'includes/ChangesList.php',
171172 'OutputPage' => 'includes/OutputPage.php',
 173+ 'PackageRepository' => 'includes/PackageRepository.php',
172174 'PageQueryPage' => 'includes/PageQueryPage.php',
173175 'PageHistory' => 'includes/HistoryPage.php',
174176 'PageHistoryPager' => 'includes/HistoryPage.php',

Follow-up revisions

RevisionCommit summaryAuthorDate
r71108Follow up to r71107jeroendedauw09:41, 15 August 2010
r71109Follow up to r71107jeroendedauw09:48, 15 August 2010
r71110Follow up to r71107 - added forgotten global function and corrected @since an...jeroendedauw09:49, 15 August 2010
r71111Follow up to r71107 - moved forgotten global variablesjeroendedauw10:02, 15 August 2010
r77883Remove "checking for latest version" feature from the new installer. Original...demon15:32, 6 December 2010

Comments

#Comment by Nikerabbit (talk | contribs)   10:38, 15 August 2010

Why PackageRepository is abstract class instead of an interface?

#Comment by Jeroen De Dauw (talk | contribs)   10:46, 15 August 2010

It's not completely abstract. No gain in changing it at this point, maybe later on.

#Comment by Nikerabbit (talk | contribs)   10:50, 15 August 2010

Is the non-abstract part actually useful at this point? Abstract classes are poor interfaces, I've noticed. I've started doing both an interface and an abstract class if I want default implementations.

#Comment by Jeroen De Dauw (talk | contribs)   10:53, 15 August 2010

You can change it if you want, but I'm concentrating on getting things to work now, and am not going to do refactoring that can be done later with the same amount of effort.

Status & tagging log