r63862 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r63861‎ | r63862 | r63863 >
Date:13:28, 17 March 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r63845
Modified paths:
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValueDescription.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php
@@ -75,7 +75,7 @@
7676 $this->m_longparts = false;
7777 $this->m_wikivalue = $value;
7878
79 - // first normalise some typical symbols
 79+ // Normalize the notation.
8080 $this->initDirectionLabels();
8181 $value = str_replace( array( ' ', $this->m_N, $this->m_E, $this->m_W, $this->m_S, ),
8282 array( ' ', 'N', 'E', 'W', 'S' ), $value );
@@ -84,10 +84,10 @@
8585 $value = str_replace( array( '″', '″', "''", '"', '´´', SM_GEO_MIN . SM_GEO_MIN ), SM_GEO_SEC, $value );
8686 $value = str_replace( array( '′', '′', "'", '´' ), SM_GEO_MIN, $value );
8787
88 - // now split the string
 88+ // Split the value string.
8989 $parts = preg_split( '/\s*(°|' . SM_GEO_MIN . '|' . SM_GEO_SEC . '|N|E|W|S|;)\s*/u', str_replace( ', ', ';', $value ) . ';', - 1, PREG_SPLIT_DELIM_CAPTURE );
9090 $curnum = false;
91 - $angles = array( false, false, false ); // temporary values for deg, min, sec
 91+ $angles = array( false, false, false ); // Temporary values for deg, min, sec
9292
9393 foreach ( $parts as $part ) {
9494 switch ( $part ) {
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php
@@ -23,6 +23,8 @@
2424 // Hook for initializing the Geographical Proximity query support.
2525 $wgHooks['smwGetSQLConditionForValue'][] = 'smfGetGeoProximitySQLCondition';
2626
 27+define( 'SM_CMP_NEAR', 101 ); // Define the near comparator for proximity queries.
 28+
2729 /**
2830 * Adds support for the geographical coordinate data type to Semantic MediaWiki.
2931 *
@@ -36,9 +38,8 @@
3739 /**
3840 * Custom SQL query extension for matching geographic coordinates.
3941 *
40 - * TODO: Parsing latitude and longitude from the DB key of the coordinates
41 - * value is cleary not a good approach. Instead, the geographic coordinate
42 - * value object should provide functions to access this data directly.
 42+ * TODO: Change the way coords are stored in the db from a string field to 2 float fields.
 43+ * The geographic coordinate value object should provide functions to access the lat and lon data directly.
4344 *
4445 * TODO: Add support for a per-coordinate set distance parameter.
4546 */
@@ -46,11 +47,13 @@
4748 $where = '';
4849 $dv = $description->getDatavalue();
4950
 51+ // Only execute the query when the description's type is geographical coordinates,
 52+ // the description is valid, and the near comparator is used.
5053 if ( ( $dv->getTypeID() != '_geo' )
5154 || ( !$dv->isValid() )
52 - || ( $description->getComparator() != SMW_CMP_LIKE )
53 - ) return true; // Only act on certain query conditions.
54 -
 55+ || ( $description->getComparator() != SM_CMP_NEAR )
 56+ ) return true;
 57+
5558 $keys = $dv->getDBkeys();
5659 $geoarray = explode( ',', $keys[0] );
5760
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValueDescription.php
@@ -29,4 +29,25 @@
3030 $this->m_distance = $distance;
3131 }
3232
 33+ public function getQueryString( $asvalue = false ) {
 34+ if ( $this->m_datavalue !== null ) {
 35+ switch ( $this->m_comparator ) {
 36+ case SMW_CMP_LEQ: $comparator = '<'; break;
 37+ case SMW_CMP_GEQ: $comparator = '>'; break;
 38+ case SMW_CMP_NEQ: $comparator = '!'; break;
 39+ case SMW_CMP_LIKE: $comparator = '~'; break;
 40+ default: case SMW_CMP_EQ:
 41+ $comparator = '';
 42+ break;
 43+ }
 44+ if ( $asvalue ) {
 45+ return $comparator . $this->m_datavalue->getWikiValue();
 46+ } else { // this only is possible for values of Type:Page
 47+ return '[[' . $comparator . $this->m_datavalue->getWikiValue() . ']]';
 48+ }
 49+ } else {
 50+ return $asvalue ? '+':''; // the else case may result in an error here (query without proper condition)
 51+ }
 52+ }
 53+
3354 }
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -51,7 +51,7 @@
5252
5353 $wgExtensionMessagesFiles['SemanticMaps'] = $smgDir . 'SemanticMaps.i18n.php';
5454
55 - // Include the GeoCoords SMW data type file.
 55+ // Include the GeoCoords related functionality.
5656 require_once( $smgDir . '/GeoCoords/SM_GeoCoords.php' );
5757 }
5858

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r63845Restructured geocoords support....jeroendedauw23:24, 16 March 2010

Status & tagging log