
jeroendedauw at svn
Nov 17, 2009, 6:14 AM
Post #1 of 1
(80 views)
Permalink
|
|
SVN: [59170] trunk/extensions/Maps
|
|
http://www.mediawiki.org/wiki/Special:Code/MediaWiki/59170 Revision: 59170 Author: jeroendedauw Date: 2009-11-17 14:14:40 +0000 (Tue, 17 Nov 2009) Log Message: ----------- Changes for 0.5. http://www.mediawiki.org/wiki/Extension:Maps/Future#Maps_0.5 Modified Paths: -------------- trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php trunk/extensions/Maps/Maps.php trunk/extensions/Maps/Maps_Mapper.php trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php Removed Paths: ------------- trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php Modified: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php =================================================================== --- trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -1,7 +1,7 @@ <?php /** - * Class for handling the display_point(s) parser functions with Google Maps + * File holding the MapsGoogleMapsDispPoint class. * * @file Maps_GoogleMapsDispPoint.php * @ingroup MapsGoogleMaps @@ -13,6 +13,11 @@ die( 'Not an entry point.' ); } +/** + * Class for handling the display_point(s) parser functions with Google Maps. + * + * @author Jeroen De Dauw + */ final class MapsGoogleMapsDispPoint extends MapsBasePointMap { public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME; @@ -28,6 +33,8 @@ $this->elementNamePrefix = $egMapsGoogleMapsPrefix; $this->defaultZoom = $egMapsGoogleMapsZoom; + + $this->markerStringFormat = 'getGMarkerData(lat, lon, "title", "label", "icon")'; } /** @@ -48,10 +55,8 @@ * */ public function addSpecificMapHTML() { - global $wgJsMimeType, $wgOut; + global $wgJsMimeType; - $enableEarth = MapsGoogleMapsUtils::getEarthValue($this->earth); - $this->type = MapsGoogleMapsUtils::getGMapType($this->type, true); $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls); @@ -60,28 +65,9 @@ $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom); - $markerItems = array(); - - // TODO: Refactor up - foreach ($this->markerData as $markerData) { - $lat = $markerData['lat']; - $lon = $markerData['lon']; - - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; - - $title = str_replace("'", "\'", $title); - $label = str_replace("'", "\'", $label); - - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; - $markerItems[] = "getGMarkerData($lat, $lon, '$title', '$label', '$icon')"; - } - - $markersString = implode(',', $markerItems); - $this->types = explode(",", $this->types); - $typesString = MapsGoogleMapsUtils::createTypesString($this->types, $enableEarth); + $typesString = MapsGoogleMapsUtils::createTypesString($this->types); $this->output .=<<<END @@ -100,7 +86,7 @@ controls: [$this->controls], scrollWheelZoom: $this->autozoom }, - [$markersString] + [$this->markerString] ) ); /*]]>*/ </script> Modified: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php =================================================================== --- trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -124,7 +124,7 @@ * @param string $output */ public static function addGMapDependencies(&$output) { - global $wgJsMimeType, $wgLang, $wgOut; + global $wgJsMimeType, $wgLang; global $egGoogleMapsKey, $egMapsScriptPath, $egGoogleMapsOnThisPage, $egMapsStyleVersion; if (empty($egGoogleMapsOnThisPage)) { @@ -150,26 +150,6 @@ } /** - * Returns a boolean representing if the earth map type should be showed or not, - * when provided the the wiki code value. - * - * @param string $earthValue - * @param boolean $adaptDefault When not set to false, the default map type will be changed to earth when earth is enabled - * @return boolean Indicates wether the earth type should be enabled. - */ - public static function getEarthValue($earthValue, $adaptDefault = true) { - $trueValues = array('on', 'yes'); - $enabled = in_array($earthValue, $trueValues); - - if ($enabled && $adaptDefault) { - global $egMapsGoogleMapsType; - $egMapsGoogleMapsType = 'G_SATELLITE_3D_MAP'; - } - - return $enabled; - } - - /** * Returns a JS items string with the provided types. The earth type will * be added to it when it's not present and $enableEarth is true. If there are * no types, the default will be used. @@ -178,13 +158,10 @@ * @param boolean $enableEarth * @return string */ - public static function createTypesString(array &$types, $enableEarth = false) { + public static function createTypesString(array &$types) { global $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid; $types = MapsMapper::getValidTypes($types, $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid, array(__CLASS__, 'getGMapType')); - - // This is to ensure backwards compatibility with 0.1 and 0.2. - if ($enableEarth && ! in_array('G_SATELLITE_3D_MAP', $types)) $types[] = 'G_SATELLITE_3D_MAP'; return MapsMapper::createJSItemsString($types, null, false, false); } @@ -202,11 +179,12 @@ } /** + * Adds the needed output for the overlays control. * - * * @param string $output * @param string $mapName - * @return unknown_type + * @param string $overlays + * @param string $controls */ public static function addOverlayOutput(&$output, $mapName, $overlays, $controls) { global $egMapsGMapOverlays, $egMapsGoogleOverlLoaded, $wgJsMimeType; @@ -223,7 +201,7 @@ MapsMapper::enforceArrayValues($overlays); $validOverlays = array(); foreach ($overlays as $overlay) { - $segements = split('-', $overlay); + $segements = explode('-', $overlay); $name = $segements[0]; if (in_array($name, $overlayNames)) { Modified: trunk/extensions/Maps/Maps.php =================================================================== --- trunk/extensions/Maps/Maps.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/Maps.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -23,7 +23,7 @@ die( 'Not an entry point.' ); } -define('Maps_VERSION', '0.4.2 rc2'); +define('Maps_VERSION', '0.5 a1'); $egMapsScriptPath = $wgScriptPath . '/extensions/Maps'; $egMapsIP = $IP . '/extensions/Maps'; Modified: trunk/extensions/Maps/Maps_Mapper.php =================================================================== --- trunk/extensions/Maps/Maps_Mapper.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/Maps_Mapper.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -42,6 +42,7 @@ * @param string $name The name you want to check for. * @param string $mainParamName The main parameter name. * @param boolean $compareMainName Boolean indicating wether the main name should also be compared. + * * @return boolean */ public static function inParamAliases($name, $mainParamName, $compareMainName = true) { @@ -61,6 +62,7 @@ * @param string $paramName * @param array $stack * @param boolean $checkForAliases + * * @return boolean */ public static function paramIsPresent($paramName, array $stack, $checkForAliases = true) { @@ -84,6 +86,7 @@ * @param string $paramName * @param array $stack * @param boolean $checkForAliases + * * @return the parameter value or false */ public static function getParamValue($paramName, array $stack, $checkForAliases = true) { @@ -109,6 +112,7 @@ * @param array $serviceDefaults Array with the default parameters and their values for the used mapping service. * @param boolean $strict If set to false, values which a key that does not * exist in the $map array will be retained. + * * @return array */ public static function setDefaultParValues(array $params, array $serviceDefaults, $strict = true) { @@ -154,7 +158,7 @@ * @param string $delimeter */ public static function enforceArrayValues(&$values, $delimeter = ',') { - if (!is_array($values)) $values = split($delimeter, $values); // If not an array yet, split the values + if (!is_array($values)) $values = explode($delimeter, $values); // If not an array yet, split the values for ($i = 0; $i < count($values); $i++) $values[$i] = trim($values[$i]); // Trim all values } @@ -165,6 +169,8 @@ * @param array $items * @param array $defaultItems * @param boolean $asStrings + * @param boolean $toLower + * * @return string */ public static function createJSItemsString(array $items, array $defaultItems = null, $asStrings = true, $toLower = true) { @@ -180,6 +186,8 @@ * * @param array $paramz * @param array $serviceParameters + * @param boolean $strict + * * @return array */ public static function getValidParams(array $paramz, array $serviceParameters, $strict = true) { @@ -201,6 +209,7 @@ * * @param string $paramName * @param array $allowedParms + * * @return string */ private static function getMainParamName($paramName, array $allowedParms) { Modified: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php =================================================================== --- trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -1,7 +1,7 @@ <?php /** - * Class for handling the display_point(s) parser functions with OpenLayers + * File holding the MapsOpenLayersDispPoint class. * * @file Maps_OpenLayersDispPoint.php * @ingroup MapsOpenLayers @@ -13,6 +13,12 @@ die( 'Not an entry point.' ); } + +/** + * Class for handling the display_point(s) parser functions with OpenLayers. + * + * @author Jeroen De Dauw + */ class MapsOpenLayersDispPoint extends MapsBasePointMap { public $serviceName = MapsOpenLayersUtils::SERVICE_NAME; @@ -28,6 +34,8 @@ $this->elementNamePrefix = $egMapsOpenLayersPrefix; $this->defaultZoom = $egMapsOpenLayersZoom; + + $this->markerStringFormat = 'getOLMarkerData(lat, lon, "title", "label", "icon")'; } /** @@ -53,31 +61,12 @@ $controlItems = MapsOpenLayersUtils::createControlsString($this->controls); MapsMapper::enforceArrayValues($this->layers); - $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers); + $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers); - $markerItems = array(); - - // TODO: Refactor up - foreach ($this->markerData as $markerData) { - $lat = $markerData['lat']; - $lon = $markerData['lon']; - - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; - - $title = str_replace("'", "\'", $title); - $label = str_replace("'", "\'", $label); - - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; - $markerItems[] = "getOLMarkerData($lon, $lat, '$title', '$label', '$icon')"; - } - - $markersString = implode(',', $markerItems); - $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div> <script type='$wgJsMimeType'> /*<![CDATA[*/ addOnloadHook( - initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$markersString], $this->height) + initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems],[$this->markerString], $this->height) ); /*]]>*/ </script>"; } Modified: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php =================================================================== --- trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -1,7 +1,7 @@ <?php /** - * Class for handling the display_point(s) parser functions with OSM. + * File holding the MapsOSMDispPoint class. * * @file Maps_OSMDispPoint.php * @ingroup MapsOpenStreetMap @@ -13,6 +13,11 @@ die( 'Not an entry point.' ); } +/** + * Class for handling the display_point(s) parser functions with OSM. + * + * @author Jeroen De Dauw + */ class MapsOSMDispPoint extends MapsBasePointMap { public $serviceName = MapsOSMUtils::SERVICE_NAME; @@ -28,6 +33,8 @@ $this->elementNamePrefix = $egMapsOSMPrefix; $this->defaultZoom = $egMapsOSMZoom; + + $this->markerStringFormat = 'getOSMMarkerData(lat, lon, "title", "label", "icon")'; } /** @@ -48,27 +55,8 @@ * */ public function addSpecificMapHTML() { - global $wgJsMimeType; + global $wgJsMimeType; - $markerItems = array(); - - // TODO: Refactor up - foreach ($this->markerData as $markerData) { - $lat = $markerData['lat']; - $lon = $markerData['lon']; - - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; - - $title = str_replace("'", "\'", $title); - $label = str_replace("'", "\'", $label); - - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; - $markerItems[] = "getOSMMarkerData($lon, $lat, '$title', '$label', '$icon')"; - } - - $markersString = implode(',', $markerItems); - $controlItems = MapsOSMUtils::createControlsString($this->controls); $this->output .= <<<EOT @@ -81,7 +69,7 @@ zoom: $this->zoom, width: $this->width, height: $this->height, - markers: [$markersString], + markers: [$this->markerString], controls: [$controlItems] });</script> Modified: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php =================================================================== --- trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -1,7 +1,7 @@ <?php /** - * + * File holding the registration and handling functions for the display_map parser function. * * @file Maps_DisplayMap.php * @ingroup Maps @@ -20,109 +20,41 @@ $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap'; /** - * Adds the magic words for the parser functions + * Adds the magic words for the parser functions. */ function efMapsDisplayMapMagic( &$magicWords, $langCode ) { $magicWords['display_map'] = array( 0, 'display_map'); - return true; // Unless we return true, other parser functions won't get loaded + return true; // Unless we return true, other parser functions won't get loaded. } /** * Adds the parser function hooks */ function efMapsRegisterDisplayMap(&$wgParser) { - // A hook to enable the '#display_map' parser function + // A hook to enable the '#display_map' parser function. $wgParser->setFunctionHook( 'display_map', array('MapsDisplayMap', 'displayMapRender') ); return true; } /** + * Class containing the rendering functions for the display_map parser function. * - * * @author Jeroen De Dauw * */ final class MapsDisplayMap { /** - * If an address value is provided, turn it into coordinates, - * then calls getMapHtml() and returns it's result. + * Returns the output for a display_map call. * * @param unknown_type $parser * @return array */ - public static function displayMapRender(&$parser) { - $params = func_get_args(); - array_shift( $params ); // We already know the $parser ... - - $fails = MapsParserGeocoder::changeAddressesToCoords($params); - - return self::getMapHtml($parser, $params, 'display_map', $fails); + public static function displayMapRender(&$parser) { + $args = func_get_args(); + return MapsParserFunctions::getMapHtml($parser, $args, 'display_map'); } - - // TODO: refactor up - public static function getMapHtml(&$parser, array $params, $parserFunction, array $geoFails = array()) { - global $wgLang; - - $map = array(); - $coordFails = array(); - - // Go through all parameters, split their names and values, and put them in the $map array. - foreach($params as $param) { - $split = split('=', $param); - if (count($split) > 1) { - $paramName = strtolower(trim($split[0])); - $paramValue = trim($split[1]); - if (strlen($paramName) > 0 && strlen($paramValue) > 0) { - $map[$paramName] = $paramValue; - if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = MapsParserFunctions::filterInvalidCoords($map[$paramName]); - } - } - else if (count($split) == 1) { // Default parameter (without name) - $split[0] = trim($split[0]); - if (strlen($split[0]) > 0) $map['coordinates'] = $split[0]; - } - } - - $coords = MapsMapper::getParamValue('coordinates', $map); - - if ($coords) { - if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = ''; - $map['service'] = MapsMapper::getValidService($map['service'], 'pf'); - - $mapClass = self::getParserClassInstance($map['service'], $parserFunction); - - // Call the function according to the map service to get the HTML output - $output = $mapClass->displayMap($parser, $map); - - if (count($coordFails) > 0) { - $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; - } - - if (count($geoFails) > 0) { - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText($geoFails ), count( $geoFails ) ) . '</i>'; - } - } - elseif (trim($coords) == "" && (count($geoFails) > 0 || count($coordFails) > 0)) { - if (count($coordFails) > 0) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; - if (count($geoFails) > 0) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; - $output .= '<i>' . wfMsg('maps_map_cannot_be_displayed') .'</i>'; - } - else { - $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; - } - - // Return the result - return array( $output, 'noparse' => true, 'isHTML' => true ); - } - private static function getParserClassInstance($service, $parserFunction) { - global $egMapsServices; - // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not. - //die($egMapsServices[$service]['pf'][$parserFunction]['class']); - return new $egMapsServices[$service]['pf'][$parserFunction]['class'](); - } - } \ No newline at end of file Modified: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php =================================================================== --- trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -1,13 +1,11 @@ <?php /** - * Abstract class MapsBasePointMap provides the scafolding for classes handling display_point(s) - * and display_address(es) calls for a spesific mapping service. It inherits from MapsMapFeature and therefore - * forces inheriting classes to implement sereveral methods. - * + * File holding class MapsBasePointMap. + * * @file Maps_BasePointMap.php * @ingroup Maps - * + * * @author Jeroen De Dauw */ @@ -15,9 +13,18 @@ die( 'Not an entry point.' ); } +/** + * Abstract class MapsBasePointMap provides the scafolding for classes handling display_point(s) + * and display_address(es) calls for a spesific mapping service. It inherits from MapsMapFeature and therefore + * forces inheriting classes to implement sereveral methods. + * + * @author Jeroen De Dauw + */ abstract class MapsBasePointMap extends MapsMapFeature { - protected $markerData = array(); + private $markerData = array(); + protected $markerStringFormat = ''; + protected $markerString; /** * Handles the request from the parser hook by doing the work that's common for all @@ -31,13 +38,15 @@ public final function displayMap(&$parser, array $params) { $this->setMapSettings(); - $coords = $this->manageMapProperties($params, __CLASS__); + /* $coords = */ $this->manageMapProperties($params, __CLASS__); $this->doMapServiceLoad(); $this->setMapName(); - $this->setCoordinates($parser); + $this->setCoordinates($parser); + + $this->createMarkerString(); $this->setZoom(); @@ -110,6 +119,35 @@ } /** + * Creates a JS string with the marker data. + * + * @return unknown_type + */ + private function createMarkerString() { + $markerItems = array(); + + foreach ($this->markerData as $markerData) { + $lat = $markerData['lat']; + $lon = $markerData['lon']; + + $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; + $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; + + $title = str_replace("'", "\'", $title); + $label = str_replace("'", "\'", $label); + + $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; + + $markerItems[] = str_replace( array('lon', 'lat', 'title', 'label', 'icon'), + array($lon, $lat, $title, $label, $label), + $this->markerStringFormat + ); + } + + $this->markerString = implode(',', $markerItems); + } + + /** * Sets the $centre_lat and $centre_lon fields. * Note: this needs to be done AFTRE the maker coordinates are set. */ Modified: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php =================================================================== --- trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -1,7 +1,7 @@ <?php /** - * + * File holding the registration and handling functions for the display_point parser function. * * @file Maps_DisplayPoint.php * @ingroup Maps @@ -20,111 +20,42 @@ $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint'; /** - * Adds the magic words for the parser functions + * Adds the magic words for the parser functions. */ function efMapsDisplayPointMagic( &$magicWords, $langCode ) { // The display_address(es) aliases are for backward compatibility only, and will be removed eventually. $magicWords['display_point'] = array( 0, 'display_point', 'display_points', 'display_address', 'display_addresses' ); - return true; // Unless we return true, other parser functions won't get loaded + return true; // Unless we return true, other parser functions won't get loaded. } /** * Adds the parser function hooks */ function efMapsRegisterDisplayPoint(&$wgParser) { - // Hooks to enable the '#display_point' and '#display_points' parser functions + // Hooks to enable the '#display_point' and '#display_points' parser functions. $wgParser->setFunctionHook( 'display_point', array('MapsDisplayPoint', 'displayPointRender') ); return true; } /** + * Class containing the rendering functions for the display_point parser function. * - * * @author Jeroen De Dauw * */ final class MapsDisplayPoint { /** - * Sets the default map properties, gets the map HTML depending - * on the provided service, and then returns it. + * Returns the output for a display_point call. * * @param unknown_type $parser * @return array */ public static function displayPointRender(&$parser) { - $params = func_get_args(); - array_shift( $params ); // We already know the $parser ... - - $fails = MapsParserGeocoder::changeAddressesToCoords($params); - - return self::getMapHtml($parser, $params, 'display_point', $fails); + $args = func_get_args(); + return MapsParserFunctions::getMapHtml($parser, $args, 'display_point'); } - // TODO: refactor up - public static function getMapHtml(&$parser, array $params, $parserFunction, array $geoFails = array()) { - global $wgLang; - - $map = array(); - $coordFails = array(); - - // Go through all parameters, split their names and values, and put them in the $map array. - foreach($params as $param) { - $split = explode('=', $param); - if (count($split) > 1) { - $paramName = strtolower(trim($split[0])); - $paramValue = trim($split[1]); - if (strlen($paramName) > 0 && strlen($paramValue) > 0) { - $map[$paramName] = $paramValue; - if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = MapsParserFunctions::filterInvalidCoords($map[$paramName]); - } - } - else if (count($split) == 1) { // Default parameter (without name) - $split[0] = trim($split[0]); - if (strlen($split[0]) > 0) $map['coordinates'] = $split[0]; - } - } - - $coords = MapsMapper::getParamValue('coordinates', $map); - - if ($coords) { - if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = ''; - $map['service'] = MapsMapper::getValidService($map['service'], 'pf'); - - $mapClass = self::getParserClassInstance($map['service'], $parserFunction); - - // Call the function according to the map service to get the HTML output - $output = $mapClass->displayMap($parser, $map); - - if (count($coordFails) > 0) { - $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; - } - - if (count($geoFails) > 0) { - $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; - } - } - elseif (trim($coords) == "" && (count($geoFails) > 0 || count($coordFails) > 0)) { - if (count($coordFails) > 0) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; - if (count($geoFails) > 0) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; - $output .= '<i>' . wfMsg('maps_map_cannot_be_displayed') .'</i>'; - } - else { - $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; - } - - // Return the result - return array( $output, 'noparse' => true, 'isHTML' => true ); - } - - // TODO: refactor up - private static function getParserClassInstance($service, $parserFunction) { - global $egMapsServices; - // TODO: add check to see if the service actually supports this parser function, and return false for error handling if not. - //die($egMapsServices[$service]['pf'][$parserFunction]['class']); - return new $egMapsServices[$service]['pf'][$parserFunction]['class'](); - } - } \ No newline at end of file Modified: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php =================================================================== --- trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -15,23 +15,18 @@ /** * A class that holds handlers for the mapping parser functions. - * Spesific functions are located in @see MapsUtils * * @author Jeroen De Dauw - * */ final class MapsParserFunctions { /** * Initialize the parser functions feature. This function handles the parser function hook, * and will load the required classes. - * */ public static function initialize() { - global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsAvailableFeatures, $egMapsServices; + global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsServices; - $wgAutoloadClasses['MapsParserGeocoder'] = $egMapsIP. '/ParserFunctions/Maps_ParserGeocoder.php'; - foreach($egMapsServices as $serviceName => $serviceData) { // Check if the service has parser function support $hasPFs = array_key_exists('pf', $serviceData); @@ -48,13 +43,83 @@ } /** + * Returns the output for the call to the specified parser function. + * + * @param $parser + * @param array $params + * @param string $parserFunction + * + * @return array + */ + public static function getMapHtml(&$parser, array $params, $parserFunction) { + global $wgLang; + + array_shift( $params ); // We already know the $parser. + + $map = array(); + $coordFails = array(); + + $geoFails = self::changeAddressesToCoords($params); + + // Go through all parameters, split their names and values, and put them in the $map array. + foreach($params as $param) { + $split = explode('=', $param); + if (count($split) > 1) { + $paramName = strtolower(trim($split[0])); + $paramValue = trim($split[1]); + if (strlen($paramName) > 0 && strlen($paramValue) > 0) { + $map[$paramName] = $paramValue; + if (MapsMapper::inParamAliases($paramName, 'coordinates')) $coordFails = self::filterInvalidCoords($map[$paramName]); + } + } + else if (count($split) == 1) { // Default parameter (without name) + $split[0] = trim($split[0]); + if (strlen($split[0]) > 0) $map['coordinates'] = $split[0]; + } + } + + $coords = MapsMapper::getParamValue('coordinates', $map); + + if ($coords) { + if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = ''; + $map['service'] = MapsMapper::getValidService($map['service'], 'pf'); + + $mapClass = self::getParserClassInstance($map['service'], $parserFunction); + + // Call the function according to the map service to get the HTML output + $output = $mapClass->displayMap($parser, $map); + + if (count($coordFails) > 0) { + $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; + } + + if (count($geoFails) > 0) { + $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; + } + } + elseif (trim($coords) == "" && (count($geoFails) > 0 || count($coordFails) > 0)) { + if (count($coordFails) > 0) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>'; + if (count($geoFails) > 0) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>'; + $output .= '<i>' . wfMsg('maps_map_cannot_be_displayed') .'</i>'; + } + else { + $output = '<i>'.wfMsg( 'maps_coordinates_missing' ).'</i>'; + } + + // Return the result + return array( $output, 'noparse' => true, 'isHTML' => true ); + } + + /** * Filters all non coordinate valus from a coordinate string, * and returns an array containing all filtered out values. * * @param string $coordList + * @param string $delimeter + * * @return array */ - public static function filterInvalidCoords(&$coordList, $delimeter = ';') { + private static function filterInvalidCoords(&$coordList, $delimeter = ';') { $coordFails = array(); $validCoordinates = array(); $coordinates = explode($delimeter, $coordList); @@ -72,6 +137,89 @@ return $coordFails; } + /** + * Changes the values of the address or addresses parameter into coordinates + * in the provided array. Returns an array containing the addresses that + * could not be geocoded. + * + * @param array $params + * + * @return array + */ + private static function changeAddressesToCoords(&$params) { + global $egMapsDefaultService; + $fails = array(); + + // Get the service and geoservice from the parameters, since they are needed to geocode addresses. + for ($i = 0; $i < count($params); $i++) { + $split = explode('=', $params[$i]); + if (MapsMapper::inParamAliases(strtolower(trim($split[0])), 'service') && count($split) > 1) { + $service = trim($split[1]); + } + else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) { + $geoservice = trim($split[1]); + } + } + // Make sure the service and geoservice are valid. + $service = isset($service) ? MapsMapper::getValidService($service, 'pf') : $egMapsDefaultService; + if (! isset($geoservice)) $geoservice = ''; + + // Go over all parameters. + for ($i = 0; $i < count($params); $i++) { + $split = explode('=', $params[$i]); + $isAddress = (strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1; + $isDefault = count($split) == 1; + + // If a parameter is either the default (no name), or an addresses list, extract all locations. + if ($isAddress || $isDefault) { + + $address_srting = $split[count($split) == 1 ? 0 : 1]; + $addresses = explode(';', $address_srting); + + $coordinates = array(); + + // Go over every location and attempt to geocode it. + foreach($addresses as $address) { + $args = explode('~', $address); + $args[0] = trim($args[0]); + + if (strlen($args[0]) > 0) { + $coords = MapsGeocodeUtils::attemptToGeocode($args[0], $geoservice, $service, $isDefault); + + if ($coords) { + $args[0] = $coords; + $coordinates[] = implode('~', $args); + } + else { + $fails[] = $args[0]; + } + } + } + + // Add the geocoded result back to the parameter list. + $params[$i] = implode(';', $coordinates); + + } + + } + + return $fails; + } + + /** + * Returns an instance of the class supporting the spesified mapping service for + * the also spesified parser function. + * + * @param string $service + * @param string $parserFunction + * + * @return class + */ + private static function getParserClassInstance($service, $parserFunction) { + global $egMapsServices; + return new $egMapsServices[$service]['pf'][$parserFunction]['class'](); + } + } \ No newline at end of file Deleted: trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php =================================================================== --- trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/ParserFunctions/Maps_ParserGeocoder.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -1,94 +0,0 @@ -<?php - -/** - * File holding the MapsParserGeocoder class. - * - * @file Maps_ParserGeocoder.php - * @ingroup Maps - * - * @author Jeroen De Dauw - */ - -if( !defined( 'MEDIAWIKI' ) ) { - die( 'Not an entry point.' ); -} - -/** - * Class that holds static helpers for the mapping parser functions. The helpers aid in - * determining the availability of the geocoding parser functions and calling them. - * - * @author Jeroen De Dauw - * - */ -final class MapsParserGeocoder { - - /** - * Changes the values of the address or addresses parameter into coordinates - * in the provided array. Returns an array containing the addresses that - * could not be geocoded. - * - * @param array $params - */ - public static function changeAddressesToCoords(&$params) { - global $egMapsDefaultService; - - $fails = array(); - - // Get the service and geoservice from the parameters, since they are needed to geocode addresses. - for ($i = 0; $i < count($params); $i++) { - $split = explode('=', $params[$i]); - if (MapsMapper::inParamAliases(strtolower(trim($split[0])), 'service') && count($split) > 1) { - $service = trim($split[1]); - } - else if (strtolower(trim($split[0])) == 'geoservice' && count($split) > 1) { - $geoservice = trim($split[1]); - } - } - - // Make sure the service and geoservice are valid. - $service = isset($service) ? MapsMapper::getValidService($service, 'pf') : $egMapsDefaultService; - if (! isset($geoservice)) $geoservice = ''; - - // Go over all parameters. - for ($i = 0; $i < count($params); $i++) { - $split = explode('=', $params[$i]); - $isAddress = (strtolower(trim($split[0])) == 'address' || strtolower(trim($split[0])) == 'addresses') && count($split) > 1; - $isDefault = count($split) == 1; - - // If a parameter is either the default (no name), or an addresses list, extract all locations. - if ($isAddress || $isDefault) { - - $address_srting = $split[count($split) == 1 ? 0 : 1]; - $addresses = explode(';', $address_srting); - - $coordinates = array(); - - // Go over every location and attempt to geocode it. - foreach($addresses as $address) { - $args = explode('~', $address); - $args[0] = trim($args[0]); - - if (strlen($args[0]) > 0) { - $coords = MapsGeocodeUtils::attemptToGeocode($args[0], $geoservice, $service, $isDefault); - - if ($coords) { - $args[0] = $coords; - $coordinates[] = implode('~', $args); - } - else { - $fails[] = $args[0]; - } - } - } - - // Add the geocoded result back to the parameter list. - $params[$i] = implode(';', $coordinates); - - } - - } - - return $fails; - } - -} \ No newline at end of file Modified: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php =================================================================== --- trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php 2009-11-17 11:05:24 UTC (rev 59169) +++ trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php 2009-11-17 14:14:40 UTC (rev 59170) @@ -1,7 +1,7 @@ <?php /** - * Class for handling the display_point(s) parser functions with Yahoo! Maps + * File holding the MapsYahooMapsDispPoint class. * * @file Maps_YahooMapsDispPoint.php * @ingroup MapsYahooMaps @@ -13,6 +13,11 @@ die( 'Not an entry point.' ); } +/** + * Class for handling the display_point(s) parser functions with Yahoo! Maps. + * + * @author Jeroen De Dauw + */ class MapsYahooMapsDispPoint extends MapsBasePointMap { public $serviceName = MapsYahooMapsUtils::SERVICE_NAME; @@ -28,6 +33,8 @@ $this->elementNamePrefix = $egMapsYahooMapsPrefix; $this->defaultZoom = $egMapsYahooMapsZoom; + + $this->markerStringFormat = 'getYMarkerData(lat, lon, "title", "label", "icon")'; } /** @@ -55,25 +62,6 @@ $this->controls = MapsYahooMapsUtils::createControlsString($this->controls); $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom); - - $markerItems = array(); - - // TODO: Refactor up - foreach ($this->markerData as $markerData) { - $lat = $markerData['lat']; - $lon = $markerData['lon']; - - $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title; - $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label; - - $title = str_replace("'", "\'", $title); - $label = str_replace("'", "\'", $label); - - $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : ''; - $markerItems[] = "getYMarkerData($lat, $lon, '$title', '$label', '$icon')"; - } - - $markersString = implode(',', $markerItems); $this->types = explode(",", $this->types); @@ -84,7 +72,7 @@ <script type="$wgJsMimeType">/*<![CDATA[*/ addOnloadHook( - initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$markersString]) + initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$this->markerString]) ); /*]]>*/</script> END; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS [at] lists https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
|