Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php |
— | — | @@ -75,7 +75,7 @@ |
76 | 76 | $this->m_longparts = false; |
77 | 77 | $this->m_wikivalue = $value; |
78 | 78 | |
79 | | - // first normalise some typical symbols |
| 79 | + // Normalize the notation. |
80 | 80 | $this->initDirectionLabels(); |
81 | 81 | $value = str_replace( array( ' ', $this->m_N, $this->m_E, $this->m_W, $this->m_S, ), |
82 | 82 | array( ' ', 'N', 'E', 'W', 'S' ), $value ); |
— | — | @@ -84,10 +84,10 @@ |
85 | 85 | $value = str_replace( array( '″', '″', "''", '"', '´´', SM_GEO_MIN . SM_GEO_MIN ), SM_GEO_SEC, $value ); |
86 | 86 | $value = str_replace( array( '′', '′', "'", '´' ), SM_GEO_MIN, $value ); |
87 | 87 | |
88 | | - // now split the string |
| 88 | + // Split the value string. |
89 | 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 ); |
90 | 90 | $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 |
92 | 92 | |
93 | 93 | foreach ( $parts as $part ) { |
94 | 94 | switch ( $part ) { |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php |
— | — | @@ -23,6 +23,8 @@ |
24 | 24 | // Hook for initializing the Geographical Proximity query support. |
25 | 25 | $wgHooks['smwGetSQLConditionForValue'][] = 'smfGetGeoProximitySQLCondition'; |
26 | 26 | |
| 27 | +define( 'SM_CMP_NEAR', 101 ); // Define the near comparator for proximity queries. |
| 28 | + |
27 | 29 | /** |
28 | 30 | * Adds support for the geographical coordinate data type to Semantic MediaWiki. |
29 | 31 | * |
— | — | @@ -36,9 +38,8 @@ |
37 | 39 | /** |
38 | 40 | * Custom SQL query extension for matching geographic coordinates. |
39 | 41 | * |
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. |
43 | 44 | * |
44 | 45 | * TODO: Add support for a per-coordinate set distance parameter. |
45 | 46 | */ |
— | — | @@ -46,11 +47,13 @@ |
47 | 48 | $where = ''; |
48 | 49 | $dv = $description->getDatavalue(); |
49 | 50 | |
| 51 | + // Only execute the query when the description's type is geographical coordinates, |
| 52 | + // the description is valid, and the near comparator is used. |
50 | 53 | if ( ( $dv->getTypeID() != '_geo' ) |
51 | 54 | || ( !$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 | + |
55 | 58 | $keys = $dv->getDBkeys(); |
56 | 59 | $geoarray = explode( ',', $keys[0] ); |
57 | 60 | |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValueDescription.php |
— | — | @@ -29,4 +29,25 @@ |
30 | 30 | $this->m_distance = $distance; |
31 | 31 | } |
32 | 32 | |
| 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 | + |
33 | 54 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/SemanticMaps.php |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | |
53 | 53 | $wgExtensionMessagesFiles['SemanticMaps'] = $smgDir . 'SemanticMaps.i18n.php'; |
54 | 54 | |
55 | | - // Include the GeoCoords SMW data type file. |
| 55 | + // Include the GeoCoords related functionality. |
56 | 56 | require_once( $smgDir . '/GeoCoords/SM_GeoCoords.php' ); |
57 | 57 | } |
58 | 58 | |