r64428 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64427‎ | r64428 | r64429 >
Date:07:11, 31 March 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6 - follow up on r64422
Modified paths:
  • /trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMaps.php (modified) (history)
  • /trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayers.php (modified) (history)
  • /trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSM.php (modified) (history)
  • /trunk/extensions/SemanticMaps/QueryPrinters/SM_Mapper.php (modified) (history)
  • /trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SM_Settings.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)
  • /trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMaps.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMaps.php
@@ -20,5 +20,8 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -$egMapsServices['yahoomaps']['qp'] = array( 'class' => 'SMYahooMapsQP', 'file' => 'YahooMaps/SM_YahooMapsQP.php', 'local' => true );
25 -$egMapsServices['yahoomaps']['fi'] = array( 'class' => 'SMYahooMapsFormInput', 'file' => 'YahooMaps/SM_YahooMapsFormInput.php', 'local' => true );
\ No newline at end of file
 24+$wgAutoloadClasses['SMYahooMapsQP'] = dirname( __FILE__ ) . '/SM_YahooMapsQP.php';
 25+$wgAutoloadClasses['SMYahooMapsFormInput'] = dirname( __FILE__ ) . '/SM_YahooMapsFormInput.php';
 26+
 27+$egMapsServices['yahoomaps']['features']['qp'] = 'SMYahooMapsQP';
 28+$egMapsServices['yahoomaps']['features']['fi'] = 'SMYahooMapsFormInput';
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayers.php
@@ -20,5 +20,8 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -$egMapsServices['openlayers']['qp'] = array( 'class' => 'SMOpenLayersQP', 'file' => 'OpenLayers/SM_OpenLayersQP.php', 'local' => true );
25 -$egMapsServices['openlayers']['fi'] = array( 'class' => 'SMOpenLayersFormInput', 'file' => 'OpenLayers/SM_OpenLayersFormInput.php', 'local' => true );
\ No newline at end of file
 24+$wgAutoloadClasses['SMOpenLayersQP'] = dirname( __FILE__ ) . '/SM_OpenLayersQP.php';
 25+$wgAutoloadClasses['SMOpenLayersFormInput'] = dirname( __FILE__ ) . '/SM_OpenLayersFormInput.php';
 26+
 27+$egMapsServices['openlayers']['features']['qp'] = 'SMOpenLayersQP';
 28+$egMapsServices['openlayers']['features']['fi'] = 'SMOpenLayersFormInput';
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/SM_Settings.php
@@ -25,22 +25,13 @@
2626 # (named) Array of String. This array contains the available features for Maps.
2727 # The array element name contains an abbriviation, used for code references,
2828 # and in the service data arrays, the value is the human readible version for displaying purpouses.
29 -$egMapsAvailableFeatures['qp'] = array(
30 - 'name' => 'Query Printer',
31 - 'class' => 'SMQueryPrinters',
32 - 'file' => 'SemanticMaps/QueryPrinters/SM_QueryPrinters.php'
33 - );
 29+include_once $smgDir . 'QueryPrinters/SM_QueryPrinters.php'; // Query printers
 30+include_once $smgDir . 'FormInputs/SM_FormInputs.php'; // Form imputs
3431
35 -$egMapsAvailableFeatures['fi'] = array(
36 - 'name' => 'Form input',
37 - 'class' => 'SMFormInputs',
38 - 'file' => 'SemanticMaps/FormInputs/SM_FormInputs.php'
39 - );
4032
4133
4234
4335
44 -
4536 # Mapping services configuration
4637
4738 # Include the mapping services that should be loaded into Semantic Maps.
Index: trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php
@@ -13,6 +13,10 @@
1414 die( 'Not an entry point.' );
1515 }
1616
 17+$wgAutoloadClasses['SMFormInputs'] = __FILE__;
 18+
 19+$wgHooks['MappingFeatureLoad'][] = 'SMFormInputs::initialize';
 20+
1721 final class SMFormInputs {
1822
1923 public static $parameters = array();
@@ -24,13 +28,13 @@
2529 if ( isset( $sfgFormPrinter ) ) {
2630 $hasFormInputs = false;
2731
28 - $wgAutoloadClasses['SMFormInput'] = $smgDir . 'FormInputs/SM_FormInput.php';
 32+ $wgAutoloadClasses['SMFormInput'] = dirname( __FILE__ ) . '/SM_FormInput.php';
2933
3034 self::initializeParams();
3135
3236 foreach ( $egMapsServices as $serviceName => $serviceData ) {
3337 // Check if the service has a form input
34 - $hasFI = array_key_exists( 'fi', $serviceData );
 38+ $hasFI = array_key_exists( 'fi', $serviceData['features'] );
3539
3640 // If the service has no FI, skipt it and continue with the next one.
3741 if ( !$hasFI ) continue;
@@ -39,15 +43,17 @@
4044 $hasFormInputs = true;
4145
4246 // Add the result form input type for the service name.
43 - self::initFormHook( $serviceName, $serviceData['fi'], $serviceName );
 47+ self::initFormHook( $serviceName, $serviceName );
4448
4549 // Loop through the service alliases, and add them as form input types.
46 - foreach ( $serviceData['aliases'] as $alias ) self::initFormHook( $alias, $serviceData['fi'], $serviceName );
 50+ foreach ( $serviceData['aliases'] as $alias ) self::initFormHook( $alias, $serviceName );
4751 }
4852
4953 // Add the 'map' form input type if there are mapping services that have FI's loaded.
5054 if ( $hasFormInputs ) self::initFormHook( 'map' );
5155 }
 56+
 57+ return true;
5258 }
5359
5460 private static function initializeParams() {
@@ -82,17 +88,10 @@
8389 * @param array $fi
8490 * @param strig $mainName
8591 */
86 - private static function initFormHook( $inputName, array $fi = null, $mainName = '' ) {
 92+ private static function initFormHook( $inputName, $mainName = '' ) {
8793 global $wgAutoloadClasses, $sfgFormPrinter, $smgDir;
88 -
89 - if ( isset( $fi ) ) {
90 - if ( ! array_key_exists( $fi['class'], $wgAutoloadClasses ) ) {
91 - $file = array_key_exists( 'local', $fi ) && $fi['local'] ? $smgDir . $fi['file'] : $fi['file'];
92 - $wgAutoloadClasses[$fi['class']] = $file;
93 - }
94 - }
9594
96 - // Add the form input hook for the service
 95+ // Add the form input hook for the service.
9796 $field_args = array();
9897 if ( strlen( $mainName ) > 0 ) $field_args['service_name'] = $mainName;
9998 $sfgFormPrinter->setInputTypeHook( $inputName, 'smfSelectFormInputHTML', $field_args );
@@ -124,7 +123,7 @@
125124
126125 // Ensure the service is valid and create a new instance of the handling form input class.
127126 $service_name = MapsMapper::getValidService( $service_name, 'fi' );
128 - $formInput = new $egMapsServices[$service_name]['fi']['class']();
 127+ $formInput = new $egMapsServices[$service_name]['features']['fi']();
129128
130129 // Get and return the form input HTML from the hook corresponding with the provided service.
131130 return $formInput->formInputHTML( $coordinates, $input_name, $is_mandatory, $is_disabled, $field_args );
Index: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSM.php
@@ -20,5 +20,7 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -$egMapsServices['osm']['qp'] = array( 'class' => 'SMOSMQP', 'file' => 'OpenStreetMap/SM_OSMQP.php', 'local' => true );
25 -// $egMapsServices['osm']['fi'] = array('class' => 'SMOSMFormInput', 'file' => 'extensions/SemanticMaps/OpenStreetMap/SM_OSMFormInput.php', 'local' => false);
\ No newline at end of file
 24+$wgAutoloadClasses['SMOSMQP'] = dirname( __FILE__ ) . '/SM_SMOSMQP.php';
 25+
 26+$egMapsServices['osm']['features']['qp'] = 'SMOSMQP';
 27+// $egMapsServices['osm']['features']['fi'] = 'SMOSMFormInput';
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -35,7 +35,7 @@
3636
3737 // Only initialize the extension when all dependencies are present.
3838 if ( defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' ) ) {
39 - define( 'SM_VERSION', '0.6 a7' );
 39+ define( 'SM_VERSION', '0.6 a8' );
4040
4141 $smgScriptPath = ( isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/SemanticMaps';
4242 $smgDir = dirname( __FILE__ ) . '/';
@@ -74,7 +74,11 @@
7575 'path' => __FILE__,
7676 'name' => wfMsg( 'semanticmaps_name' ),
7777 'version' => SM_VERSION,
78 - 'author' => array( '[http://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]', '[http://www.mediawiki.org/wiki/User:Yaron_Koren Yaron Koren]', 'others' ),
 78+ 'author' => array(
 79+ '[http://www.mediawiki.org/wiki/User:Jeroen_De_Dauw Jeroen De Dauw]',
 80+ '[http://www.mediawiki.org/wiki/User:Yaron_Koren Yaron Koren]',
 81+ '[http://www.ohloh.net/p/semanticmaps/contributors others]'
 82+ ),
7983 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Maps',
8084 'description' => wfMsgExt( 'semanticmaps_desc', 'parsemag', $services_list ),
8185 );
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php
@@ -13,6 +13,10 @@
1414 die( 'Not an entry point.' );
1515 }
1616
 17+$wgAutoloadClasses['SMQueryPrinters'] = __FILE__;
 18+
 19+$wgHooks['MappingFeatureLoad'][] = 'SMQueryPrinters::initialize';
 20+
1721 final class SMQueryPrinters {
1822
1923 public static $parameters = array();
@@ -22,15 +26,17 @@
2327 */
2428 public static function initialize() {
2529 global $smgDir, $wgAutoloadClasses, $egMapsServices;
26 - $wgAutoloadClasses['SMMapPrinter'] = $smgDir . 'QueryPrinters/SM_MapPrinter.php';
2730
 31+ $wgAutoloadClasses['SMMapper'] = dirname( __FILE__ ) . '/SM_Mapper.php';
 32+ $wgAutoloadClasses['SMMapPrinter'] = dirname( __FILE__ ) . '/SM_MapPrinter.php';
 33+
2834 self::initializeParams();
2935
3036 $hasQueryPrinters = false;
31 -
 37+
3238 foreach ( $egMapsServices as $serviceName => $serviceData ) {
33 - // Check if the service has a query printer
34 - $hasQP = array_key_exists( 'qp', $serviceData );
 39+ // Check if the service has a query printer.
 40+ $hasQP = array_key_exists( 'qp', $serviceData['features'] );
3541
3642 // If the service has no QP, skipt it and continue with the next one.
3743 if ( !$hasQP ) continue;
@@ -39,11 +45,13 @@
4046 $hasQueryPrinters = true;
4147
4248 // Initiate the format.
43 - self::initFormat( $serviceName, $serviceData['qp'], $serviceData['aliases'] );
 49+ self::initFormat( $serviceName, $serviceData['features']['qp'], $serviceData['aliases'] );
4450 }
4551
4652 // Add the 'map' result format if there are mapping services that have QP's loaded.
47 - if ( $hasQueryPrinters ) self::initFormat( 'map', array( 'class' => 'SMMapper', 'file' => 'QueryPrinters/SM_Mapper.php', 'local' => true ), array() );
 53+ if ( $hasQueryPrinters ) self::initFormat( 'map', 'SMMapper' );
 54+
 55+ return true;
4856 }
4957
5058 private static function initializeParams() {
@@ -127,27 +135,21 @@
128136 * Add the result format for a mapping service or alias.
129137 *
130138 * @param string $format
131 - * @param array $qp
 139+ * @param string $formatClass
132140 * @param array $aliases
133141 */
134 - private static function initFormat( $format, array $qp, array $aliases ) {
 142+ private static function initFormat( $format, $formatClass, array $aliases = array() ) {
135143 global $wgAutoloadClasses, $smgDir, $smwgResultAliases;
136144
137 - // Load the QP class when it's not loaded yet.
138 - if ( ! array_key_exists( $qp['class'], $wgAutoloadClasses ) ) {
139 - $file = array_key_exists( 'local', $qp ) && $qp['local'] ? $smgDir . $qp['file'] : $qp['file'];
140 - $wgAutoloadClasses[$qp['class']] = $file;
141 - }
142 -
143145 // Add the QP to SMW.
144 - self::addFormatQP( $format, $qp['class'] );
 146+ self::addFormatQP( $format, $formatClass );
145147
146148 // If SMW supports aliasing, add the aliases to $smwgResultAliases.
147149 if ( isset( $smwgResultAliases ) ) {
148150 $smwgResultAliases[$format] = $aliases;
149151 }
150152 else { // If SMW does not support aliasing, add every alias as a format.
151 - foreach ( $aliases as $alias ) self::addFormatQP( $alias, $qp['class'] );
 153+ foreach ( $aliases as $alias ) self::addFormatQP( $alias, $formatClass );
152154 }
153155 }
154156
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_Mapper.php
@@ -26,7 +26,7 @@
2727
2828 $service = MapsMapper::getValidService( $format, 'qp' );
2929
30 - $this->queryPrinter = new $egMapsServices[$service]['qp']['class']( $format, $inline );
 30+ $this->queryPrinter = new $egMapsServices[$service]['features']['qp']( $format, $inline );
3131 }
3232
3333 public static function getAliases() {
Index: trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMaps.php
@@ -20,5 +20,8 @@
2121 die( 'Not an entry point.' );
2222 }
2323
24 -$egMapsServices['googlemaps2']['qp'] = array( 'class' => 'SMGoogleMapsQP', 'file' => 'GoogleMaps/SM_GoogleMapsQP.php', 'local' => true );
25 -$egMapsServices['googlemaps2']['fi'] = array( 'class' => 'SMGoogleMapsFormInput', 'file' => 'GoogleMaps/SM_GoogleMapsFormInput.php', 'local' => true );
\ No newline at end of file
 24+$wgAutoloadClasses['SMGoogleMapsQP'] = dirname( __FILE__ ) . '/SM_GoogleMapsQP.php';
 25+$wgAutoloadClasses['SMGoogleMapsFormInput'] = dirname( __FILE__ ) . '/SM_GoogleMapsFormInput.php';
 26+
 27+$egMapsServices['googlemaps2']['features']['qp'] = 'SMGoogleMapsQP';
 28+$egMapsServices['googlemaps2']['features']['fi'] = 'SMGoogleMapsFormInput';
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r64422Changes for 0.6 - Mayor rewrite of how services and features are hooked.jeroendedauw05:18, 31 March 2010

Status & tagging log