Yaron Koren has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/64052


Change subject: Fixes to comments, formatting and code for latest additions
......................................................................

Fixes to comments, formatting and code for latest additions

Change-Id: Ia89a35678e1c1f7ea20303e131fb403c46ac2eb1
---
M ED_Utils.php
1 file changed, 17 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ExternalData 
refs/changes/52/64052/1

diff --git a/ED_Utils.php b/ED_Utils.php
index cfcb1c4..d2863c4 100644
--- a/ED_Utils.php
+++ b/ED_Utils.php
@@ -292,7 +292,7 @@
                $collection = new MongoCollection( $db, $from );
 
                $findArray = array();
-               // Was a direct MongoDB find query JSON string provided?
+               // Was a direct MongoDB "find" query JSON string provided?
                // If so, use that.
                if ( array_key_exists( 'find query', $otherParams ) ) {
                        // Note to users: be sure to use spaces between curly
@@ -356,23 +356,27 @@
                $values = array();
                foreach ( $resultsCursor as $doc ) {
                        foreach ( $columns as $column ) {
-                               // if MongoDB returns an array for a column, do 
some extra processing
-                               if (is_array($doc[$column])) {
-                                       // check if its GeoJSON geometry. 
http://www.geojson.org/geojson-spec.html#geometry-objects 
-                                       // If so, return it in a format that 
Maps can understand
-                                       if ($column == 'geometry' && 
array_key_exists('coordinates', $doc['geometry'])) {
+                               // If MongoDB returns an array for a column,
+                               // do some extra processing.
+                               if ( is_array( $doc[$column] ) ) {
+                                       // Check if it's GeoJSON geometry:
+                                       // 
http://www.geojson.org/geojson-spec.html#geometry-objects 
+                                       // If so, return it in a format that
+                                       // the Maps extension can understand.
+                                       if ( $column == 'geometry' && 
array_key_exists( 'coordinates', $doc['geometry'] ) ) {
                                                $coordinates = 
$doc['geometry']['coordinates'][0];
-                                               $sgeometry = '';
-                                               foreach ($coordinates as 
$coordinate) {
-                                                       $sgeometry .= 
$coordinate[1] . ',' . $coordinate[0] . ':';
+                                               $coordinateStrings = array();
+                                               foreach ( $coordinates as 
$coordinate ) {
+                                                       $coordinateStrings[] = 
$coordinate[1] . ',' . $coordinate[0];
                                                }
-                                               $values[$column][] =  
substr($sgeometry,0,strlen($sgeometry)-1);
+                                               $values[$column][] =  implode( 
':', $coordinateStrings );
                                        } else {
-                                               // just return it as a JSON 
string - the lingua franca of MongoDB
-                                               $values[$column][] = 
json_encode($doc[$column]);
+                                               // Just return it as JSON, the
+                                               // lingua franca of MongoDB.
+                                               $values[$column][] = 
json_encode( $doc[$column] );
                                        }
                                } else {
-                                       // its a simple literal
+                                       // It's a simple literal.
                                        $values[$column][] = $doc[$column];
                                }
                        }

-- 
To view, visit https://gerrit.wikimedia.org/r/64052
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia89a35678e1c1f7ea20303e131fb403c46ac2eb1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ExternalData
Gerrit-Branch: master
Gerrit-Owner: Yaron Koren <yaro...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to