r64203 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64202‎ | r64203 | r64204 >
Date:00:36, 26 March 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.5.6 - rewriting coordinate validation and parsing
Modified paths:
  • /trunk/extensions/SemanticMaps/FormInputs/SM_FormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php (modified) (history)
  • /trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php
@@ -14,8 +14,8 @@
1515 die( 'Not an entry point.' );
1616 }
1717
18 -// / Unicode symbols for coordinate minutes and seconds;
19 -// / may not display in every font ...
 18+/// Unicode symbols for coordinate minutes and seconds;
 19+/// may not display in every font ...
2020 define( 'SM_GEO_MIN', '′' );
2121 define( 'SM_GEO_SEC', '″' );
2222
@@ -44,6 +44,16 @@
4545 // Note: signs are used as e.g. on Google maps, i.e. S and W are negative numbers.
4646
4747 /**
 48+ * Adds support for the geographical coordinate data type to Semantic MediaWiki.
 49+ *
 50+ * TODO: i18n keys still need to be moved
 51+ */
 52+ function InitGeoCoordsType() {
 53+ SMWDataValueFactory::registerDatatype( '_geo', 'SMGeoCoordsValue', 'Geographic coordinate' );
 54+ return true;
 55+ }
 56+
 57+ /**
4858 * @see SMWDataValue::parseUserValue
4959 */
5060 protected function parseUserValue( $value ) {
@@ -85,7 +95,12 @@
8696 $value = str_replace( array( '′', '′', "'", '´' ), SM_GEO_MIN, $value );
8797
8898 // Split the value string.
89 - $parts = preg_split( '/\s*(°|' . SM_GEO_MIN . '|' . SM_GEO_SEC . '|N|E|W|S|;)\s*/u', str_replace( ', ', ';', $value ) . ';', - 1, PREG_SPLIT_DELIM_CAPTURE );
 99+ $parts = preg_split(
 100+ '/\s*(°|' . SM_GEO_MIN . '|' . SM_GEO_SEC . '|N|E|W|S|;)\s*/u',
 101+ str_replace( ', ', ';', $value ) . ';',
 102+ - 1,
 103+ PREG_SPLIT_DELIM_CAPTURE
 104+ );
90105 $curnum = false;
91106 $angles = array( false, false, false ); // Temporary values for deg, min, sec
92107
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php
@@ -18,22 +18,13 @@
1919 $wgAutoloadClasses['SMGeoCoordsValueDescription'] = $smgDir . 'GeoCoords/SM_GeoCoordsValueDescription.php';
2020
2121 // Hook for initializing the Geographical Coordinate type.
22 -$wgHooks['smwInitDatatypes'][] = 'smfInitGeoCoordsType';
 22+$wgHooks['smwInitDatatypes'][] = 'SMGeoCoordsValue::InitGeoCoordsType';
2323
2424 // Hook for initializing the Geographical Proximity query support.
2525 $wgHooks['smwGetSQLConditionForValue'][] = 'smfGetGeoProximitySQLCondition';
2626
2727 define( 'SM_CMP_NEAR', 101 ); // Define the near comparator for proximity queries.
2828
29 -/**
30 - * Adds support for the geographical coordinate data type to Semantic MediaWiki.
31 - *
32 - * TODO: i18n keys still need to be moved
33 - */
34 -function smfInitGeoCoordsType() {
35 - SMWDataValueFactory::registerDatatype( '_geo', 'SMGeoCoordsValue', 'Geographic coordinate' );
36 - return true;
37 -}
3829
3930 /**
4031 * Custom SQL query extension for matching geographic coordinates.
@@ -44,6 +35,8 @@
4536 * TODO: Add support for a per-coordinate set distance parameter.
4637 */
4738 function smfGetGeoProximitySQLCondition( &$where, $description, $tablename, $fieldname, $dbs ) {
 39+ global $smgGeoCoordDistance;
 40+
4841 $where = '';
4942 $dv = $description->getDatavalue();
5043
@@ -68,7 +61,7 @@
6962 // Compute distances in miles:
7063 $distance = "ROUND(((ACOS( SIN({$latitude} * PI()/180 ) * SIN(SUBSTRING_INDEX({$tablename}.{$fieldname}, ',',1) * PI()/180 ) + COS({$latitude} * PI()/180 ) * COS(SUBSTRING_INDEX({$tablename}.{$fieldname}, ',',1) * PI()/180 ) * COS(({$longitude} - SUBSTRING_INDEX({$tablename}.{$fieldname}, ',',-1)) * PI()/180))*180/PI())*60*1.1515),6)";
7164
72 - $where = "{$distance} <= " . $dbs->addQuotes( "5" );
 65+ $where = "{$distance} <= " . $dbs->addQuotes( $smgGeoCoordDistance );
7366
7467 return true;
7568 }
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/FormInputs/SM_FormInput.php
@@ -148,7 +148,7 @@
149149 }
150150 else {
151151 // Geocode and convert if required.
152 - $centre = MapsGeocodeUtils::attemptToGeocode( $this->centre, $this->geoservice, $this->serviceName );
 152+ $centre = MapsGeocoder::attemptToGeocode( $this->centre, $this->geoservice, $this->serviceName );
153153 $centre = MapsUtils::getLatLon( $centre );
154154
155155 $this->centre_lat = Xml::escapeJsString( $centre['lat'] );
Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -35,7 +35,7 @@
3636
3737 // Only initialize the extension when all dependencies are present.
3838 if ( defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' ) ) {
39 - define( 'SM_VERSION', '0.5.5' );
 39+ define( 'SM_VERSION', '0.5.6' );
4040
4141 $smgScriptPath = ( isset( $wgExtensionAssetsPath ) && $wgExtensionAssetsPath ? $wgExtensionAssetsPath : $wgScriptPath . '/extensions' ) . '/SemanticMaps';
4242 $smgDir = dirname( __FILE__ ) . '/';
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php
@@ -303,7 +303,7 @@
304304 // If a centre value is set, use it.
305305 if ( strlen( $this->centre ) > 0 ) {
306306 // Geocode and convert if required.
307 - $centre = MapsGeocodeUtils::attemptToGeocode( $this->centre, $this->geoservice, $this->serviceName );
 307+ $centre = MapsGeocoder::attemptToGeocode( $this->centre, $this->geoservice, $this->serviceName );
308308 $centre = MapsUtils::getLatLon( $centre );
309309
310310 $this->centre_lat = $centre['lat'];

Status & tagging log