http://www.mediawiki.org/wiki/Special:Code/MediaWiki/60372
Revision: 60372 Author: jeroendedauw Date: 2009-12-24 22:16:17 +0000 (Thu, 24 Dec 2009) Log Message: ----------- Changes for 0.5.1. Changes for 0.5.1. Modified parameter definitions to work Validator 0.2. Modified Paths: -------------- trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php trunk/extensions/Maps/Maps.php trunk/extensions/Maps/Maps_Mapper.php trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php Modified: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php =================================================================== --- trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php 2009-12-24 21:57:39 UTC (rev 60371) +++ trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php 2009-12-24 22:16:17 UTC (rev 60372) @@ -44,6 +44,8 @@ public static function initialize() { self::initializeParams(); + Validator::addOutputFormat('gmaptype', array('MapsGoogleMaps', 'setGMapType')); + Validator::addOutputFormat('gmaptypes', array('MapsGoogleMaps', 'setGMapTypes')); } private static function initializeParams() { @@ -52,43 +54,45 @@ $allowedTypes = self::getTypeNames(); $egMapsServices[self::SERVICE_NAME]['parameters'] = array( - 'zoom' => array( - 'default' => $egMapsGoogleMapsZoom, - ), - 'controls' => array( - 'type' => array('string', 'list'), - 'criteria' => array( - 'in_array' => self::getControlNames() - ), - 'default' => $egMapsGMapControls, - 'output-type' => array('list', ',', '\'') - ), - 'type' => array( - 'aliases' => array('map-type', 'map type'), - 'criteria' => array( - 'in_array' => $allowedTypes - ), - 'default' => $egMapsGoogleMapsType - ), - 'types' => array( - 'type' => array('string', 'list'), - 'aliases' => array('map-types', 'map types'), - 'criteria' => array( - 'in_array' => $allowedTypes - ), - 'default' => $egMapsGoogleMapsTypes - ), - 'autozoom' => array( - 'type' => 'boolean', - 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'), - 'criteria' => array( - 'in_array' => array('on', 'off', 'yes', 'no') - ), - 'default' => $egMapsGoogleAutozoom - ), - 'class' => array(), - 'style' => array(), - ); + 'zoom' => array( + 'default' => $egMapsGoogleMapsZoom, + ), + 'controls' => array( + 'type' => array('string', 'list'), + 'criteria' => array( + 'in_array' => self::getControlNames() + ), + 'default' => $egMapsGMapControls, + 'output-type' => array('list', ',', '\'') + ), + 'type' => array( + 'aliases' => array('map-type', 'map type'), + 'criteria' => array( + 'in_array' => $allowedTypes + ), + 'default' => $egMapsGoogleMapsType, + 'output-type' => array('gmaptype') + ), + 'types' => array( + 'type' => array('string', 'list'), + 'aliases' => array('map-types', 'map types'), + 'criteria' => array( + 'in_array' => $allowedTypes + ), + 'default' => $egMapsGoogleMapsTypes, + 'output-types' => array('gmaptypes', 'list') + ), + 'autozoom' => array( + 'type' => 'boolean', + 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'), + 'criteria' => array( + 'in_array' => array('on', 'off', 'yes', 'no') + ), + 'default' => $egMapsGoogleAutozoom + ), + 'class' => array(), + 'style' => array(), + ); } // http://code.google.com/apis/maps/documentation/reference.html#GMapType.G_NORMAL_MAP @@ -147,31 +151,28 @@ } /** - * Returns the Google Map type (defined in MapsGoogleMaps::$mapTypes) - * for the provided a general map type. When no match is found, false - * will be returned. + * Changes the map type name into the corresponding Google Maps API identifier. * * @param string $type - * @param boolean $restoreAsDefault * - * @return string or false + * @return string */ - public static function getGMapType($type, $restoreAsDefault = false) { - global $egMapsGoogleMapsType; - $typeIsValid = array_key_exists($type, self::$mapTypes); - - if ($typeIsValid) { - return self::$mapTypes[ $type ]; + public static function setGMapType(&$type) { + $type = self::$mapTypes[ $type ]; + } + + /** + * Changes the map type names into the corresponding Google Maps API identifiers. + * + * @param array $types + * + * @return array + */ + public static function setGMapTypes(array &$types) { + for($i = count($types) - 1; $i >= 0; $i--) { + $types[$i] = self::$mapTypes[ $types[$i] ]; } - else { - if ($restoreAsDefault) { - return self::$mapTypes[ $egMapsGoogleMapsType ]; - } - else { - return false; - } - } - } + } /** * Add references to the Google Maps API and required JS file to the provided output @@ -192,6 +193,8 @@ } /** + * TODO: remove + * * Retuns a boolean as string, true if $autozoom is on or yes. * * @param string $autozoom @@ -202,23 +205,6 @@ } /** - * 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. - * - * @param array $types - * - * @return string - */ - public static function createTypesString(array &$types) { - global $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid; - - $types = MapsMapper::getValidTypes($types, $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid, array(__CLASS__, 'getGMapType')); - - return MapsMapper::createJSItemsString($types, null, false, false); - } - - /** * This function ensures backward compatibility with Semantic Google Maps and other extensions * using $wgGoogleMapsKey instead of $egGoogleMapsKey. */ Modified: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php =================================================================== --- trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php 2009-12-24 21:57:39 UTC (rev 60371) +++ trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php 2009-12-24 22:16:17 UTC (rev 60372) @@ -57,14 +57,10 @@ public function addSpecificMapHTML() { global $wgJsMimeType; - $this->type = MapsGoogleMaps::getGMapType($this->type, true); - $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom); - $typesString = MapsGoogleMaps::createTypesString($this->types); - $this->output .=<<<END <div id="$this->mapName" class="$this->class" style="$this->style" ></div> @@ -78,7 +74,7 @@ lon: $this->centre_lon, zoom: $this->zoom, type: $this->type, - types: [$typesString], + types: [$this->types], controls: [$this->controls], scrollWheelZoom: $this->autozoom }, []) Modified: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php =================================================================== --- trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php 2009-12-24 21:57:39 UTC (rev 60371) +++ trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php 2009-12-24 22:16:17 UTC (rev 60372) @@ -67,16 +67,10 @@ public function addSpecificMapHTML() { global $wgJsMimeType; - $this->type = MapsGoogleMaps::getGMapType($this->type, true); - $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom); - $this->types = $this->types; - - $typesString = MapsGoogleMaps::createTypesString($this->types); - $this->output .=<<<END <div id="$this->mapName" class="$this->class" style="$this->style" ></div> @@ -90,7 +84,7 @@ lon: $this->centre_lon, zoom: $this->zoom, type: $this->type, - types: [$typesString], + types: [$this->types], controls: [$this->controls], scrollWheelZoom: $this->autozoom }, Modified: trunk/extensions/Maps/Maps.php =================================================================== --- trunk/extensions/Maps/Maps.php 2009-12-24 21:57:39 UTC (rev 60371) +++ trunk/extensions/Maps/Maps.php 2009-12-24 22:16:17 UTC (rev 60372) @@ -33,7 +33,7 @@ echo '<b>Warning:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.'; } else { - define('Maps_VERSION', '0.5.1 a4'); + define('Maps_VERSION', '0.5.1 a5'); $egMapsScriptPath = $wgScriptPath . '/extensions/Maps'; $egMapsIP = $IP . '/extensions/Maps'; Modified: trunk/extensions/Maps/Maps_Mapper.php =================================================================== --- trunk/extensions/Maps/Maps_Mapper.php 2009-12-24 21:57:39 UTC (rev 60371) +++ trunk/extensions/Maps/Maps_Mapper.php 2009-12-24 22:16:17 UTC (rev 60372) @@ -62,6 +62,8 @@ } /** + * TODO: remove + * * Returns the JS version (true/false as string) of the provided boolean parameter. * * @param boolean $bool @@ -72,6 +74,8 @@ } /** + * TODO: remove + * * Turns the provided values into an array by splitting it on comma's if * it's not an array yet. * @@ -84,67 +88,6 @@ } /** - * Checks if the items array has members, and sets it to the default when this is not the case. - * Then returns an imploded/joined, comma seperated, version of the array as string. - * - * @param array $items - * @param array $defaultItems - * @param boolean $asStrings - * @param boolean $toLower - * - * @return string - */ - public static function createJSItemsString(array $items, $asStrings = true, $toLower = true) { - $itemString = $asStrings ? "'" . implode("','", $items) . "'" : implode(',', $items); - if ($toLower) $itemString = strtolower($itemString); - return $itemString; - } - - /** - * Returns a valid version of the types. - * - * @param array $types - * @param array $defaults - * @param boolean $defaultsAreValid - * @param function $validationFunction - * - * @return array - */ - public static function getValidTypes(array $types, array &$defaults, &$defaultsAreValid, $validationFunction) { - $validTypes = array(); - $phpAtLeast523 = MapsUtils::phpVersionIsEqualOrBigger('5.2.3'); - - // Ensure every type is valid and uses the relevant map API's name. - for($i = 0 ; $i < count($types); $i++) { - $type = call_user_func($validationFunction, $phpAtLeast523 ? $types[$i] : array($types[$i])); - if ($type) $validTypes[] = $type; - } - - $types = $validTypes; - - // If there are no valid types, add the default ones. - if (count($types) < 1) { - $validTypes = array(); - - // If the default ones have not been checked, - // ensure every type is valid and uses the relevant map API's name. - if (empty($defaultsAreValid)) { - for($i = 0 ; $i < count($defaults); $i++) { - $type = call_user_func($validationFunction, $phpAtLeast523 ? $defaults[$i] : array($defaults[$i])); - if ($type) $validTypes[] = $type; - } - - $defaults = $validTypes; - $defaultsAreValid = true; - } - - $types = $defaults; - } - - return $types; - } - - /** * Returns a valid service. When an invalid service is provided, the default one will be returned. * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName(). * Modified: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php =================================================================== --- trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php 2009-12-24 21:57:39 UTC (rev 60371) +++ trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php 2009-12-24 22:16:17 UTC (rev 60372) @@ -44,6 +44,8 @@ public static function initialize() { self::initializeParams(); + Validator::addOutputFormat('ymaptype', array('MapsYahooMaps', 'setYMapType')); + Validator::addOutputFormat('ymaptypes', array('MapsYahooMaps', 'setYMapTypes')); } private static function initializeParams() { @@ -68,7 +70,8 @@ 'criteria' => array( 'in_array' => $allowedTypes ), - 'default' => $egMapsYahooMapsType + 'default' => $egMapsYahooMapsType, + 'output-type' => array('ymaptype') ), 'types' => array ( 'type' => array('string', 'list'), @@ -76,7 +79,8 @@ 'criteria' => array( 'in_array' => $allowedTypes ), - 'default' => $egMapsYahooMapsTypes + 'default' => $egMapsYahooMapsTypes, + 'output-types' => array('ymaptypes', 'list') ), 'autozoom' => array( 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'), @@ -114,26 +118,30 @@ public static function getControlNames() { return array('scale', 'type', 'pan', 'zoom', 'zoom-short', 'auto-zoom'); } - + /** - * Returns the Yahoo Map type (defined in MapsYahooMaps::$mapTypes) - * for the provided a general map type. When no match is found, the first - * Google Map type will be returned as default. + * Changes the map type name into the corresponding Yahoo! Maps API identifier. * * @param string $type - * @param boolean $restoreAsDefault * - * @return string or false + * @return string */ - public static function getYMapType($type, $restoreAsDefault = false) { - global $egMapsYahooMapsType; - - $typeIsValid = array_key_exists($type, self::$mapTypes); - - if (!$typeIsValid && $restoreAsDefault) $type = $egMapsYahooMapsType; - - return $typeIsValid || $restoreAsDefault ? self::$mapTypes[ $type ] : false; - } + public static function setYMapType(&$type) { + $type = self::$mapTypes[ $type ]; + } + + /** + * Changes the map type names into the corresponding Yahoo! Maps API identifiers. + * + * @param array $types + * + * @return array + */ + public static function setYMapTypes(array &$types) { + for($i = count($types) - 1; $i >= 0; $i--) { + $types[$i] = self::$mapTypes[ $types[$i] ]; + } + } /** * Add references to the Yahoo! Maps API and required JS file to the provided output Modified: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php =================================================================== --- trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php 2009-12-24 21:57:39 UTC (rev 60371) +++ trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php 2009-12-24 22:16:17 UTC (rev 60372) @@ -47,19 +47,15 @@ */ public function addSpecificMapHTML() { global $wgJsMimeType; - - $this->type = MapsYahooMaps::getYMapType($this->type, true); - $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); + $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); - $typesString = MapsYahooMaps::createTypesString($this->types); - $this->output .= <<<END <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div> <script type="$wgJsMimeType">/*<![CDATA[*/ addOnloadHook( - initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [], $this->height) + initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$this->types], [$this->controls], $this->autozoom, [], $this->height) ); /*]]>*/</script> END; Modified: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php =================================================================== --- trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php 2009-12-24 21:57:39 UTC (rev 60371) +++ trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php 2009-12-24 22:16:17 UTC (rev 60372) @@ -57,22 +57,18 @@ /** * @see MapsBaseMap::addSpecificMapHTML() * - */ + */ public function addSpecificMapHTML() { global $wgJsMimeType; - $this->type = MapsYahooMaps::getYMapType($this->type, true); - - $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); + $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); - $typesString = MapsYahooMaps::createTypesString($this->types); - $this->output .= <<<END <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div> <script type="$wgJsMimeType">/*<![CDATA[*/ addOnloadHook( - initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$this->markerString], $this->height) + initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$this->types], [$this->controls], $this->autozoom, [$this->markerString], $this->height) ); /*]]>*/</script> END; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs