http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72488

Revision: 72488
Author:   jeroendedauw
Date:     2010-09-06 12:28:24 +0000 (Mon, 06 Sep 2010)

Log Message:
-----------
Changes for 0.7 - moved common service stuff to includes/

Modified Paths:
--------------
    trunk/extensions/Maps/Maps.php

Added Paths:
-----------
    trunk/extensions/Maps/includes/Maps_MappingService.php
    trunk/extensions/Maps/includes/Maps_MappingServices.php
    trunk/extensions/Maps/includes/iMappingService.php

Removed Paths:
-------------
    trunk/extensions/Maps/includes/services/Maps_MappingService.php
    trunk/extensions/Maps/includes/services/Maps_MappingServices.php
    trunk/extensions/Maps/includes/services/iMappingService.php

Modified: trunk/extensions/Maps/Maps.php
===================================================================
--- trunk/extensions/Maps/Maps.php      2010-09-06 12:25:25 UTC (rev 72487)
+++ trunk/extensions/Maps/Maps.php      2010-09-06 12:28:24 UTC (rev 72488)
@@ -97,6 +97,9 @@
        $wgAutoloadClasses['MapsGeocoder']                              = 
$incDir . 'Maps_Geocoder.php';
        $wgAutoloadClasses['iMappingFeature']                   = $incDir . 
'iMappingFeature.php';
        $wgAutoloadClasses['iMappingParserFunction']    = $incDir . 
'iMappingParserFunction.php'; // TODO
+       $wgAutoloadClasses['iMappingService']                   = $incDir . 
'iMappingService.php';
+       $wgAutoloadClasses['MapsMappingServices']               = $incDir . 
'Maps_MappingServices.php';
+       $wgAutoloadClasses['MapsMappingService']                = $incDir . 
'Maps_MappingService.php';  
        
        // Geocoders at "Includes/Geocoders/".
        $geoDir = $incDir . 'geocoders/';
@@ -114,12 +117,6 @@
        $wgAutoloadClasses['MapsGeocode']                               = 
$phDir . 'Maps_Geocode.php';
        $wgAutoloadClasses['MapsGeodistance']                   = $phDir . 
'Maps_Geodistance.php';
        
-       // Load the "Service/" classes and interfaces.
-       $srvDir = $incDir . '/services/';
-       $wgAutoloadClasses['iMappingService']                   = $srvDir . 
'iMappingService.php';
-       $wgAutoloadClasses['MapsMappingServices']               = $srvDir . 
'Maps_MappingServices.php';
-       $wgAutoloadClasses['MapsMappingService']                = $srvDir . 
'Maps_MappingService.php';
-       
        // Load the "Feature/" classes.
        $ftDir = $incDir . '/features/';
        $wgAutoloadClasses['MapsBaseMap']                               = 
$ftDir . 'Maps_BaseMap.php';

Copied: trunk/extensions/Maps/includes/Maps_MappingService.php (from rev 72483, 
trunk/extensions/Maps/includes/services/Maps_MappingService.php)
===================================================================
--- trunk/extensions/Maps/includes/Maps_MappingService.php                      
        (rev 0)
+++ trunk/extensions/Maps/includes/Maps_MappingService.php      2010-09-06 
12:28:24 UTC (rev 72488)
@@ -0,0 +1,249 @@
+<?php
+
+/**
+ * File holding the MapsMappingService class.
+ *
+ * @file Maps_MappingService.php
+ * @ingroup Maps
+ *
+ * @author Jeroen De Dauw
+ */
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+       die( 'Not an entry point.' );
+}
+
+/**
+ * Base class for mapping services. Deriving classes hold mapping service 
specific 
+ * information and functionality, which can be used by any mapping feature.
+ * 
+ * @since 0.6.3
+ * 
+ * @author Jeroen De Dauw
+ */
+abstract class MapsMappingService implements iMappingService {
+       
+       /**
+        * The internal name of the service.
+        * 
+        * @since 0.6.3
+        * 
+        * @var string
+        */
+       protected $serviceName;
+       
+       /**
+        * A list of aliases for the internal name.
+        * 
+        * @since 0.6.3
+        * 
+        * @var array
+        */
+       protected $aliases;
+       
+       /**
+        * A list of features that support the service, used for validation and 
defaulting.
+        * 
+        * @since 0.6.3
+        * 
+        * @var array
+        */
+       protected $features;
+       
+       /**
+        * A list of parameter info specific to the service, which can be used 
by any feature
+        * to pass along to Validator to handle parameters.
+        * 
+        * @since 0.6.3
+        * 
+        * @var mixed Array or false
+        */
+       private $parameterInfo = false;
+       
+       /**
+        * A list of dependencies (header items) that have been added.
+        * 
+        * @since 0.6.3
+        * 
+        * @var array
+        */
+       private $addedDependencies = array();
+       
+       /**
+        * A list of dependencies (header items) that need to be added.
+        * 
+        * @since 0.6.3
+        * 
+        * @var array
+        */
+       private $dependencies = array();
+       
+       /**
+        * Constructor. Creates a new instance of MapsMappingService.
+        * 
+        * @since 0.6.3
+        * 
+        * @param string $serviceName
+        * @param array $aliases
+        */
+       function __construct( $serviceName, array $aliases = array() ) {
+               $this->serviceName = $serviceName;
+               $this->aliases = $aliases;
+       }
+       
+       /**
+        * @see iMappingService::getParameterInfo
+        * 
+        * @since 0.6.3
+        */     
+       public final function getParameterInfo() {
+               if ( $this->parameterInfo === false ) {
+                       $this->parameterInfo = array();
+                       $this->initParameterInfo( $this->parameterInfo );
+               }
+               
+               return $this->parameterInfo;
+       }
+       
+       /**
+        * @see iMappingService::createMarkersJs
+        * 
+        * @since 0.6.5
+        */
+       public function createMarkersJs( array $markers ) {
+               return '[]';
+       }               
+       
+       /**
+        * @see iMappingService::addFeature
+        * 
+        * @since 0.6.3
+        */
+       public function addFeature( $featureName, $handlingClass ) {
+               $this->features[$featureName] = $handlingClass;
+       }
+       
+       /**
+        * @see iMappingService::addDependencies 
+        * 
+        * @since 0.6.3
+        */
+       public final function addDependencies( &$parserOrOut ) {
+               $dependencies = $this->getDependencyHtml();
+               
+               // Only aff a head item when there are dependencies.
+               if ( $dependencies ) {
+                       if ( $parserOrOut instanceof Parser ) {
+                               $parserOrOut->getOutput()->addHeadItem( 
$dependencies );
+                       } 
+                       else if ( $parserOrOut instanceof OutputPage ) { 
+                               $parserOrOut->addHeadItem( md5( $dependencies 
), $dependencies );
+                       }                       
+               }
+       }
+       
+       /**
+        * @see iMappingService::getDependencyHtml 
+        * 
+        * @since 0.6.3
+        */
+       public final function getDependencyHtml() {
+               $allDependencies = array_merge( $this->getDependencies(), 
$this->dependencies );
+               $dependencies = array();
+               
+               // Only add dependnecies that have not yet been added.
+               foreach ( $allDependencies as $dependency ) {
+                       if ( !in_array( $dependency, $this->addedDependencies ) 
) {
+                               $dependencies[] = $dependency;
+                               $this->addedDependencies[] = $dependency;
+                       }
+               }
+               
+               // If there are dependencies, put them all together in a 
string, otherwise return false.
+               return count( $dependencies ) > 0 ? implode( '', $dependencies 
) : false;
+       }
+       
+       /**
+        * @see iMappingService::addDependency
+        * 
+        * @since 0.6.3
+        */
+       public final function addDependency( $dependencyHtml ) {
+               $this->dependencies[] = $dependencyHtml;
+       }       
+       
+       /**
+        * @see iMappingService::getName
+        * 
+        * @since 0.6.3
+        */     
+       public function getName() {
+               return $this->serviceName;
+       }
+       
+       /**
+        * @see iMappingService::getFeature
+        * 
+        * @since 0.6.3
+        */
+       public function getFeature( $featureName ) {
+               return array_key_exists( $featureName, $this->features ) ? 
$this->features[$featureName] : false;
+       }
+       
+       /**
+        * @see iMappingService::getFeatureInstance
+        * 
+        * @since 0.6.6
+        */
+       public function getFeatureInstance( $featureName ) {
+               $className = $this->getFeature( $featureName );
+               
+               if ( $className === false || !class_exists( $className ) ) {
+                       // TODO: log/throw error, as this should not happen
+               }
+               
+               return new $className( $this );
+       }       
+       
+       /**
+        * @see iMappingService::getAliases
+        * 
+        * @since 0.6.3
+        */
+       public function getAliases() {
+               return $this->aliases;
+       }
+       
+       /**
+        * @see iMappingService::hasAlias
+        * 
+        * @since 0.6.3
+        */
+       public function hasAlias( $alias ) {
+               return in_array( $alias, $this->aliases );
+       }
+       
+       /**
+        * Returns a list of html fragments, such as script includes, the 
current service depends on.
+        * 
+        * @since 0.6.3
+        * 
+        * @return array
+        */
+       protected function getDependencies() {
+               return array();
+       }
+       
+       /**
+        * Initializes the service parameters.
+        * 
+        * You can override this method to set service specific parameters in 
the inheriting class. 
+        * 
+        * @since 0.6.3
+        * 
+        * @param array $parameters
+        */     
+       protected function initParameterInfo( array &$parameters ) {
+       }       
+       
+}
\ No newline at end of file

Copied: trunk/extensions/Maps/includes/Maps_MappingServices.php (from rev 
72483, trunk/extensions/Maps/includes/services/Maps_MappingServices.php)
===================================================================
--- trunk/extensions/Maps/includes/Maps_MappingServices.php                     
        (rev 0)
+++ trunk/extensions/Maps/includes/Maps_MappingServices.php     2010-09-06 
12:28:24 UTC (rev 72488)
@@ -0,0 +1,222 @@
+<?php
+
+/**
+ * Class for interaction with MappingService objects.
+ * 
+ * @since 0.6.6
+ * 
+ * @file Maps_MappingServices.php
+ * @ingroup Maps
+ * 
+ * @author Jeroen De Dauw
+ */
+final class MapsMappingServices {
+       
+       /**
+        * Accociative array containing service identifiers as keys and the 
names
+        * of service classes as values.
+        * 
+        * @since 0.6.6
+        * 
+        * @var array of string
+        */
+       protected static $registeredServices = array();
+       
+       /**
+        * Accociative with service identifiers as keys containing instances of
+        * the mapping service classes. 
+        * 
+        * Note: This list only contains the instances, so is not to be used for
+        * looping over all available services, as not all of them are 
guaranteed 
+        * to have an instance already, use $registeredServices for this 
purpouse.
+        * 
+        * @since 0.6.6
+        * 
+        * @var array of iMappingService
+        */
+       protected static $services = array();
+       
+       /**
+        * Registeres a service class linked to an identifier. 
+        * Also allows automatic registration of a list of features for this 
service.
+        * 
+        * @since 0.6.6
+        * 
+        * @param $serviceIdentifier String: internal service identifier
+        * @param $serviceClassName String
+        * @param $features Array
+        */
+       public static function registerService( $serviceIdentifier, 
$serviceClassName, array $features = array() ) {
+               self::$registeredServices[$serviceIdentifier] = 
$serviceClassName;
+               
+               foreach( $features as $featureName => $featureClassName ) {
+                       self::registerServiceFeature( $serviceIdentifier, 
$featureName, $featureClassName );
+               }
+       }
+       
+       /**
+        * Registeres a feature for a service object.
+        * Registers a warning when the service is not registered, but does not 
give an error.
+        * 
+        * @since 0.6.6
+        * 
+        * @param $serviceIdentifier String: internal service identifier
+        * @param $featureName String
+        * @param $featureClassName String
+        */
+       public static function registerServiceFeature( $serviceIdentifier, 
$featureName, $featureClassName ) {
+               if ( array_key_exists( $serviceIdentifier, 
self::$registeredServices ) ) {
+                       $service = self::getServiceInstance( $serviceIdentifier 
);
+                       $service->addFeature( $featureName, $featureClassName 
);                        
+               }
+               else {
+                       // If the feature is not registered, register a 
warning. This is not an error though!
+                       wfWarn( "Tried to register feature '$featureName' with 
class '$featureClassName' to non-registered service '$serviceIdentifier'." );
+               }
+       }
+       
+       /**
+        * Returns the instance of a service class. This method takes
+        * care of creating the instance if this is not done yet.
+        * 
+        * @since 0.6.6
+        * 
+        * @param $serviceIdentifier String: internal service identifier
+        * 
+        * @return iMappingService
+        */
+       public static function getServiceInstance( $serviceIdentifier ) {
+               if ( !array_key_exists( $serviceIdentifier, self::$services ) ) 
{
+                       if ( array_key_exists( $serviceIdentifier, 
self::$registeredServices ) ) {
+                               $service = new 
self::$registeredServices[$serviceIdentifier]( $serviceIdentifier );
+                               
+                               if ( $service instanceof iMappingService ) {
+                                       self::$services[$serviceIdentifier] = 
$service;
+                               }
+                               else {
+                                       throw new Exception( 'The service 
object linked to service identifier ' . $serviceIdentifier . ' does not 
implement iMappingService.' );
+                               }
+                       }
+                       else {
+                               throw new Exception( 'There is no service 
object linked to service identifier ' . $serviceIdentifier . '.' );
+                       }
+               }
+
+               return self::$services[$serviceIdentifier];
+       }
+       
+       /**
+        * Retuns an instance of a MapsMappingService. The service name is 
validated
+        * and aliases are resolved and a check is made if the feature is 
supported.
+        * If the feature is not supported, or the service does not exist, 
defaulting
+        * will be used.
+        * 
+        * @since 0.6.6
+        * 
+        * @param $service String: service name or alias, does not need to be 
secure
+        * @param $feature String
+        * 
+        * @return iMappingService
+        */
+       public static function getValidServiceInstance( $service, $feature ) {
+               return self::getServiceInstance( self::getValidServiceName( 
$service, $feature ) );
+       }
+       
+       /**
+        * Returns a valid service. When an invalid service is provided, the 
default one will be returned.
+        * Aliases are also changed into the main service names @see 
MapsMappingServices::getMainServiceName.
+        *
+        * @since 0.6.6
+        *
+        * @param $service String: service name or alias, does not need to be 
secure
+        * @param $feature String
+        *
+        * @return string
+        */
+       public static function getValidServiceName( $service, $feature ) {
+               global $egMapsDefaultService, $egMapsDefaultServices;
+
+               // Get rid of any aliases.
+               // Also rely on this to instantiate all registered services.
+               $service = self::getMainServiceName( $service );
+               
+               // Check if there is a mathing instance.
+               $shouldChange = !array_key_exists( $service, self::$services );
+               
+               // If it should not be changed, ensure the service supports 
this feature.
+               if ( !$shouldChange ) {
+                       $shouldChange = self::getServiceInstance( $service 
)->getFeature( $feature ) === false;
+               }
+
+               // Change the service to the most specific default value 
available.
+               // Note: the default services should support their 
corresponding features.
+               // If they don't, a fatal error will occur later on.
+               if ( $shouldChange ) {
+                       if ( array_key_exists( $feature, $egMapsDefaultServices 
) ) {
+                               $service = $egMapsDefaultServices[$feature];
+                       }
+                       else {
+                               $service = $egMapsDefaultService;
+                       }
+               }
+
+               return $service;
+       }
+
+       /**
+        * Returns an array with the identifiers for all registered services.
+        * 
+        * @since 0.6.6
+        * 
+        * @return array
+        */
+       public static function getServiceIdentifiers() {
+               return array_keys( self::$registeredServices );
+       }
+       
+       /**
+        * Checks if the service name is an alias for an actual service,
+        * and changes it into the main service name if this is the case.
+        *
+        * @since 0.6.6
+        *
+        * @param $serviceName String: service name or alias, does not need to 
be secure
+        * 
+        * @return string
+        */
+       protected static function getMainServiceName( $serviceName ) {
+               if ( !array_key_exists( $serviceName, self::$services ) ) {
+                       foreach ( self::getServiceIdentifiers() as 
$serviceIdentifier ) {
+                               $service = self::getServiceInstance( 
$serviceIdentifier );
+
+                               if ( $service->hasAlias( $serviceName ) ) {
+                                        $serviceName = $service->getName();
+                                        break;
+                               }
+                       }
+               }
+               
+               return $serviceName;
+       }
+       
+       /**
+        * Returns an array containing all the possible values for the service 
parameter, including aliases.
+        *
+        * @since 0.6.6
+        *
+        * @return array
+        */
+       public static function getAllServiceValues() {
+               global $egMapsAvailableServices;
+
+               $allServiceValues = array();
+
+               foreach ( $egMapsAvailableServices as $availableService ) {
+                       $allServiceValues[] = $availableService;
+                       $allServiceValues = array_merge( $allServiceValues, 
self::getServiceInstance( $availableService )->getAliases() );
+               }
+
+               return $allServiceValues;
+       }       
+       
+}
\ No newline at end of file

Copied: trunk/extensions/Maps/includes/iMappingService.php (from rev 72483, 
trunk/extensions/Maps/includes/services/iMappingService.php)
===================================================================
--- trunk/extensions/Maps/includes/iMappingService.php                          
(rev 0)
+++ trunk/extensions/Maps/includes/iMappingService.php  2010-09-06 12:28:24 UTC 
(rev 72488)
@@ -0,0 +1,158 @@
+<?php
+
+/**
+ * File holding interface iMapParserFunction.
+ * 
+ * @file iMappingService.php
+ * @ingroup Maps
+ * 
+ * @author Jeroen De Dauw
+ */
+
+if ( !defined( 'MEDIAWIKI' ) ) {
+       die( 'Not an entry point.' );
+}
+
+/**
+ * Interface that should be implemented by all mapping feature classes.
+ * 
+ * @since 0.6.3
+ * 
+ * @author Jeroen De Dauw
+ */
+interface iMappingService {
+       
+       /**
+        * Returns the internal name of the service.
+        * 
+        * @since 0.6.5
+        * 
+        * @return string
+        */     
+       function getName();
+       
+       /**
+        * Adds the dependencies to the parser output as head items.
+        * 
+        * @since 0.6.3
+        * 
+        * @param mixed $parserOrOut
+        */
+       function addDependencies( &$parserOrOut );
+       
+       /**
+        * Returns an array that specifies the parameters supported by this 
service,
+        * together with their meta-data. This is in a format usable by 
Validator.
+        * 
+        * @since 0.6.3
+        * 
+        * @return array
+        */
+       function getParameterInfo();
+       
+       /**
+        * Adds a dependency that is needed for this service. It will be passed 
along with the next 
+        * call to getDependencyHtml or addDependencies.
+        * 
+        * @since 0.6.5
+        * 
+        * @param string $dependencyHtml
+        */     
+       function addDependency( $dependencyHtml );
+       
+       /**
+        * Adds a feature to this service. This is to indicate this service has 
support for this feature.
+        * 
+        * @since 0.6.5
+        * 
+        * @param string $featureName
+        * @param string $handlingClass
+        */     
+       function addFeature( $featureName, $handlingClass );
+       
+       /**
+        * Returns the html for the needed dependencies or false.
+        * 
+        * @since 0.6.5
+        * 
+        * @return mixed String or false
+        */     
+       function getDependencyHtml();
+       
+       /**
+        * Returns the name of the class that handles the provided feature in 
this service, or false if there is none.
+        * 
+        * @since 0.6.5
+        * 
+        * @param string $featureName.
+        * 
+        * @return mixed String or false
+        */     
+       function getFeature( $featureName );
+       
+       /**
+        * Returns an instance of the class handling the provided feature with 
this service, or false if there is none.
+        * 
+        * @since 0.6.6
+        * 
+        * @param string $featureName.
+        * 
+        * @return iMappingFeature or false
+        */     
+       function getFeatureInstance( $featureName );    
+       
+       /**
+        * Returns a list of aliases.
+        * 
+        * @since 0.6.5
+        * 
+        * @return array
+        */     
+       function getAliases();
+       
+       /**
+        * Returns if the service has a certain alias or not.
+        * 
+        * @since 0.6.5
+        * 
+        * @param string $alias
+        * 
+        * @return boolean
+        */     
+       function hasAlias( $alias );
+       
+       /**
+        * Returns the default zoomlevel for the mapping service.
+        * 
+        * @since 0.6.5
+        * 
+        * @return integer
+        */
+       function getDefaultZoom();
+       
+       /**
+        * Returns a string that can be used as an unique ID for the map html 
element.
+        * Increments the number by default, providing false for $increment 
will get
+        * you the same ID as on the last request.
+        * 
+        * @since 0.6.5
+        * 
+        * @param boolean $increment
+        * 
+        * @return string
+        */
+       function getMapId( $increment = true );
+
+       /**
+        * Creates a JS array with marker meta data that can be used to 
construct a 
+        * map with markers via a function in this services JS file.
+        * 
+        * @since 0.6.5
+        * 
+        * @param array $markers
+        * 
+        * @return string
+        */     
+       function createMarkersJs( array $markers );     
+
+}
\ No newline at end of file

Deleted: trunk/extensions/Maps/includes/services/Maps_MappingService.php
===================================================================
--- trunk/extensions/Maps/includes/services/Maps_MappingService.php     
2010-09-06 12:25:25 UTC (rev 72487)
+++ trunk/extensions/Maps/includes/services/Maps_MappingService.php     
2010-09-06 12:28:24 UTC (rev 72488)
@@ -1,249 +0,0 @@
-<?php
-
-/**
- * File holding the MapsMappingService class.
- *
- * @file Maps_MappingService.php
- * @ingroup Maps
- *
- * @author Jeroen De Dauw
- */
-
-if ( !defined( 'MEDIAWIKI' ) ) {
-       die( 'Not an entry point.' );
-}
-
-/**
- * Base class for mapping services. Deriving classes hold mapping service 
specific 
- * information and functionality, which can be used by any mapping feature.
- * 
- * @since 0.6.3
- * 
- * @author Jeroen De Dauw
- */
-abstract class MapsMappingService implements iMappingService {
-       
-       /**
-        * The internal name of the service.
-        * 
-        * @since 0.6.3
-        * 
-        * @var string
-        */
-       protected $serviceName;
-       
-       /**
-        * A list of aliases for the internal name.
-        * 
-        * @since 0.6.3
-        * 
-        * @var array
-        */
-       protected $aliases;
-       
-       /**
-        * A list of features that support the service, used for validation and 
defaulting.
-        * 
-        * @since 0.6.3
-        * 
-        * @var array
-        */
-       protected $features;
-       
-       /**
-        * A list of parameter info specific to the service, which can be used 
by any feature
-        * to pass along to Validator to handle parameters.
-        * 
-        * @since 0.6.3
-        * 
-        * @var mixed Array or false
-        */
-       private $parameterInfo = false;
-       
-       /**
-        * A list of dependencies (header items) that have been added.
-        * 
-        * @since 0.6.3
-        * 
-        * @var array
-        */
-       private $addedDependencies = array();
-       
-       /**
-        * A list of dependencies (header items) that need to be added.
-        * 
-        * @since 0.6.3
-        * 
-        * @var array
-        */
-       private $dependencies = array();
-       
-       /**
-        * Constructor. Creates a new instance of MapsMappingService.
-        * 
-        * @since 0.6.3
-        * 
-        * @param string $serviceName
-        * @param array $aliases
-        */
-       function __construct( $serviceName, array $aliases = array() ) {
-               $this->serviceName = $serviceName;
-               $this->aliases = $aliases;
-       }
-       
-       /**
-        * @see iMappingService::getParameterInfo
-        * 
-        * @since 0.6.3
-        */     
-       public final function getParameterInfo() {
-               if ( $this->parameterInfo === false ) {
-                       $this->parameterInfo = array();
-                       $this->initParameterInfo( $this->parameterInfo );
-               }
-               
-               return $this->parameterInfo;
-       }
-       
-       /**
-        * @see iMappingService::createMarkersJs
-        * 
-        * @since 0.6.5
-        */
-       public function createMarkersJs( array $markers ) {
-               return '[]';
-       }               
-       
-       /**
-        * @see iMappingService::addFeature
-        * 
-        * @since 0.6.3
-        */
-       public function addFeature( $featureName, $handlingClass ) {
-               $this->features[$featureName] = $handlingClass;
-       }
-       
-       /**
-        * @see iMappingService::addDependencies 
-        * 
-        * @since 0.6.3
-        */
-       public final function addDependencies( &$parserOrOut ) {
-               $dependencies = $this->getDependencyHtml();
-               
-               // Only aff a head item when there are dependencies.
-               if ( $dependencies ) {
-                       if ( $parserOrOut instanceof Parser ) {
-                               $parserOrOut->getOutput()->addHeadItem( 
$dependencies );
-                       } 
-                       else if ( $parserOrOut instanceof OutputPage ) { 
-                               $parserOrOut->addHeadItem( md5( $dependencies 
), $dependencies );
-                       }                       
-               }
-       }
-       
-       /**
-        * @see iMappingService::getDependencyHtml 
-        * 
-        * @since 0.6.3
-        */
-       public final function getDependencyHtml() {
-               $allDependencies = array_merge( $this->getDependencies(), 
$this->dependencies );
-               $dependencies = array();
-               
-               // Only add dependnecies that have not yet been added.
-               foreach ( $allDependencies as $dependency ) {
-                       if ( !in_array( $dependency, $this->addedDependencies ) 
) {
-                               $dependencies[] = $dependency;
-                               $this->addedDependencies[] = $dependency;
-                       }
-               }
-               
-               // If there are dependencies, put them all together in a 
string, otherwise return false.
-               return count( $dependencies ) > 0 ? implode( '', $dependencies 
) : false;
-       }
-       
-       /**
-        * @see iMappingService::addDependency
-        * 
-        * @since 0.6.3
-        */
-       public final function addDependency( $dependencyHtml ) {
-               $this->dependencies[] = $dependencyHtml;
-       }       
-       
-       /**
-        * @see iMappingService::getName
-        * 
-        * @since 0.6.3
-        */     
-       public function getName() {
-               return $this->serviceName;
-       }
-       
-       /**
-        * @see iMappingService::getFeature
-        * 
-        * @since 0.6.3
-        */
-       public function getFeature( $featureName ) {
-               return array_key_exists( $featureName, $this->features ) ? 
$this->features[$featureName] : false;
-       }
-       
-       /**
-        * @see iMappingService::getFeatureInstance
-        * 
-        * @since 0.6.6
-        */
-       public function getFeatureInstance( $featureName ) {
-               $className = $this->getFeature( $featureName );
-               
-               if ( $className === false || !class_exists( $className ) ) {
-                       // TODO: log/throw error, as this should not happen
-               }
-               
-               return new $className( $this );
-       }       
-       
-       /**
-        * @see iMappingService::getAliases
-        * 
-        * @since 0.6.3
-        */
-       public function getAliases() {
-               return $this->aliases;
-       }
-       
-       /**
-        * @see iMappingService::hasAlias
-        * 
-        * @since 0.6.3
-        */
-       public function hasAlias( $alias ) {
-               return in_array( $alias, $this->aliases );
-       }
-       
-       /**
-        * Returns a list of html fragments, such as script includes, the 
current service depends on.
-        * 
-        * @since 0.6.3
-        * 
-        * @return array
-        */
-       protected function getDependencies() {
-               return array();
-       }
-       
-       /**
-        * Initializes the service parameters.
-        * 
-        * You can override this method to set service specific parameters in 
the inheriting class. 
-        * 
-        * @since 0.6.3
-        * 
-        * @param array $parameters
-        */     
-       protected function initParameterInfo( array &$parameters ) {
-       }       
-       
-}
\ No newline at end of file

Deleted: trunk/extensions/Maps/includes/services/Maps_MappingServices.php
===================================================================
--- trunk/extensions/Maps/includes/services/Maps_MappingServices.php    
2010-09-06 12:25:25 UTC (rev 72487)
+++ trunk/extensions/Maps/includes/services/Maps_MappingServices.php    
2010-09-06 12:28:24 UTC (rev 72488)
@@ -1,222 +0,0 @@
-<?php
-
-/**
- * Class for interaction with MappingService objects.
- * 
- * @since 0.6.6
- * 
- * @file Maps_MappingServices.php
- * @ingroup Maps
- * 
- * @author Jeroen De Dauw
- */
-final class MapsMappingServices {
-       
-       /**
-        * Accociative array containing service identifiers as keys and the 
names
-        * of service classes as values.
-        * 
-        * @since 0.6.6
-        * 
-        * @var array of string
-        */
-       protected static $registeredServices = array();
-       
-       /**
-        * Accociative with service identifiers as keys containing instances of
-        * the mapping service classes. 
-        * 
-        * Note: This list only contains the instances, so is not to be used for
-        * looping over all available services, as not all of them are 
guaranteed 
-        * to have an instance already, use $registeredServices for this 
purpouse.
-        * 
-        * @since 0.6.6
-        * 
-        * @var array of iMappingService
-        */
-       protected static $services = array();
-       
-       /**
-        * Registeres a service class linked to an identifier. 
-        * Also allows automatic registration of a list of features for this 
service.
-        * 
-        * @since 0.6.6
-        * 
-        * @param $serviceIdentifier String: internal service identifier
-        * @param $serviceClassName String
-        * @param $features Array
-        */
-       public static function registerService( $serviceIdentifier, 
$serviceClassName, array $features = array() ) {
-               self::$registeredServices[$serviceIdentifier] = 
$serviceClassName;
-               
-               foreach( $features as $featureName => $featureClassName ) {
-                       self::registerServiceFeature( $serviceIdentifier, 
$featureName, $featureClassName );
-               }
-       }
-       
-       /**
-        * Registeres a feature for a service object.
-        * Registers a warning when the service is not registered, but does not 
give an error.
-        * 
-        * @since 0.6.6
-        * 
-        * @param $serviceIdentifier String: internal service identifier
-        * @param $featureName String
-        * @param $featureClassName String
-        */
-       public static function registerServiceFeature( $serviceIdentifier, 
$featureName, $featureClassName ) {
-               if ( array_key_exists( $serviceIdentifier, 
self::$registeredServices ) ) {
-                       $service = self::getServiceInstance( $serviceIdentifier 
);
-                       $service->addFeature( $featureName, $featureClassName 
);                        
-               }
-               else {
-                       // If the feature is not registered, register a 
warning. This is not an error though!
-                       wfWarn( "Tried to register feature '$featureName' with 
class '$featureClassName' to non-registered service '$serviceIdentifier'." );
-               }
-       }
-       
-       /**
-        * Returns the instance of a service class. This method takes
-        * care of creating the instance if this is not done yet.
-        * 
-        * @since 0.6.6
-        * 
-        * @param $serviceIdentifier String: internal service identifier
-        * 
-        * @return iMappingService
-        */
-       public static function getServiceInstance( $serviceIdentifier ) {
-               if ( !array_key_exists( $serviceIdentifier, self::$services ) ) 
{
-                       if ( array_key_exists( $serviceIdentifier, 
self::$registeredServices ) ) {
-                               $service = new 
self::$registeredServices[$serviceIdentifier]( $serviceIdentifier );
-                               
-                               if ( $service instanceof iMappingService ) {
-                                       self::$services[$serviceIdentifier] = 
$service;
-                               }
-                               else {
-                                       throw new Exception( 'The service 
object linked to service identifier ' . $serviceIdentifier . ' does not 
implement iMappingService.' );
-                               }
-                       }
-                       else {
-                               throw new Exception( 'There is no service 
object linked to service identifier ' . $serviceIdentifier . '.' );
-                       }
-               }
-
-               return self::$services[$serviceIdentifier];
-       }
-       
-       /**
-        * Retuns an instance of a MapsMappingService. The service name is 
validated
-        * and aliases are resolved and a check is made if the feature is 
supported.
-        * If the feature is not supported, or the service does not exist, 
defaulting
-        * will be used.
-        * 
-        * @since 0.6.6
-        * 
-        * @param $service String: service name or alias, does not need to be 
secure
-        * @param $feature String
-        * 
-        * @return iMappingService
-        */
-       public static function getValidServiceInstance( $service, $feature ) {
-               return self::getServiceInstance( self::getValidServiceName( 
$service, $feature ) );
-       }
-       
-       /**
-        * Returns a valid service. When an invalid service is provided, the 
default one will be returned.
-        * Aliases are also changed into the main service names @see 
MapsMappingServices::getMainServiceName.
-        *
-        * @since 0.6.6
-        *
-        * @param $service String: service name or alias, does not need to be 
secure
-        * @param $feature String
-        *
-        * @return string
-        */
-       public static function getValidServiceName( $service, $feature ) {
-               global $egMapsDefaultService, $egMapsDefaultServices;
-
-               // Get rid of any aliases.
-               // Also rely on this to instantiate all registered services.
-               $service = self::getMainServiceName( $service );
-               
-               // Check if there is a mathing instance.
-               $shouldChange = !array_key_exists( $service, self::$services );
-               
-               // If it should not be changed, ensure the service supports 
this feature.
-               if ( !$shouldChange ) {
-                       $shouldChange = self::getServiceInstance( $service 
)->getFeature( $feature ) === false;
-               }
-
-               // Change the service to the most specific default value 
available.
-               // Note: the default services should support their 
corresponding features.
-               // If they don't, a fatal error will occur later on.
-               if ( $shouldChange ) {
-                       if ( array_key_exists( $feature, $egMapsDefaultServices 
) ) {
-                               $service = $egMapsDefaultServices[$feature];
-                       }
-                       else {
-                               $service = $egMapsDefaultService;
-                       }
-               }
-
-               return $service;
-       }
-
-       /**
-        * Returns an array with the identifiers for all registered services.
-        * 
-        * @since 0.6.6
-        * 
-        * @return array
-        */
-       public static function getServiceIdentifiers() {
-               return array_keys( self::$registeredServices );
-       }
-       
-       /**
-        * Checks if the service name is an alias for an actual service,
-        * and changes it into the main service name if this is the case.
-        *
-        * @since 0.6.6
-        *
-        * @param $serviceName String: service name or alias, does not need to 
be secure
-        * 
-        * @return string
-        */
-       protected static function getMainServiceName( $serviceName ) {
-               if ( !array_key_exists( $serviceName, self::$services ) ) {
-                       foreach ( self::getServiceIdentifiers() as 
$serviceIdentifier ) {
-                               $service = self::getServiceInstance( 
$serviceIdentifier );
-
-                               if ( $service->hasAlias( $serviceName ) ) {
-                                        $serviceName = $service->getName();
-                                        break;
-                               }
-                       }
-               }
-               
-               return $serviceName;
-       }
-       
-       /**
-        * Returns an array containing all the possible values for the service 
parameter, including aliases.
-        *
-        * @since 0.6.6
-        *
-        * @return array
-        */
-       public static function getAllServiceValues() {
-               global $egMapsAvailableServices;
-
-               $allServiceValues = array();
-
-               foreach ( $egMapsAvailableServices as $availableService ) {
-                       $allServiceValues[] = $availableService;
-                       $allServiceValues = array_merge( $allServiceValues, 
self::getServiceInstance( $availableService )->getAliases() );
-               }
-
-               return $allServiceValues;
-       }       
-       
-}
\ No newline at end of file

Deleted: trunk/extensions/Maps/includes/services/iMappingService.php
===================================================================
--- trunk/extensions/Maps/includes/services/iMappingService.php 2010-09-06 
12:25:25 UTC (rev 72487)
+++ trunk/extensions/Maps/includes/services/iMappingService.php 2010-09-06 
12:28:24 UTC (rev 72488)
@@ -1,158 +0,0 @@
-<?php
-
-/**
- * File holding interface iMapParserFunction.
- * 
- * @file iMappingService.php
- * @ingroup Maps
- * 
- * @author Jeroen De Dauw
- */
-
-if ( !defined( 'MEDIAWIKI' ) ) {
-       die( 'Not an entry point.' );
-}
-
-/**
- * Interface that should be implemented by all mapping feature classes.
- * 
- * @since 0.6.3
- * 
- * @author Jeroen De Dauw
- */
-interface iMappingService {
-       
-       /**
-        * Returns the internal name of the service.
-        * 
-        * @since 0.6.5
-        * 
-        * @return string
-        */     
-       function getName();
-       
-       /**
-        * Adds the dependencies to the parser output as head items.
-        * 
-        * @since 0.6.3
-        * 
-        * @param mixed $parserOrOut
-        */
-       function addDependencies( &$parserOrOut );
-       
-       /**
-        * Returns an array that specifies the parameters supported by this 
service,
-        * together with their meta-data. This is in a format usable by 
Validator.
-        * 
-        * @since 0.6.3
-        * 
-        * @return array
-        */
-       function getParameterInfo();
-       
-       /**
-        * Adds a dependency that is needed for this service. It will be passed 
along with the next 
-        * call to getDependencyHtml or addDependencies.
-        * 
-        * @since 0.6.5
-        * 
-        * @param string $dependencyHtml
-        */     
-       function addDependency( $dependencyHtml );
-       
-       /**
-        * Adds a feature to this service. This is to indicate this service has 
support for this feature.
-        * 
-        * @since 0.6.5
-        * 
-        * @param string $featureName
-        * @param string $handlingClass
-        */     
-       function addFeature( $featureName, $handlingClass );
-       
-       /**
-        * Returns the html for the needed dependencies or false.
-        * 
-        * @since 0.6.5
-        * 
-        * @return mixed String or false
-        */     
-       function getDependencyHtml();
-       
-       /**
-        * Returns the name of the class that handles the provided feature in 
this service, or false if there is none.
-        * 
-        * @since 0.6.5
-        * 
-        * @param string $featureName.
-        * 
-        * @return mixed String or false
-        */     
-       function getFeature( $featureName );
-       
-       /**
-        * Returns an instance of the class handling the provided feature with 
this service, or false if there is none.
-        * 
-        * @since 0.6.6
-        * 
-        * @param string $featureName.
-        * 
-        * @return iMappingFeature or false
-        */     
-       function getFeatureInstance( $featureName );    
-       
-       /**
-        * Returns a list of aliases.
-        * 
-        * @since 0.6.5
-        * 
-        * @return array
-        */     
-       function getAliases();
-       
-       /**
-        * Returns if the service has a certain alias or not.
-        * 
-        * @since 0.6.5
-        * 
-        * @param string $alias
-        * 
-        * @return boolean
-        */     
-       function hasAlias( $alias );
-       
-       /**
-        * Returns the default zoomlevel for the mapping service.
-        * 
-        * @since 0.6.5
-        * 
-        * @return integer
-        */
-       function getDefaultZoom();
-       
-       /**
-        * Returns a string that can be used as an unique ID for the map html 
element.
-        * Increments the number by default, providing false for $increment 
will get
-        * you the same ID as on the last request.
-        * 
-        * @since 0.6.5
-        * 
-        * @param boolean $increment
-        * 
-        * @return string
-        */
-       function getMapId( $increment = true );
-
-       /**
-        * Creates a JS array with marker meta data that can be used to 
construct a 
-        * map with markers via a function in this services JS file.
-        * 
-        * @since 0.6.5
-        * 
-        * @param array $markers
-        * 
-        * @return string
-        */     
-       function createMarkersJs( array $markers );     
-
-}
\ No newline at end of file



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to