Index: tags/extensions/SemanticMaps/REL_0_3_2/SemanticMaps.php |
— | — | @@ -0,0 +1,211 @@ |
| 2 | +<?php
|
| 3 | +
|
| 4 | +/**
|
| 5 | + * Initialization file for the Semantic Maps extension.
|
| 6 | + * Extension documentation: http://www.mediawiki.org/wiki/Extension:Semantic_Maps
|
| 7 | + *
|
| 8 | + * @file SemanticMaps.php
|
| 9 | + * @ingroup SemanticMaps
|
| 10 | + *
|
| 11 | + * @author Jeroen De Dauw
|
| 12 | + */
|
| 13 | +
|
| 14 | +/**
|
| 15 | + * This documenation group collects source code files belonging to Semantic Maps.
|
| 16 | + *
|
| 17 | + * Please do not use this group name for other code. If you have an extension to
|
| 18 | + * Semantic Maps, please use your own group defenition.
|
| 19 | + *
|
| 20 | + * @defgroup SemanticMaps Semantic Maps
|
| 21 | + */
|
| 22 | +
|
| 23 | +if( !defined( 'MEDIAWIKI' ) ) {
|
| 24 | + die( 'Not an entry point.' );
|
| 25 | +}
|
| 26 | +
|
| 27 | +define('SM_VERSION', '0.3.2');
|
| 28 | +
|
| 29 | +$smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps';
|
| 30 | +$smgIP = $IP . '/extensions/SemanticMaps';
|
| 31 | +
|
| 32 | +$wgExtensionFunctions[] = 'smfSetup';
|
| 33 | +
|
| 34 | +$wgHooks['AdminLinks'][] = 'smfAddToAdminLinks';
|
| 35 | +
|
| 36 | +$wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php';
|
| 37 | +
|
| 38 | +// Autoload the general classes
|
| 39 | +$wgAutoloadClasses['SMMapPrinter'] = $smgIP . '/SM_MapPrinter.php';
|
| 40 | +$wgAutoloadClasses['SMMapper'] = $smgIP . '/SM_Mapper.php';
|
| 41 | +$wgAutoloadClasses['SMFormInput'] = $smgIP . '/SM_FormInput.php';
|
| 42 | +
|
| 43 | +// Add the services
|
| 44 | +$egMapsServices['googlemaps']['qp'] = array('class' => 'SMGoogleMaps', 'file' => 'GoogleMaps/SM_GoogleMaps.php', 'local' => true);
|
| 45 | +$egMapsServices['googlemaps']['fi'] = array('class' => 'SMGoogleMapsFormInput', 'file' => 'GoogleMaps/SM_GoogleMapsFormInput.php', 'local' => true);
|
| 46 | +
|
| 47 | +$egMapsServices['yahoomaps']['qp'] = array('class' => 'SMYahooMaps', 'file' => 'YahooMaps/SM_YahooMaps.php', 'local' => true);
|
| 48 | +$egMapsServices['yahoomaps']['fi'] = array('class' => 'SMYahooMapsFormInput', 'file' => 'YahooMaps/SM_YahooMapsFormInput.php', 'local' => true);
|
| 49 | +
|
| 50 | +$egMapsServices['openlayers']['qp'] = array('class' => 'SMOpenLayers', 'file' => 'OpenLayers/SM_OpenLayers.php', 'local' => true);
|
| 51 | +$egMapsServices['openlayers']['fi'] = array('class' => 'SMOpenLayersFormInput', 'file' => 'OpenLayers/SM_OpenLayersFormInput.php', 'local' => true);
|
| 52 | +
|
| 53 | +/**
|
| 54 | + * Initialization function for the Semantic Maps extension
|
| 55 | + *
|
| 56 | + */
|
| 57 | +function smfSetup() {
|
| 58 | + global $wgExtensionCredits, $egMapsServices;
|
| 59 | +
|
| 60 | + $services_list = implode(', ', array_keys($egMapsServices));
|
| 61 | + $services_count = count( $egMapsServices );
|
| 62 | +
|
| 63 | + wfLoadExtensionMessages( 'SemanticMaps' );
|
| 64 | +
|
| 65 | + $wgExtensionCredits['other'][]= array(
|
| 66 | + 'path' => __FILE__,
|
| 67 | + 'name' => wfMsg('semanticmaps_name'),
|
| 68 | + 'version' => SM_VERSION,
|
| 69 | + 'author' => array("[http://bn2vs.com Jeroen De Dauw]", "Yaron Koren", "Robert Buzink"),
|
| 70 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Maps',
|
| 71 | + 'description' => wfMsgExt( 'semanticmaps_desc', 'parsemag', $services_list, $services_count ),
|
| 72 | + 'descriptionmsg' => wfMsgExt( 'semanticmaps_desc', 'parsemag', $services_list, $services_count ),
|
| 73 | + );
|
| 74 | +
|
| 75 | + smfInitFormHook('map');
|
| 76 | + smfInitFormat('map', array('class' => 'SMMapper', 'file' => 'SM_Mapper.php', 'local' => true));
|
| 77 | +
|
| 78 | + foreach($egMapsServices as $serviceName => $serviceData) {
|
| 79 | + $hasQP = array_key_exists('qp', $serviceData);
|
| 80 | + $hasFI = array_key_exists('fi', $serviceData);
|
| 81 | +
|
| 82 | + // If the service has no QP and no FI, skipt it and continue with the next one.
|
| 83 | + if (!$hasQP && !$hasFI) continue;
|
| 84 | +
|
| 85 | + // Add the result format and form input type for the service name when needed.
|
| 86 | + if ($hasQP) smfInitFormat($serviceName, $serviceData['qp']);
|
| 87 | + if ($hasFI) smfInitFormHook($serviceName, $serviceData['fi']);
|
| 88 | +
|
| 89 | + // Loop through the service alliases, and add them as result formats and form input types when needed.
|
| 90 | + foreach ($serviceData['aliases'] as $alias) {
|
| 91 | + if ($hasQP) smfInitFormat($alias, $serviceData['qp']);
|
| 92 | + if ($hasFI) smfInitFormHook($alias, $serviceData['fi'], $serviceName);
|
| 93 | + }
|
| 94 | + }
|
| 95 | +
|
| 96 | +}
|
| 97 | +
|
| 98 | +/**
|
| 99 | + * Add the result format for a mapping service or alias
|
| 100 | + *
|
| 101 | + * @param string $format
|
| 102 | + * @param array $qp
|
| 103 | + */
|
| 104 | +function smfInitFormat($format, array $qp) {
|
| 105 | + global $wgAutoloadClasses, $smwgResultFormats, $smgIP;
|
| 106 | +
|
| 107 | + if (! array_key_exists($qp['class'], $wgAutoloadClasses)) {
|
| 108 | + $file = $qp['local'] ? $smgIP . '/' . $qp['file'] : $qp['file'];
|
| 109 | + $wgAutoloadClasses[$qp['class']] = $file;
|
| 110 | + }
|
| 111 | +
|
| 112 | + if (isset($smwgResultFormats)) {
|
| 113 | + $smwgResultFormats[$format] = $qp['class'];
|
| 114 | + }
|
| 115 | + else {
|
| 116 | + SMWQueryProcessor::$formats[$format] = $qp['class'];
|
| 117 | + }
|
| 118 | +}
|
| 119 | +
|
| 120 | +/**
|
| 121 | + * Adds a mapping service's form hook
|
| 122 | + *
|
| 123 | + * @param string $service
|
| 124 | + * @param array $fi
|
| 125 | + * @param strig $mainName
|
| 126 | + */
|
| 127 | +function smfInitFormHook($service, array $fi = null, $mainName = '') {
|
| 128 | + global $wgAutoloadClasses, $sfgFormPrinter, $smgIP;
|
| 129 | +
|
| 130 | + if (isset($fi)) {
|
| 131 | + if (! array_key_exists($fi['class'], $wgAutoloadClasses)) {
|
| 132 | + $file = $fi['local'] ? $smgIP . '/' . $fi['file'] : $fi['file'];
|
| 133 | + $wgAutoloadClasses[$fi['class']] = $file;
|
| 134 | + }
|
| 135 | + }
|
| 136 | +
|
| 137 | + // Add the form input hook for the service
|
| 138 | + $field_args = array();
|
| 139 | + if (strlen($mainName) > 0) $field_args['service_name'] = $mainName;
|
| 140 | + $sfgFormPrinter->setInputTypeHook($service, 'smfSelectFormInputHTML', $field_args);
|
| 141 | +}
|
| 142 | +
|
| 143 | +/**
|
| 144 | + * Class for the form input type 'map'. The relevant form input class is called depending on the provided service.
|
| 145 | + *
|
| 146 | + * @param unknown_type $coordinates
|
| 147 | + * @param unknown_type $input_name
|
| 148 | + * @param unknown_type $is_mandatory
|
| 149 | + * @param unknown_type $is_disabled
|
| 150 | + * @param array $field_args
|
| 151 | + * @return unknown
|
| 152 | + */
|
| 153 | +function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args) {
|
| 154 | + global $egMapsServices;
|
| 155 | +
|
| 156 | + // If service_name is set, use this value, and ignore any given
|
| 157 | + // service parameters
|
| 158 | + // This will prevent ..input type=googlemaps|service=yahoo.. from
|
| 159 | + // showing up as a Yahoo! Maps map
|
| 160 | + if (array_key_exists('service_name', $field_args)) {
|
| 161 | + $service_name = $field_args['service_name'];
|
| 162 | + }
|
| 163 | + elseif (array_key_exists('service', $field_args)) {
|
| 164 | + $service_name = $field_args['service'];
|
| 165 | + }
|
| 166 | + else{
|
| 167 | + $service_name = null;
|
| 168 | + }
|
| 169 | +
|
| 170 | + $service_name = MapsMapper::getValidService($service_name, 'fi');
|
| 171 | +
|
| 172 | + if (array_key_exists('fi', $egMapsServices[$service_name])) {
|
| 173 | + $formInput = new $egMapsServices[$service_name]['fi']['class']();
|
| 174 | +
|
| 175 | + // Get and return the form input HTML from the hook corresponding with the provided service
|
| 176 | + return $formInput->formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args);
|
| 177 | + }
|
| 178 | + else {
|
| 179 | + return "<b>ERROR: Form input for ".$field_args['service']." not found</b>";
|
| 180 | + }
|
| 181 | +
|
| 182 | +}
|
| 183 | +
|
| 184 | +/**
|
| 185 | + * Returns html for an html input field with a default value that will automatically dissapear when
|
| 186 | + * the user clicks in it, and reappers when the focus on the field is lost and it's still empty.
|
| 187 | + *
|
| 188 | + * @param string $id
|
| 189 | + * @param string $value
|
| 190 | + * @param string $args
|
| 191 | + * @return html
|
| 192 | + */
|
| 193 | +function smfGetDynamicInput($id, $value, $args='') {
|
| 194 | + // By De Dauw Jeroen - November 2008 - http://code.bn2vs.com/viewtopic.php?t=120
|
| 195 | + return '<input id="'.$id.'" '.$args.' value="'.$value.'" onfocus="if (this.value==\''.$value.'\') {this.value=\'\';}" onblur="if (this.value==\'\') {this.value=\''.$value.'\';}" />';
|
| 196 | +}
|
| 197 | +
|
| 198 | +/**
|
| 199 | + * Adds a link to Admin Links page
|
| 200 | + */
|
| 201 | +function smfAddToAdminLinks(&$admin_links_tree) {
|
| 202 | + $displaying_data_section = $admin_links_tree->getSection(wfMsg('smw_adminlinks_displayingdata'));
|
| 203 | + // Escape if SMW hasn't added links
|
| 204 | + if (is_null($displaying_data_section))
|
| 205 | + return true;
|
| 206 | + $smw_docu_row = $displaying_data_section->getRow('smw');
|
| 207 | + wfLoadExtensionMessages('SemanticMaps');
|
| 208 | + $sm_docu_label = wfMsg('adminlinks_documentation', wfMsg('semanticmaps_name'));
|
| 209 | + $smw_docu_row->addItem(AlItem::newFromExternalLink("http://www.mediawiki.org/wiki/Extension:Semantic_Maps", $sm_docu_label));
|
| 210 | + return true;
|
| 211 | +}
|
| 212 | +
|