r65998 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65997‎ | r65998 | r65999 >
Date:21:54, 6 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Work on didstance query
Modified paths:
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValueDescription.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php
@@ -78,20 +78,23 @@
7979 if ( $value == '' ) {
8080 $this->addError( wfMsg( 'smw_novalues' ) );
8181 } else {
82 - // TODO: parse the parts here
8382 SMWDataValue::prepareValue( $value, $comparator );
 83+
 84+ $parts = explode( '(', $value );
8485
85 - $parts = array();
86 - preg_match( '/(.*)\((.*)\)/', $value, $parts );
87 -
88 - $coordinates = array_shift( $parts );
89 - $distance = count( $parts ) > 0 ? array_shift( $parts ) : false;
90 -
91 - if ( $distance !== false && !preg_match( '/^\d+(\.\d+)?$/', $distance ) ) {
92 - $this->addError( wfMsgExt( 'semanticmaps-unrecognizeddistance', array( 'parsemag' ), $distance ) );
93 - $distance = false;
 86+ $coordinates = trim( array_shift( $parts ) );
 87+ $distance = count( $parts ) > 0 ? trim( array_shift( $parts ) ) : false;
 88+
 89+ if ( $distance !== false ) {
 90+ if ( preg_match( '/^\d+(\.\d+)?\)$/', $distance ) ) {
 91+ $distance = substr( $distance, 0, -1 );
 92+ }
 93+ else {
 94+ $this->addError( wfMsgExt( 'semanticmaps-unrecognizeddistance', array( 'parsemag' ), $distance ) );
 95+ $distance = false;
 96+ }
9497 }
95 -
 98+
9699 $parsedCoords = MapsCoordinateParser::parseCoordinates( $coordinates );
97100 if ( $parsedCoords ) {
98101 $this->mCoordinateSet = $parsedCoords;
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValueDescription.php
@@ -68,7 +68,6 @@
6969 $coordinates = $dataValue->getCoordinateSet();
7070
7171 $comparator = $description->getComparator() == SMW_CMP_EQ ? '=' : '!=';
72 - //var_dump($comparator);exit;
7372
7473 // TODO: The field names are hardcoded in, since SMW offers no support for selection based on multiple fields.
7574 // Ideally SMW's setup should be changed to allow for this. Now the query can break when other extensions
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php
@@ -26,9 +26,10 @@
2727 protected $mBounds = false;
2828
2929 public function __construct( SMGeoCoordsValue $dataValue, $radius ) {
30 - parent::__construct( $dataValue );
 30+ parent::__construct( $dataValue, SM_CMP_NEAR );
3131
32 - // If the MapsGeoFunctions class is not loaded, we can not create the bounding box, so don't add any conditions.
 32+ // If the MapsGeoFunctions class is not loaded, we can not create the bounding box,
 33+ // so don't add any conditions.
3334 if ( self::geoFunctionsAreAvailable() ) {
3435 $dbKeys = $dataValue->getDBkeys();
3536
@@ -88,11 +89,13 @@
8990 * @return An associative array containing the limits with keys north, east, south and west.
9091 */
9192 private static function getBoundingBox( array $centerCoordinates, $circleRadius ) {
 93+ $centerCoordinates = array('lat' => 0, 'lon' => 0);
 94+ var_dump($centerCoordinates);
9295 $north = MapsGeoFunctions::findDestination( $centerCoordinates, 0, $circleRadius );
9396 $east = MapsGeoFunctions::findDestination( $centerCoordinates, 90, $circleRadius );
9497 $south = MapsGeoFunctions::findDestination( $centerCoordinates, 180, $circleRadius );
9598 $west = MapsGeoFunctions::findDestination( $centerCoordinates, 270, $circleRadius );
96 -
 99+var_dump($north);var_dump($east);var_dump($south);var_dump($west);exit;
97100 return array(
98101 'north' => $north['lat'],
99102 'east' => $east['lon'],
@@ -105,8 +108,7 @@
106109 * Returns a boolean indicating if MapsGeoFunctions is available.
107110 */
108111 private static function geoFunctionsAreAvailable() {
109 - global $wgAutoloadClasses;
110 - return array_key_exists( 'MapsGeoFunctions', $wgAutoloadClasses );
 112+ return class_exists( 'MapsGeoFunctions' );
111113 }
112114
113115 /**
@@ -122,7 +124,7 @@
123125 */
124126 public static function getSQLCondition( &$whereSQL, SMWDescription $description, $tablename, $fieldname, DatabaseBase $dbs ) {
125127 $dataValue = $description->getDatavalue();
126 -
 128+
127129 // Only execute the query when the description's type is geographical coordinates,
128130 // the description is valid, and the near comparator is used.
129131 if ( $dataValue->getTypeID() != '_geo'
@@ -136,12 +138,12 @@
137139 $east = $dbs->addQuotes( $boundingBox['east'] );
138140 $south = $dbs->addQuotes( $boundingBox['south'] );
139141 $west = $dbs->addQuotes( $boundingBox['west'] );
140 -
 142+
141143 // TODO: The field names are hardcoded in, since SMW offers no support for selection based on multiple fields.
142144 // Ideally SMW's setup should be changed to allow for this. Now the query can break when other extensions
143145 // add their own semantic tables with similar signatures.
144146 $whereSQL .= "{$tablename}.lat < $north && {$tablename}.lat > $south && {$tablename}.lon < $east && {$tablename}.lon > $west";
145 -
 147+var_dump($whereSQL);exit;
146148 return true;
147149 }
148150 }
\ No newline at end of file

Status & tagging log