r66678 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r66677‎ | r66678 | r66679 >
Date:03:30, 20 May 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6 - added infrastructure for spacial extensions support and hook for custom SMW field type signatures
Modified paths:
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SM_Settings.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php
@@ -38,15 +38,37 @@
3939 }
4040
4141 /**
 42+ * Defines the signature for geographical fields needed for the smw_coords table.
 43+ *
 44+ * @param array $fieldTypes The field types defined by SMW, passed by reference.
 45+ */
 46+ public static function initGeoCoordsFieldTypes( array $fieldTypes ) {
 47+ global $smgUseSpatialExtensions;
 48+
 49+ // Only add the table when the SQL store is not a postgres database, and it has not been added by SMW itself.
 50+ if ( $smgUseSpatialExtensions && !array_key_exists( 'c', $fieldTypes ) ) {
 51+ $fieldTypes['c'] = 'WUHAAAA'; // TODO: WUHAAAA is not a valid field type o_O
 52+ }
 53+
 54+ return true;
 55+ }
 56+
 57+ /**
4258 * Defines the layout for the smw_coords table which is used to store value of the GeoCoords type.
4359 *
4460 * @param array $propertyTables The property tables defined by SMW, passed by reference.
4561 */
4662 public static function initGeoCoordsTable( array $propertyTables ) {
 63+ global $smgUseSpatialExtensions;
 64+
 65+ // No spatial extensions support for postgres yet, so just store as 2 float fields.
 66+ $signature = $smgUseSpatialExtensions ? array( 'c' ) : array( 'lat' => 'f', 'lon' => 'f' );
 67+
4768 $propertyTables['smw_coords'] = new SMWSQLStore2Table(
4869 'sm_coords',
49 - array( 'lat' => 'f', 'lon' => 'f' )
 70+ $signature
5071 );
 72+
5173 return true;
5274 }
5375
@@ -131,10 +153,15 @@
132154 * @see SMWDataValue::parseDBkeys
133155 */
134156 protected function parseDBkeys( $args ) {
135 - global $smgQPCoodFormat, $smgQPCoodDirectional;
 157+ global $smgUseSpatialExtensions, $smgQPCoodFormat, $smgQPCoodDirectional;
136158
137 - $this->mCoordinateSet['lat'] = $args[0];
138 - $this->mCoordinateSet['lon'] = $args[1];
 159+ if ( $smgUseSpatialExtensions ) {
 160+ // TODO
 161+ }
 162+ else {
 163+ $this->mCoordinateSet['lat'] = $args[0];
 164+ $this->mCoordinateSet['lon'] = $args[1];
 165+ }
139166
140167 $this->m_caption = MapsCoordinateParser::formatCoordinates(
141168 $this->mCoordinateSet,
@@ -151,17 +178,22 @@
152179 public function getDBkeys() {
153180 $this->unstub();
154181
155 - return array(
156 - $this->mCoordinateSet['lat'],
157 - $this->mCoordinateSet['lon']
158 - );
 182+ if ( $smgUseSpatialExtensions ) {
 183+ // TODO
 184+ }
 185+ else {
 186+ return array(
 187+ $this->mCoordinateSet['lat'],
 188+ $this->mCoordinateSet['lon']
 189+ );
 190+ }
159191 }
160192
161193 /**
162194 * @see SMWDataValue::getSignature
163195 */
164196 public function getSignature() {
165 - return 'ff';
 197+ return $smgUseSpatialExtensions ? 'c' : 'ff';
166198 }
167199
168200 /**
@@ -170,11 +202,15 @@
171203 public function getShortWikiText( $linked = null ) {
172204 if ( $this->isValid() && ( $linked !== null ) && ( $linked !== false ) ) {
173205 SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP );
 206+
 207+ // TODO: fix lang keys so they include the space and coordinates.
 208+
174209 return '<span class="smwttinline">' . htmlspecialchars( $this->m_caption ) . '<span class="smwttcontent">' .
175210 htmlspecialchars ( wfMsgForContent( 'maps-latitude' ) . ' ' . $this->mCoordinateSet['lat'] ) . '<br />' .
176211 htmlspecialchars ( wfMsgForContent( 'maps-longitude' ) . ' ' . $this->mCoordinateSet['lon'] ) .
177212 '</span></span>';
178 - } else {
 213+ }
 214+ else {
179215 return htmlspecialchars( $this->m_caption );
180216 }
181217 }
@@ -192,7 +228,8 @@
193229 public function getLongWikiText( $linked = null ) {
194230 if ( !$this->isValid() ) {
195231 return $this->getErrorText();
196 - } else {
 232+ }
 233+ else {
197234 global $smgQPCoodFormat, $smgQPCoodDirectional;
198235 return MapsCoordinateParser::formatCoordinates( $this->mCoordinateSet, $smgQPCoodFormat, $smgQPCoodDirectional );
199236 }
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php
@@ -22,5 +22,7 @@
2323 // Hook for initializing the Geographical Coordinate type.
2424 $wgHooks['smwInitDatatypes'][] = 'SMGeoCoordsValue::initGeoCoordsType';
2525
 26+$wgHooks['SMWCustomSQLStoreFieldType'][] = 'SMGeoCoordsValue::initGeoCoordsFieldTypes';
 27+
2628 // Hook for defining a table to store geographical coordinates in.
2729 $wgHooks['SMWPropertyTables'][] = 'SMGeoCoordsValue::initGeoCoordsTable';
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php
@@ -59,13 +59,8 @@
6060 // If the MapsGeoFunctions class is not loaded, we can not create the bounding box,
6161 // so don't add any conditions.
6262 if ( self::geoFunctionsAreAvailable() ) {
63 - $dbKeys = $dataValue->getDBkeys();
64 -
6563 $this->mBounds = self::getBoundingBox(
66 - array(
67 - 'lat' => $dbKeys[0],
68 - 'lon' => $dbKeys[1]
69 - ),
 64+ $dataValue->getCoordinateSet(),
7065 $radius
7166 );
7267 }
@@ -147,6 +142,8 @@
148143 * @return true
149144 */
150145 public function getSQLCondition( $tableName, array $fieldNames, DatabaseBase $dbs ) {
 146+ global $smgUseSpatialExtensions;
 147+
151148 $dataValue = $this->getDatavalue();
152149
153150 // Only execute the query when the description's type is geographical coordinates,
@@ -167,16 +164,22 @@
168165
169166 $isEq = $this->getComparator() == SMW_CMP_EQ;
170167
171 - $smallerThen = $isEq ? '<' : '>=';
172 - $biggerThen = $isEq ? '>' : '<=';
173 - $joinCond = $isEq ? '&&' : '||';
174 -
175168 $conditions = array();
176 - $conditions[] = "{$tableName}.$fieldNames[0] $smallerThen $north";
177 - $conditions[] = "{$tableName}.$fieldNames[0] $biggerThen $south";
178 - $conditions[] = "{$tableName}.$fieldNames[1] $smallerThen $east";
179 - $conditions[] = "{$tableName}.$fieldNames[1] $biggerThen $west";
180169
 170+ if ( $smgUseSpatialExtensions ) {
 171+ // TODO
 172+ }
 173+ else {
 174+ $smallerThen = $isEq ? '<' : '>=';
 175+ $biggerThen = $isEq ? '>' : '<=';
 176+ $joinCond = $isEq ? '&&' : '||';
 177+
 178+ $conditions[] = "{$tableName}.$fieldNames[0] $smallerThen $north";
 179+ $conditions[] = "{$tableName}.$fieldNames[0] $biggerThen $south";
 180+ $conditions[] = "{$tableName}.$fieldNames[1] $smallerThen $east";
 181+ $conditions[] = "{$tableName}.$fieldNames[1] $biggerThen $west";
 182+ }
 183+
181184 return implode( " $joinCond ", $conditions );
182185 }
183186 }
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/SM_Settings.php
@@ -52,6 +52,16 @@
5353
5454
5555
 56+# General
 57+
 58+ # Boolean. Indicates if spatial extensions should be used for coordinate storage.
 59+ # Spatial extensions significantly speed up querying, but are not present by default on postgres databases.
 60+ # If this value is false, coordinates will be stored in 2 float fields.
 61+ # You are unlikely to need to change this setting, so don't unless you know what you are doing!
 62+ $smgUseSpatialExtensions = false; // $wgDBtype != 'postgres';
 63+
 64+
 65+
5666 # Queries
5767
5868 # Boolean. The default value for the forceshow parameter. Will force a map to be shown even when there are no query results

Status & tagging log