r54219 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54218‎ | r54219 | r54220 >
Date:18:06, 2 August 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Modified paths:
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -1,5 +1,5 @@
22 <?php
3 -
 3+
44 /**
55 * Initialization file for the Semantic Maps extension.
66 * Extension documentation: http://www.mediawiki.org/wiki/Extension:Semantic_Maps
@@ -14,7 +14,7 @@
1515 die( 'Not an entry point.' );
1616 }
1717
18 -define('SM_VERSION', '0.2');
 18+define('SM_VERSION', '0.3');
1919
2020 $smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps';
2121 $smgIP = $IP . '/extensions/SemanticMaps';
@@ -30,11 +30,19 @@
3131 $wgAutoloadClasses['SMMapper'] = $smgIP . '/SM_Mapper.php';
3232 $wgAutoloadClasses['SMFormInput'] = $smgIP . '/SM_FormInput.php';
3333
34 -function smfSetup() {
35 - global $wgExtensionCredits, $egMapsServices, $egMapsMainServices, $wgParser, $wgExtensionCredits;
 34+// Add the services
 35+$egMapsServices['googlemaps']['qp'] = array('class' => 'SMGoogleMaps', 'file' => 'GoogleMaps/SM_GoogleMaps.php');
 36+$egMapsServices['googlemaps']['fi'] = array('class' => 'SMGoogleMapsFormInput', 'file' => 'GoogleMaps/SM_GoogleMapsFormInput.php');
3637
37 - foreach($egMapsMainServices as $service) smfInitFormat($service);
 38+$egMapsServices['yahoomaps']['qp'] = array('class' => 'SMYahooMaps', 'file' => 'YahooMaps/SM_YahooMaps.php');
 39+$egMapsServices['yahoomaps']['fi'] = array('class' => 'SMYahooMapsFormInput', 'file' => 'YahooMaps/SM_YahooMapsFormInput.php');
3840
 41+$egMapsServices['openlayers']['qp'] = array('class' => 'SMOpenLayers', 'file' => 'OpenLayers/SM_OpenLayers.php');
 42+$egMapsServices['openlayers']['fi'] = array('class' => 'SMOpenLayersFormInput', 'file' => 'OpenLayers/SM_OpenLayersFormInput.php');
 43+
 44+function smfSetup() {
 45+ global $wgExtensionCredits, $egMapsMainServices, $egMapsServices;
 46+
3947 $services_list = implode(', ', $egMapsMainServices);
4048
4149 wfLoadExtensionMessages( 'SemanticMaps' );
@@ -46,48 +54,39 @@
4755 'author' => array("[http://bn2vs.com Jeroen De Dauw]", "Yaron Koren", "Robert Buzink"),
4856 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Maps',
4957 'description' => wfMsg( 'semanticmaps_desc', $services_list ),
50 - 'descriptionmsg' => array( 'semanticmaps_desc', $services_list ),
 58+ 'descriptionmsg' => wfMsg( 'semanticmaps_desc', $services_list ),
5159 );
5260
53 - smfInitializeService('map', 'SMMapper');
 61+ smfInitFormHook('map');
 62+ smfInitFormat('map', array('class' => 'SMMapper', 'file' => 'SM_Mapper.php'));
5463
55 - smfInitializeServiceAliases('googlemaps', 'SMGoogleMaps');
56 - smfInitializeServiceAliases('yahoomaps', 'SMYahooMaps');
57 - smfInitializeServiceAliases('openlayers', 'SMOpenLayers');
58 -}
59 -
60 -/**
61 - * Apply smfInitializeService() to a service and all it's aliases.
62 - *
63 - * @param unknown_type $mainServiceName
64 - * @param unknown_type $queryPrinter
65 - */
66 -function smfInitializeServiceAliases($mainServiceName, $queryPrinter) {
67 - global $egMapsServices;
 64+ foreach($egMapsServices as $serviceName => $serviceData) {
 65+ $hasQP = array_key_exists('qp', $serviceData);
 66+ $hasFI = array_key_exists('fi', $serviceData);
 67+
 68+ if ($hasQP) smfInitFormat($serviceName, $serviceData['qp']);
 69+ if ($hasFI) smfInitFormHook($serviceName, $serviceData['fi']);
 70+
 71+ foreach ($serviceData['aliases'] as $alias) {
 72+ if ($hasQP) smfInitFormat($alias, $serviceData['qp']);
 73+ if ($hasFI) smfInitFormHook($alias, $serviceData['fi'], $serviceName);
 74+ }
 75+ }
6876
69 - smfInitializeService($mainServiceName, $queryPrinter, $mainServiceName);
70 - foreach ($egMapsServices[$mainServiceName] as $alias) smfInitializeService($alias, $queryPrinter, $mainServiceName);
7177 }
7278
7379 /**
74 - * Add the service name as result format for the provided query printer,
75 - * and set a hook for it's form input.
 80+ * Adds a mapping service's form hook
7681 *
7782 * @param unknown_type $service
78 - * @param unknown_type $queryPrinter
7983 * @param unknown_type $mainName
8084 */
81 -function smfInitializeService($service, $queryPrinter, $mainName = '') {
82 - global $smwgResultFormats, $sfgFormPrinter;
83 -
84 - // Check if $smwgResultFormats, a global variable introduced in SMW 1.2.2, is set
85 - // and add the query printer to the result format.
86 - if (isset($smwgResultFormats)) {
87 - $smwgResultFormats[$service] = $queryPrinter;
 85+function smfInitFormHook($service, $fi = null, $mainName = '') {
 86+ global $wgAutoloadClasses, $sfgFormPrinter, $smgIP;
 87+
 88+ if (isset($fi)) {
 89+ if (! array_key_exists($fi['class'], $wgAutoloadClasses)) $wgAutoloadClasses[$fi['class']] = $smgIP . '/' . $fi['file'];
8890 }
89 - else {
90 - SMWQueryProcessor::$formats[$service] = $queryPrinter;
91 - }
9291
9392 // Add the form input hook for the service
9493 $field_args = array();
@@ -96,32 +95,22 @@
9796 }
9897
9998 /**
100 - * Initialize the result format depending on the map service
 99+ * Add the result format for a mapping service or alias
 100+ *
 101+ * @param unknown_type $format
 102+ * @param unknown_type $qp
101103 */
102 -function smfInitFormat( $format ) {
103 - global $smwgResultFormats, $wgAutoloadClasses, $smgIP;
104 -
105 - switch ($format) {
106 - case 'googlemaps':
107 - $class = 'SMGoogleMaps';
108 - $file = $smgIP . '/GoogleMaps/SM_GoogleMaps';
109 - break;
110 - case 'openlayers':
111 - $class = 'SMOpenLayers';
112 - $file = $smgIP . '/OpenLayers/SM_OpenLayers';
113 - break;
114 - case 'yahoomaps':
115 - $class = 'SMYahooMaps';
116 - $file = $smgIP . '/YahooMaps/SM_YahooMaps';
117 - break;
 104+function smfInitFormat($format, $qp) {
 105+ global $wgAutoloadClasses, $smwgResultFormats, $smgIP;
 106+
 107+ if (! array_key_exists($qp['class'], $wgAutoloadClasses)) $wgAutoloadClasses[$qp['class']] = $smgIP . '/' . $qp['file'];
 108+
 109+ if (isset($smwgResultFormats)) {
 110+ $smwgResultFormats[$format] = $qp['class'];
118111 }
119 -
120 - if (isset($class) && isset($file)) {
121 - $smwgResultFormats[$format] = $class;
122 - $wgAutoloadClasses[$class] = $file . ".php";
123 - $wgAutoloadClasses[$class . "FormInput"] = $file . "FormInput.php";
124 - }
125 -
 112+ else {
 113+ SMWQueryProcessor::$formats[$format] = $qp['class'];
 114+ }
126115 }
127116
128117 /**
@@ -135,14 +124,13 @@
136125 * @return unknown
137126 */
138127 function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args) {
139 - global $egMapsAvailableServices, $egMapsDefaultService;
140 -
141128 // If service_name is set, use this value, and ignore any given service parameters
142129 // This will prevent ..input type=googlemaps|service=yahoo.. from shwoing up a Yahoo! Maps map
143130 if (array_key_exists('service_name', $field_args)) $field_args['service'] = $field_args['service_name'];
144131
145132 $field_args['service'] = MapsMapper::getValidService($field_args['service']);
146133
 134+ // TODO: get class from hook system afetr check if fi is available
147135 // Create an instace of
148136 switch ($field_args['service']) {
149137 case 'googlemaps' :

Status & tagging log