r65067 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65066‎ | r65067 | r65068 >
Date:14:36, 15 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6 - GeoCoordsDescription changed in AreaDescription and moved over some code to this class from the distance query hook
Modified paths:
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php (added) (history)
  • /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 (deleted) (history)
  • /trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValueDescription.php
@@ -1,65 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * File holding the SMGeoCoordsValueDescription class.
6 - *
7 - * @file SM_GeoCoordsValueDescription.php
8 - * @ingroup SemanticMaps
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if ( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -/**
18 - * Description of one data value of type Goegraphical Coordinates.
19 - *
20 - * @author Jeroen De Dauw
21 - *
22 - * @ingroup SemanticMaps
23 - *
24 - * TODO: storing the distance here does not seem quite right
25 - */
26 -class SMGeoCoordsValueDescription extends SMWValueDescription {
27 - protected $m_distance;
28 -
29 - public function __construct( SMGeoCoordsValue $datavalue, $distance, $comparator = SMW_CMP_EQ ) {
30 - parent::__construct( $datavalue, $comparator );
31 - $this->m_distance = $distance;
32 - }
33 -
34 - /**
35 - * @see SMWDescription:getQueryString
36 - * @param Boolean $asvalue
37 - */
38 - public function getQueryString( $asValue = false ) {
39 - if ( $this->m_datavalue !== null ) {
40 - $queryString = $this->m_datavalue->getWikiValue();
41 - return $asValue ? $queryString : "[[$queryString]]";
42 - } else {
43 - return $asValue ? '+' : '';
44 - }
45 - }
46 -
47 - /**
48 - * @see SMWDescription:prune
49 - */
50 - public function prune( &$maxsize, &$maxdepth, &$log ) {
51 - if ( ( $maxsize < $this->getSize() ) || ( $maxdepth < $this->getDepth() ) ) {
52 - $log[] = $this->getQueryString();
53 - $result = new SMWThingDescription();
54 - $result->setPrintRequests( $this->getPrintRequests() );
55 - return $result;
56 - } else {
57 - $maxsize = $maxsize - $this->getSize();
58 - $maxdepth = $maxdepth - $this->getDepth();
59 - return $this;
60 - }
61 - }
62 -
63 - public function getDistance() {
64 - return $this->m_distance;
65 - }
66 -}
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php
@@ -0,0 +1,111 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the SMAreaValueDescription class.
 6+ *
 7+ * @file SM_AreaValueDescription.php
 8+ * @ingroup SemanticMaps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+/**
 18+ * Description of one data value of type Goegraphical Areas.
 19+ *
 20+ * @author Jeroen De Dauw
 21+ *
 22+ * @ingroup SemanticMaps
 23+ *
 24+ * TODO: storing the distance here does not seem quite right
 25+ */
 26+class SMAreaValueDescription extends SMWValueDescription {
 27+ protected $mBounds = false;
 28+
 29+ public function __construct( SMGeoCoordsValue $dataValue, $radius, $comparator = SMW_CMP_EQ ) {
 30+ parent::__construct( $dataValue, $comparator );
 31+
 32+ // TODO: get user provided distance
 33+ //global $smgGeoCoordDistance;
 34+ //$distance = $smgGeoCoordDistance;
 35+
 36+ // If the MapsGeoFunctions class is not loaded, we can not create the bounding box, so don't add any conditions.
 37+ if ( self::geoFunctionsAreAvailable() ) {
 38+ $dbKeys = $dataValue->getDBkeys();
 39+
 40+ $this->mBounds = self::getBoundingBox(
 41+ array(
 42+ 'lat' => $dbKeys[0],
 43+ 'lon' => $dbKeys[1]
 44+ ),
 45+ $radius
 46+ );
 47+ }
 48+ }
 49+
 50+ /**
 51+ * @see SMWDescription:getQueryString
 52+ * @param Boolean $asvalue
 53+ */
 54+ public function getQueryString( $asValue = false ) {
 55+ if ( $this->m_datavalue !== null ) {
 56+ $queryString = $this->m_datavalue->getWikiValue();
 57+ return $asValue ? $queryString : "[[$queryString]]";
 58+ } else {
 59+ return $asValue ? '+' : '';
 60+ }
 61+ }
 62+
 63+ /**
 64+ * @see SMWDescription:prune
 65+ */
 66+ public function prune( &$maxsize, &$maxdepth, &$log ) {
 67+ if ( ( $maxsize < $this->getSize() ) || ( $maxdepth < $this->getDepth() ) ) {
 68+ $log[] = $this->getQueryString();
 69+ $result = new SMWThingDescription();
 70+ $result->setPrintRequests( $this->getPrintRequests() );
 71+ return $result;
 72+ } else {
 73+ $maxsize = $maxsize - $this->getSize();
 74+ $maxdepth = $maxdepth - $this->getDepth();
 75+ return $this;
 76+ }
 77+ }
 78+
 79+ public function getBounds() {
 80+ return $this->mBounds;
 81+ }
 82+
 83+ /**
 84+ * Returns the lat and lon limits of a bounding box around a circle defined by the provided parameters.
 85+ *
 86+ * @param array $centerCoordinates Array containing non-directional float coordinates with lat and lon keys.
 87+ * @param float $circleRadius The radidus of the circle to create a bounding box for, in km.
 88+ *
 89+ * @return An associative array containing the limits with keys north, east, south and west.
 90+ */
 91+ private static function getBoundingBox( array $centerCoordinates, $circleRadius ) {
 92+ $north = MapsGeoFunctions::findDestination( $centerCoordinates, 0, $circleRadius );
 93+ $east = MapsGeoFunctions::findDestination( $centerCoordinates, 90, $circleRadius );
 94+ $south = MapsGeoFunctions::findDestination( $centerCoordinates, 180, $circleRadius );
 95+ $west = MapsGeoFunctions::findDestination( $centerCoordinates, 270, $circleRadius );
 96+
 97+ return array(
 98+ 'north' => $north['lat'],
 99+ 'east' => $east['lon'],
 100+ 'south' => $south['lat'],
 101+ 'west' => $west['lon'],
 102+ );
 103+ }
 104+
 105+ /**
 106+ * Returns a boolean indicating if MapsGeoFunctions is available.
 107+ */
 108+ private static function geoFunctionsAreAvailable() {
 109+ global $wgAutoloadClasses;
 110+ return array_key_exists( 'MapsGeoFunctions', $wgAutoloadClasses );
 111+ }
 112+}
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php
@@ -41,16 +41,12 @@
4242 * Defines the layout for the smw_coords table which is used to store value of the GeoCoords type.
4343 *
4444 * @param array $propertyTables The property tables defined by SMW, passed by reference.
45 - *
46 - * FIXME
4745 */
4846 public static function initGeoCoordsTable( array $propertyTables ) {
49 - /*
5047 $propertyTables['smw_coords'] = new SMWSQLStore2Table(
5148 'sm_coords',
5249 array( 'lat' => 'f', 'lon' => 'f' )
5350 );
54 - */
5551 return true;
5652 }
5753
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php
@@ -18,7 +18,7 @@
1919 $wgAutoloadClasses['SMGeoCoordsValue'] = dirname( __FILE__ ) . '/SM_GeoCoordsValue.php';
2020
2121 // Registration of the Geographical Coordinate value description class.
22 -$wgAutoloadClasses['SMGeoCoordsValueDescription'] = dirname( __FILE__ ) . '/SM_GeoCoordsValueDescription.php';
 22+$wgAutoloadClasses['SMAreaValueDescription'] = dirname( __FILE__ ) . '/SM_AreaValueDescription.php';
2323
2424 // Hook for initializing the Geographical Coordinate type.
2525 $wgHooks['smwInitDatatypes'][] = 'SMGeoCoordsValue::initGeoCoordsType';
@@ -36,19 +36,14 @@
3737 * Custom SQL query extension for matching geographic coordinates.
3838 *
3939 * @param string $whereSQL The SQL where condition to expand.
40 - * @param SMGeoCoordsValueDescription $description The description of center coordinate.
 40+ * @param SMAreaValueDescription $description The description of center coordinate.
4141 * @param string $tablename
4242 * @param string $fieldname
43 - * @param Database $dbs
 43+ * @param DatabaseBase $dbs
4444 *
4545 * @return true
4646 */
47 - public static function getGeoProximitySQLCondition( &$whereSQL, SMGeoCoordsValueDescription $description, $tablename, $fieldname, DatabaseBase $dbs ) {
48 - // If the MapsGeoFunctions class is not loaded, we can not create the bounding box, so don't add any conditions.
49 - if ( !self::geoFunctionsAreAvailable() ) {
50 - return true;
51 - }
52 -
 47+ public static function getGeoProximitySQLCondition( &$whereSQL, SMAreaValueDescription $description, $tablename, $fieldname, DatabaseBase $dbs ) {
5348 $dataValue = $description->getDatavalue();
5449
5550 // Only execute the query when the description's type is geographical coordinates,
@@ -56,23 +51,10 @@
5752 if ( ( $dataValue->getTypeID() != '_geo' )
5853 || ( !$dataValue->isValid() )
5954 || ( $description->getComparator() != SM_CMP_NEAR )
60 - ) return true;
61 -
62 - $dbKeys = $dataValue->getDBkeys();
63 -
64 - // TODO: get user provided distance
65 - // $dataValue->getDistance()
66 - global $smgGeoCoordDistance;
67 - $distance = $smgGeoCoordDistance;
 55+ ) return true;
6856
69 - $boundingBox = self::getBoundingBox(
70 - array(
71 - 'lat' => $dbKeys[0],
72 - 'lon' => $dbKeys[1]
73 - ),
74 - $distance
75 - );
76 -
 57+ $boundingBox = $description->getBounds();
 58+
7759 $north = $dbs->addQuotes( $boundingBox['north'] );
7860 $east = $dbs->addQuotes( $boundingBox['east'] );
7961 $south = $dbs->addQuotes( $boundingBox['south'] );
@@ -83,34 +65,6 @@
8466 return true;
8567 }
8668
87 - /**
88 - * Returns the lat and lon limits of a bounding box around a circle defined by the provided parameters.
89 - *
90 - * @param array $centerCoordinates Array containing non-directional float coordinates with lat and lon keys.
91 - * @param float $circleRadius The radidus of the circle to create a bounding box for, in km.
92 - *
93 - * @return An associative array containing the limits with keys north, east, south and west.
94 - */
95 - private static function getBoundingBox( array $centerCoordinates, $circleRadius ) {
96 - $north = MapsGeoFunctions::findDestination( $centerCoordinates, 0, $circleRadius );
97 - $east = MapsGeoFunctions::findDestination( $centerCoordinates, 90, $circleRadius );
98 - $south = MapsGeoFunctions::findDestination( $centerCoordinates, 180, $circleRadius );
99 - $west = MapsGeoFunctions::findDestination( $centerCoordinates, 270, $circleRadius );
10069
101 - return array(
102 - 'north' => $north['lat'],
103 - 'east' => $east['lon'],
104 - 'south' => $south['lat'],
105 - 'west' => $west['lon'],
106 - );
107 - }
108 -
109 - /**
110 - * Returns a boolean indicating if MapsGeoFunctions is available.
111 - */
112 - private static function geoFunctionsAreAvailable() {
113 - global $wgAutoloadClasses;
114 - return array_key_exists( 'MapsGeoFunctions', $wgAutoloadClasses );
115 - }
11670 }
11771
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php
@@ -131,7 +131,7 @@
132132
133133 $manager = new ValidatorManager();
134134
135 - $result = $manager->manageMapparameters( $mapProperties, $parameterInfo );
 135+ $result = $manager->manageParameters( $mapProperties, $parameterInfo );
136136
137137 $showMap = $result !== false;
138138

Status & tagging log