Yaron Koren has uploaded a new change for review.

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

Change subject: Moved coordinate-related static functions from CargoStore to 
CargoUtils
......................................................................

Moved coordinate-related static functions from CargoStore to CargoUtils

Change-Id: I22cb47f4ea89c145b09f3643045ec1a1f3999340
---
M CargoSQLQuery.php
M CargoUtils.php
M parserfunctions/CargoDisplayMap.php
M parserfunctions/CargoStore.php
4 files changed, 124 insertions(+), 124 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Cargo 
refs/changes/31/227731/1

diff --git a/CargoSQLQuery.php b/CargoSQLQuery.php
index 5734dc9..6044228 100644
--- a/CargoSQLQuery.php
+++ b/CargoSQLQuery.php
@@ -881,7 +881,7 @@
                $latDistance = $distanceInKM / 111;
 
                // Convert the latitude string to a latitude number - code is
-               // copied from CargoStore::parseCoordinatesString().
+               // copied from CargoUtils::parseCoordinatesString().
                $latIsNegative = false;
                if ( strpos( $latString, 'S' ) > 0 ) {
                        $latIsNegative = true;
@@ -890,7 +890,7 @@
                if ( is_numeric( $latString ) ) {
                        $latNum = floatval( $latString );
                } else {
-                       $latNum = CargoStore::coordinatePartToNumber( 
$latString );
+                       $latNum = CargoUtils::coordinatePartToNumber( 
$latString );
                }
                if ( $latIsNegative ) {
                        $latNum *= -1;
diff --git a/CargoUtils.php b/CargoUtils.php
index 3966fe5..1d6ed2c 100644
--- a/CargoUtils.php
+++ b/CargoUtils.php
@@ -537,4 +537,123 @@
                }
        }
 
+       /**
+        * Parses one half of a set of coordinates into a number.
+        *
+        * Copied from Miga, also written by Yaron Koren
+        * (https://github.com/yaronkoren/miga/blob/master/MDVCoordinates.js)
+        * - though that one is in Javascript.
+        */
+       public static function coordinatePartToNumber( $coordinateStr ) {
+               $degreesSymbols = array( "\x{00B0}", "d" );
+               $minutesSymbols = array( "'", "\x{2032}", "\x{00B4}" );
+               $secondsSymbols = array( '"', "\x{2033}", "\x{00B4}\x{00B4}" );
+
+               $numDegrees = null;
+               $numMinutes = null;
+               $numSeconds = null;
+
+               foreach ( $degreesSymbols as $degreesSymbol ) {
+                       $pattern = '/([\d\.]+)' . $degreesSymbol . '/u';
+                       if ( preg_match( $pattern, $coordinateStr, $matches ) ) 
{
+                               $numDegrees = floatval( $matches[1] );
+                               break;
+                       }
+               }
+               if ( $numDegrees == null ) {
+                       throw new MWException( "Error: could not parse degrees 
in \"$coordinateStr\"." );
+               }
+
+               foreach ( $minutesSymbols as $minutesSymbol ) {
+                       $pattern = '/([\d\.]+)' . $minutesSymbol . '/u';
+                       if ( preg_match( $pattern, $coordinateStr, $matches ) ) 
{
+                               $numMinutes = floatval( $matches[1] );
+                               break;
+                       }
+               }
+               if ( $numMinutes == null ) {
+                       // This might not be an error - the number of minutes
+                       // might just not have been set.
+                       $numMinutes = 0;
+               }
+
+               foreach ( $secondsSymbols as $secondsSymbol ) {
+                       $pattern = '/(\d+)' . $secondsSymbol . '/u';
+                       if ( preg_match( $pattern, $coordinateStr, $matches ) ) 
{
+                               $numSeconds = floatval( $matches[1] );
+                               break;
+                       }
+               }
+               if ( $numSeconds == null ) {
+                       // This might not be an error - the number of seconds
+                       // might just not have been set.
+                       $numSeconds = 0;
+               }
+
+               return ( $numDegrees + ( $numMinutes / 60 ) + ( $numSeconds / 
3600 ) );
+       }
+
+       /**
+        * Parses a coordinate string in (hopefully) any standard format.
+        *
+        * Copied from Miga, also written by Yaron Koren
+        * (https://github.com/yaronkoren/miga/blob/master/MDVCoordinates.js)
+        * - though that one is in Javascript.
+        */
+       public static function parseCoordinatesString( $coordinatesString ) {
+               $coordinatesString = trim( $coordinatesString );
+               if ( $coordinatesString == null ) {
+                       return;
+               }
+
+               // This is safe to do, right?
+               $coordinatesString = str_replace( array( '[', ']' ), '', 
$coordinatesString );
+               // See if they're separated by commas.
+               if ( strpos( $coordinatesString, ',' ) > 0 ) {
+                       $latAndLonStrings = explode( ',', $coordinatesString );
+               } else {
+                       // If there are no commas, the first half, for the
+                       // latitude, should end with either 'N' or 'S', so do a
+                       // little hack to split up the two halves.
+                       $coordinatesString = str_replace( array( 'N', 'S' ), 
array( 'N,', 'S,' ), $coordinatesString );
+                       $latAndLonStrings = explode( ',', $coordinatesString );
+               }
+
+               if ( count( $latAndLonStrings ) != 2 ) {
+                       throw new MWException( "Error parsing coordinates 
string: \"$coordinatesString\"." );
+               }
+               list( $latString, $lonString ) = $latAndLonStrings;
+
+               // Handle strings one at a time.
+               $latIsNegative = false;
+               if ( strpos( $latString, 'S' ) > 0 ) {
+                       $latIsNegative = true;
+               }
+               $latString = str_replace( array( 'N', 'S' ), '', $latString );
+               if ( is_numeric( $latString ) ) {
+                       $latNum = floatval( $latString );
+               } else {
+                       $latNum = self::coordinatePartToNumber( $latString );
+               }
+               if ( $latIsNegative ) {
+                       $latNum *= -1;
+               }
+
+               $lonIsNegative = false;
+               if ( strpos( $lonString, 'W' ) > 0 ) {
+                       $lonIsNegative = true;
+               }
+               $lonString = str_replace( array( 'E', 'W' ), '', $lonString );
+               if ( is_numeric( $lonString ) ) {
+                       $lonNum = floatval( $lonString );
+               } else {
+                       $lonNum = self::coordinatePartToNumber( $lonString );
+               }
+               if ( $lonIsNegative ) {
+                       $lonNum *= -1;
+               }
+
+               return array( $latNum, $lonNum );
+       }
+
 }
diff --git a/parserfunctions/CargoDisplayMap.php 
b/parserfunctions/CargoDisplayMap.php
index 675265b..b3fe308 100644
--- a/parserfunctions/CargoDisplayMap.php
+++ b/parserfunctions/CargoDisplayMap.php
@@ -70,7 +70,7 @@
                        $mappingFormat = new CargoOpenLayersFormat( 
$parser->getOutput() );
                }
 
-               list ( $lat, $lon ) = CargoStore::parseCoordinatesString( 
$pointStr );
+               list ( $lat, $lon ) = CargoUtils::parseCoordinatesString( 
$pointStr );
                $valuesTable = array( array( 'Coords  lat' => $lat, 'Coords  
lon' => $lon ) );
                $formattedValuesTable = $valuesTable;
                $coordsDesc = new CargoFieldDescription();
diff --git a/parserfunctions/CargoStore.php b/parserfunctions/CargoStore.php
index 96ca322..aaebd05 100644
--- a/parserfunctions/CargoStore.php
+++ b/parserfunctions/CargoStore.php
@@ -16,125 +16,6 @@
        const YEAR_ONLY = 3;
 
        /**
-        * Parses one half of a set of coordinates into a number.
-        *
-        * Copied from Miga, also written by Yaron Koren
-        * (https://github.com/yaronkoren/miga/blob/master/MDVCoordinates.js)
-        * - though that one is in Javascript.
-        */
-       public static function coordinatePartToNumber( $coordinateStr ) {
-               $degreesSymbols = array( "\x{00B0}", "d" );
-               $minutesSymbols = array( "'", "\x{2032}", "\x{00B4}" );
-               $secondsSymbols = array( '"', "\x{2033}", "\x{00B4}\x{00B4}" );
-
-               $numDegrees = null;
-               $numMinutes = null;
-               $numSeconds = null;
-
-               foreach ( $degreesSymbols as $degreesSymbol ) {
-                       $pattern = '/([\d\.]+)' . $degreesSymbol . '/u';
-                       if ( preg_match( $pattern, $coordinateStr, $matches ) ) 
{
-                               $numDegrees = floatval( $matches[1] );
-                               break;
-                       }
-               }
-               if ( $numDegrees == null ) {
-                       throw new MWException( "Error: could not parse degrees 
in \"$coordinateStr\"." );
-               }
-
-               foreach ( $minutesSymbols as $minutesSymbol ) {
-                       $pattern = '/([\d\.]+)' . $minutesSymbol . '/u';
-                       if ( preg_match( $pattern, $coordinateStr, $matches ) ) 
{
-                               $numMinutes = floatval( $matches[1] );
-                               break;
-                       }
-               }
-               if ( $numMinutes == null ) {
-                       // This might not be an error - the number of minutes
-                       // might just not have been set.
-                       $numMinutes = 0;
-               }
-
-               foreach ( $secondsSymbols as $secondsSymbol ) {
-                       $pattern = '/(\d+)' . $secondsSymbol . '/u';
-                       if ( preg_match( $pattern, $coordinateStr, $matches ) ) 
{
-                               $numSeconds = floatval( $matches[1] );
-                               break;
-                       }
-               }
-               if ( $numSeconds == null ) {
-                       // This might not be an error - the number of seconds
-                       // might just not have been set.
-                       $numSeconds = 0;
-               }
-
-               return ( $numDegrees + ( $numMinutes / 60 ) + ( $numSeconds / 
3600 ) );
-       }
-
-       /**
-        * Parses a coordinate string in (hopefully) any standard format.
-        *
-        * Copied from Miga, also written by Yaron Koren
-        * (https://github.com/yaronkoren/miga/blob/master/MDVCoordinates.js)
-        * - though that one is in Javascript.
-        */
-       public static function parseCoordinatesString( $coordinatesString ) {
-               $coordinatesString = trim( $coordinatesString );
-               if ( $coordinatesString == null ) {
-                       return;
-               }
-
-               // This is safe to do, right?
-               $coordinatesString = str_replace( array( '[', ']' ), '', 
$coordinatesString );
-               // See if they're separated by commas.
-               if ( strpos( $coordinatesString, ',' ) > 0 ) {
-                       $latAndLonStrings = explode( ',', $coordinatesString );
-               } else {
-                       // If there are no commas, the first half, for the
-                       // latitude, should end with either 'N' or 'S', so do a
-                       // little hack to split up the two halves.
-                       $coordinatesString = str_replace( array( 'N', 'S' ), 
array( 'N,', 'S,' ), $coordinatesString );
-                       $latAndLonStrings = explode( ',', $coordinatesString );
-               }
-
-               if ( count( $latAndLonStrings ) != 2 ) {
-                       throw new MWException( "Error parsing coordinates 
string: \"$coordinatesString\"." );
-               }
-               list( $latString, $lonString ) = $latAndLonStrings;
-
-               // Handle strings one at a time.
-               $latIsNegative = false;
-               if ( strpos( $latString, 'S' ) > 0 ) {
-                       $latIsNegative = true;
-               }
-               $latString = str_replace( array( 'N', 'S' ), '', $latString );
-               if ( is_numeric( $latString ) ) {
-                       $latNum = floatval( $latString );
-               } else {
-                       $latNum = self::coordinatePartToNumber( $latString );
-               }
-               if ( $latIsNegative ) {
-                       $latNum *= -1;
-               }
-
-               $lonIsNegative = false;
-               if ( strpos( $lonString, 'W' ) > 0 ) {
-                       $lonIsNegative = true;
-               }
-               $lonString = str_replace( array( 'E', 'W' ), '', $lonString );
-               if ( is_numeric( $lonString ) ) {
-                       $lonNum = floatval( $lonString );
-               } else {
-                       $lonNum = self::coordinatePartToNumber( $lonString );
-               }
-               if ( $lonIsNegative ) {
-                       $lonNum *= -1;
-               }
-
-               return array( $latNum, $lonNum );
-       }
-
-       /**
         * Handles the #cargo_set parser function - saves data for one
         * template call.
         *
@@ -404,7 +285,7 @@
                                        // For coordinates, there are two more
                                        // fields, for latitude and longitude.
                                        if ( $fieldType == 'Coordinates' ) {
-                                               list( $latitude, $longitude) = 
self::parseCoordinatesString( $individualValue );
+                                               list( $latitude, $longitude) = 
CargoUtils::parseCoordinatesString( $individualValue );
                                                $fieldValues['_lat'] = 
$latitude;
                                                $fieldValues['_lon'] = 
$longitude;
                                        }
@@ -415,7 +296,7 @@
                                $tableFieldValues[$fieldName . '__full'] = 
$tableFieldValues[$fieldName];
                                unset( $tableFieldValues[$fieldName] );
                        } elseif ( $fieldType == 'Coordinates' ) {
-                               list( $latitude, $longitude) = 
self::parseCoordinatesString( $tableFieldValues[$fieldName] );
+                               list( $latitude, $longitude) = 
CargoUtils::parseCoordinatesString( $tableFieldValues[$fieldName] );
                                // Rename the field.
                                $tableFieldValues[$fieldName . '__full'] = 
$tableFieldValues[$fieldName];
                                unset( $tableFieldValues[$fieldName] );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I22cb47f4ea89c145b09f3643045ec1a1f3999340
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Cargo
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