Index: trunk/extensions/SemanticMaps/SemanticMaps.php |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | + |
4 | 4 | /** |
5 | 5 | * Initialization file for the Semantic Maps extension. |
6 | 6 | * Extension documentation: http://www.mediawiki.org/wiki/Extension:Semantic_Maps |
— | — | @@ -14,7 +14,7 @@ |
15 | 15 | die( 'Not an entry point.' ); |
16 | 16 | } |
17 | 17 | |
18 | | -define('SM_VERSION', '0.2'); |
| 18 | +define('SM_VERSION', '0.3'); |
19 | 19 | |
20 | 20 | $smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps'; |
21 | 21 | $smgIP = $IP . '/extensions/SemanticMaps'; |
— | — | @@ -30,11 +30,19 @@ |
31 | 31 | $wgAutoloadClasses['SMMapper'] = $smgIP . '/SM_Mapper.php'; |
32 | 32 | $wgAutoloadClasses['SMFormInput'] = $smgIP . '/SM_FormInput.php'; |
33 | 33 | |
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'); |
36 | 37 | |
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'); |
38 | 40 | |
| 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 | + |
39 | 47 | $services_list = implode(', ', $egMapsMainServices); |
40 | 48 | |
41 | 49 | wfLoadExtensionMessages( 'SemanticMaps' ); |
— | — | @@ -46,48 +54,39 @@ |
47 | 55 | 'author' => array("[http://bn2vs.com Jeroen De Dauw]", "Yaron Koren", "Robert Buzink"), |
48 | 56 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Maps', |
49 | 57 | 'description' => wfMsg( 'semanticmaps_desc', $services_list ), |
50 | | - 'descriptionmsg' => array( 'semanticmaps_desc', $services_list ), |
| 58 | + 'descriptionmsg' => wfMsg( 'semanticmaps_desc', $services_list ), |
51 | 59 | ); |
52 | 60 | |
53 | | - smfInitializeService('map', 'SMMapper'); |
| 61 | + smfInitFormHook('map'); |
| 62 | + smfInitFormat('map', array('class' => 'SMMapper', 'file' => 'SM_Mapper.php')); |
54 | 63 | |
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 | + } |
68 | 76 | |
69 | | - smfInitializeService($mainServiceName, $queryPrinter, $mainServiceName); |
70 | | - foreach ($egMapsServices[$mainServiceName] as $alias) smfInitializeService($alias, $queryPrinter, $mainServiceName); |
71 | 77 | } |
72 | 78 | |
73 | 79 | /** |
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 |
76 | 81 | * |
77 | 82 | * @param unknown_type $service |
78 | | - * @param unknown_type $queryPrinter |
79 | 83 | * @param unknown_type $mainName |
80 | 84 | */ |
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']; |
88 | 90 | } |
89 | | - else { |
90 | | - SMWQueryProcessor::$formats[$service] = $queryPrinter; |
91 | | - } |
92 | 91 | |
93 | 92 | // Add the form input hook for the service |
94 | 93 | $field_args = array(); |
— | — | @@ -96,32 +95,22 @@ |
97 | 96 | } |
98 | 97 | |
99 | 98 | /** |
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 |
101 | 103 | */ |
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']; |
118 | 111 | } |
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 | + } |
126 | 115 | } |
127 | 116 | |
128 | 117 | /** |
— | — | @@ -135,14 +124,13 @@ |
136 | 125 | * @return unknown |
137 | 126 | */ |
138 | 127 | function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args) { |
139 | | - global $egMapsAvailableServices, $egMapsDefaultService; |
140 | | - |
141 | 128 | // If service_name is set, use this value, and ignore any given service parameters |
142 | 129 | // This will prevent ..input type=googlemaps|service=yahoo.. from shwoing up a Yahoo! Maps map |
143 | 130 | if (array_key_exists('service_name', $field_args)) $field_args['service'] = $field_args['service_name']; |
144 | 131 | |
145 | 132 | $field_args['service'] = MapsMapper::getValidService($field_args['service']); |
146 | 133 | |
| 134 | + // TODO: get class from hook system afetr check if fi is available |
147 | 135 | // Create an instace of |
148 | 136 | switch ($field_args['service']) { |
149 | 137 | case 'googlemaps' : |