r74973 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r74972‎ | r74973 | r74974 >
Date:22:21, 18 October 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Workaround for Xml::encodeJsVar not handling floats correctly
Modified paths:
  • /trunk/extensions/Maps/includes/Maps_Layer.php (modified) (history)
  • /trunk/extensions/Maps/includes/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/includes/services/OpenLayers/Maps_ParamOLLayers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/includes/Maps_Layer.php
@@ -126,7 +126,8 @@
127127 $params['type'] = new Parameter( 'type' );
128128 $params['type']->addCriteria( New CriterionInArray( array_keys( self::$types ) ) );
129129
130 - $params[] = new Parameter( 'label' );
 130+ $params['label'] = new Parameter( 'label' );
 131+ $params['label']->lowerCaseValue = false;
131132
132133 $params[] = new Parameter( 'lowerbound', Parameter::TYPE_FLOAT );
133134 $params[] = new Parameter( 'upperbound', Parameter::TYPE_FLOAT );
@@ -188,9 +189,9 @@
189190 */
190191 public function getJavaScriptDefinition() {
191192 foreach ( $this->properties as $name => $value ) {
192 - ${ $name } = Xml::encodeJsVar( $value );
 193+ ${ $name } = MapsMapper::encodeJsVar( $value );
193194 }
194 -
 195+
195196 $class = self::$types[$this->getType()]['class'];
196197
197198 $options = array();
Index: trunk/extensions/Maps/includes/services/OpenLayers/Maps_ParamOLLayers.php
@@ -36,6 +36,7 @@
3737
3838 foreach ( $parameter->getValue() as $layerOrGroup ) {
3939 $lcLayerOrGroup = strtolower( $layerOrGroup );
 40+
4041 // Layer groups. Loop over all items and add them when not present yet.
4142 if ( array_key_exists( $lcLayerOrGroup, $egMapsOLLayerGroups ) ) {
4243 foreach ( $egMapsOLLayerGroups[$lcLayerOrGroup] as $layerName ) {
Index: trunk/extensions/Maps/includes/Maps_Mapper.php
@@ -63,6 +63,56 @@
6464 }
6565
6666 /**
 67+ * Encode a variable of unknown type to JavaScript.
 68+ * Arrays are converted to JS arrays, objects are converted to JS associative
 69+ * arrays (objects). So cast your PHP associative arrays to objects before
 70+ * passing them to here.
 71+ *
 72+ * This is a copy of
 73+ * @see Xml::encodeJsVar
 74+ * which fixes incorrect behaviour with floats.
 75+ *
 76+ * @since 0.7.1
 77+ *
 78+ * @param mixed $value
 79+ */
 80+ public static function encodeJsVar( $value ) {
 81+ if ( is_bool( $value ) ) {
 82+ $s = $value ? 'true' : 'false';
 83+ } elseif ( is_null( $value ) ) {
 84+ $s = 'null';
 85+ } elseif ( is_int( $value ) || is_float( $value ) ) {
 86+ $s = $value;
 87+ } elseif ( is_array( $value ) && // Make sure it's not associative.
 88+ array_keys($value) === range( 0, count($value) - 1 ) ||
 89+ count($value) == 0
 90+ ) {
 91+ $s = '[';
 92+ foreach ( $value as $elt ) {
 93+ if ( $s != '[' ) {
 94+ $s .= ', ';
 95+ }
 96+ $s .= self::encodeJsVar( $elt );
 97+ }
 98+ $s .= ']';
 99+ } elseif ( is_object( $value ) || is_array( $value ) ) {
 100+ // Objects and associative arrays
 101+ $s = '{';
 102+ foreach ( (array)$value as $name => $elt ) {
 103+ if ( $s != '{' ) {
 104+ $s .= ', ';
 105+ }
 106+ $s .= '"' . Xml::escapeJsString( $name ) . '": ' .
 107+ self::encodeJsVar( $elt );
 108+ }
 109+ $s .= '}';
 110+ } else {
 111+ $s = '"' . Xml::escapeJsString( $value ) . '"';
 112+ }
 113+ return $s;
 114+ }
 115+
 116+ /**
67117 * This function returns the definitions for the parameters used by every map feature.
68118 *
69119 * @return array

Status & tagging log