MaxSem has uploaded a new change for review.

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

Change subject: Don't index non-Earth coordinates
......................................................................

Don't index non-Earth coordinates

This was never supposed to happen, but was somehow missed. Search API
explicitly doesn't permit such searches anyway.

Bug: T136559
Change-Id: If9be410d7fdccdf5f3fdf2020f07e442eda6398a
(cherry picked from commit 4285cf58ba8c4f0b48ae4668a95ebdeffa9a738d)
---
M includes/Hooks.php
R includes�Coord.php
2 files changed, 24 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GeoData 
refs/changes/47/292047/1

diff --git a/includes/Hooks.php b/includes/Hooks.php
index ef527eb..03fc448 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -16,6 +16,10 @@
 use User;
 use WikiPage;
 
+/**
+ * Hook handlers
+ * @todo: tests
+ */
 class Hooks {
        /**
         * LoadExtensionSchemaUpdates hook handler
@@ -302,17 +306,31 @@
                $coords = [];
                /** @var Coord $coord */
                foreach ( $parserOutput->geoData->getAll() as $coord ) {
-                       $arr = $coord->getAsArray();
-                       $arr['coord'] = [ 'lat' => $coord->lat, 'lon' => 
$coord->lon ];
-                       unset( $arr['id'] );
-                       unset( $arr['lat'] );
-                       unset( $arr['lon'] );
-                       $coords[] = $arr;
+                       if ( $coord->globe !== 'earth' ) {
+                               continue;
+                       }
+                       $coords[] = self::coordToElastic( $coord );
                }
                $doc->set( 'coordinates', $coords );
        }
 
        /**
+        * Transforms coordinates into an array for insertion onto Elasticsearch
+        *
+        * @param Coord $coord
+        * @return array
+        */
+       public static function coordToElastic( Coord $coord ) {
+               $result = $coord->getAsArray();
+               $result['coord'] = [ 'lat' => $coord->lat, 'lon' => $coord->lon 
];
+               unset( $result['id'] );
+               unset( $result['lat'] );
+               unset( $result['lon'] );
+
+               return $result;
+       }
+
+       /**
         * Add to the tables cloned for parser testing
         * @see https://www.mediawiki.org/wiki/Manual:Hooks/ParserTestTables
         *
diff --git "a/includes\303\260Coord.php" "b/includes\357\277\275Coord.php"
similarity index 100%
rename from "includes\303\260Coord.php"
rename to "includes\357\277\275Coord.php"

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If9be410d7fdccdf5f3fdf2020f07e442eda6398a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GeoData
Gerrit-Branch: wmf/1.28.0-wmf.3
Gerrit-Owner: MaxSem <maxsem.w...@gmail.com>

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

Reply via email to