r54187 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54186‎ | r54187 | r54188 >
Date:21:13, 1 August 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Modified paths:
  • /tags/extensions/SemanticMaps/REL_0_2_2/SemanticMaps.php (added) (history)

Diff [purge]

Index: tags/extensions/SemanticMaps/REL_0_2_2/SemanticMaps.php
@@ -0,0 +1,190 @@
 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+if( !defined( 'MEDIAWIKI' ) ) {
 15+ die( 'Not an entry point.' );
 16+}
 17+
 18+define('SM_VERSION', '0.3');
 19+
 20+$smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps';
 21+$smgIP = $IP . '/extensions/SemanticMaps';
 22+
 23+$wgExtensionFunctions[] = 'smfSetup';
 24+
 25+$wgHooks['AdminLinks'][] = 'smfAddToAdminLinks';
 26+
 27+$wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php';
 28+
 29+// Autoload the general classes
 30+$wgAutoloadClasses['SMMapPrinter'] = $smgIP . '/SM_MapPrinter.php';
 31+$wgAutoloadClasses['SMMapper'] = $smgIP . '/SM_Mapper.php';
 32+$wgAutoloadClasses['SMFormInput'] = $smgIP . '/SM_FormInput.php';
 33+
 34+function smfSetup() {
 35+ global $wgExtensionCredits, $egMapsMainServices, $wgExtensionCredits;
 36+
 37+ $services_list = implode(', ', $egMapsMainServices);
 38+
 39+ wfLoadExtensionMessages( 'SemanticMaps' );
 40+
 41+ $wgExtensionCredits['other'][]= array(
 42+ 'path' => __FILE__,
 43+ 'name' => wfMsg('semanticmaps_name'),
 44+ 'version' => SM_VERSION,
 45+ 'author' => array("[http://bn2vs.com Jeroen De Dauw]", "Yaron Koren", "Robert Buzink"),
 46+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Maps',
 47+ 'description' => wfMsg( 'semanticmaps_desc', $services_list ),
 48+ 'descriptionmsg' => array( 'semanticmaps_desc', $services_list ),
 49+ );
 50+
 51+ smfInitFormat('map');
 52+ smfInitializeService('map');
 53+
 54+ foreach($egMapsMainServices as $service) smfInitFormat($service);
 55+
 56+ smfInitializeServiceAliases('googlemaps');
 57+ smfInitializeServiceAliases('yahoomaps');
 58+ smfInitializeServiceAliases('openlayers');
 59+}
 60+
 61+/**
 62+ * Apply smfInitializeService() to a service and all it's aliases.
 63+ *
 64+ * @param unknown_type $mainServiceName
 65+ * @param unknown_type $queryPrinter
 66+ */
 67+function smfInitializeServiceAliases($mainServiceName) {
 68+ global $egMapsServices;
 69+
 70+ smfInitializeService($mainServiceName, $mainServiceName);
 71+ foreach ($egMapsServices[$mainServiceName] as $alias) smfInitializeService($alias, $mainServiceName);
 72+}
 73+
 74+/**
 75+ * Add the service name as result format for the provided query printer,
 76+ * and set a hook for it's form input.
 77+ *
 78+ * @param unknown_type $service
 79+ * @param unknown_type $queryPrinter
 80+ * @param unknown_type $mainName
 81+ */
 82+function smfInitializeService($service, $mainName = '') {
 83+ global $sfgFormPrinter;
 84+
 85+ // Add the form input hook for the service
 86+ $field_args = array();
 87+ if (strlen($mainName) > 0) $field_args['service_name'] = $mainName;
 88+ $sfgFormPrinter->setInputTypeHook($service, 'smfSelectFormInputHTML', $field_args);
 89+}
 90+
 91+/**
 92+ * Initialize the result format depending on the map service
 93+ */
 94+function smfInitFormat( $format ) {
 95+ global $smwgResultFormats, $wgAutoloadClasses, $smgIP;
 96+
 97+ switch ($format) {
 98+ case 'map':
 99+ $class = 'SMMapper';
 100+ $file = $smgIP . '/SM_Mapper';
 101+ break;
 102+ case 'googlemaps':
 103+ $class = 'SMGoogleMaps';
 104+ $file = $smgIP . '/GoogleMaps/SM_GoogleMaps';
 105+ break;
 106+ case 'openlayers':
 107+ $class = 'SMOpenLayers';
 108+ $file = $smgIP . '/OpenLayers/SM_OpenLayers';
 109+ break;
 110+ case 'yahoomaps':
 111+ $class = 'SMYahooMaps';
 112+ $file = $smgIP . '/YahooMaps/SM_YahooMaps';
 113+ break;
 114+ }
 115+
 116+ if (isset($class) && isset($file)) {
 117+ // Check if $smwgResultFormats, a global variable introduced in SMW 1.2.2,
 118+ // is set and add the query printer to the result format.
 119+ if (isset($smwgResultFormats)) {
 120+ $smwgResultFormats[$format] = $class;
 121+ }
 122+ else {
 123+ SMWQueryProcessor::$formats[$format] = $class;
 124+ }
 125+
 126+ if ($format != 'map') {
 127+ $wgAutoloadClasses[$class] = $file . ".php";
 128+ $wgAutoloadClasses[$class . "FormInput"] = $file . "FormInput.php";
 129+ }
 130+ }
 131+
 132+
 133+
 134+}
 135+
 136+/**
 137+ * Class for the form input type 'map'. The relevant form input class is called depending on the provided service.
 138+ *
 139+ * @param unknown_type $coordinates
 140+ * @param unknown_type $input_name
 141+ * @param unknown_type $is_mandatory
 142+ * @param unknown_type $is_disabled
 143+ * @param unknown_type $field_args
 144+ * @return unknown
 145+ */
 146+function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args) {
 147+ global $egMapsAvailableServices, $egMapsDefaultService;
 148+
 149+ // If service_name is set, use this value, and ignore any given service parameters
 150+ // This will prevent ..input type=googlemaps|service=yahoo.. from shwoing up a Yahoo! Maps map
 151+ if (array_key_exists('service_name', $field_args)) $field_args['service'] = $field_args['service_name'];
 152+
 153+ $field_args['service'] = MapsMapper::getValidService($field_args['service']);
 154+
 155+ // Create an instace of
 156+ switch ($field_args['service']) {
 157+ case 'googlemaps' :
 158+ $formInput = new SMGoogleMapsFormInput();
 159+ break;
 160+ case 'openlayers' :
 161+ $formInput = new SMOpenLayersFormInput();
 162+ break;
 163+ case 'yahoomaps' :
 164+ $formInput = new SMYahooMapsFormInput();
 165+ break;
 166+ }
 167+
 168+ // Get and return the form input HTML from the hook corresponding with the provided service
 169+ return $formInput->formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args);
 170+}
 171+
 172+function smfGetDynamicInput($id, $value, $args='') {
 173+ // By De Dauw Jeroen - November 2008 - http://code.bn2vs.com/viewtopic.php?t=120
 174+ return '<input id="'.$id.'" '.$args.' value="'.$value.'" onfocus="if (this.value==\''.$value.'\') {this.value=\'\';}" onblur="if (this.value==\'\') {this.value=\''.$value.'\';}" />';
 175+}
 176+
 177+/**
 178+ * Adds a link to Admin Links page
 179+ */
 180+function smfAddToAdminLinks(&$admin_links_tree) {
 181+ $displaying_data_section = $admin_links_tree->getSection(wfMsg('smw_adminlinks_displayingdata'));
 182+ // Escape if SMW hasn't added links
 183+ if (is_null($displaying_data_section))
 184+ return true;
 185+ $smw_docu_row = $displaying_data_section->getRow('smw');
 186+ wfLoadExtensionMessages('SemanticMaps');
 187+ $sm_docu_label = wfMsg('adminlinks_documentation', wfMsg('semanticmaps_name'));
 188+ $smw_docu_row->addItem(AlItem::newFromExternalLink("http://www.mediawiki.org/wiki/Extension:Semantic_Maps", $sm_docu_label));
 189+ return true;
 190+}
 191+

Status & tagging log