Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php |
— | — | @@ -38,15 +38,37 @@ |
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
| 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 | + /** |
42 | 58 | * Defines the layout for the smw_coords table which is used to store value of the GeoCoords type. |
43 | 59 | * |
44 | 60 | * @param array $propertyTables The property tables defined by SMW, passed by reference. |
45 | 61 | */ |
46 | 62 | 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 | + |
47 | 68 | $propertyTables['smw_coords'] = new SMWSQLStore2Table( |
48 | 69 | 'sm_coords', |
49 | | - array( 'lat' => 'f', 'lon' => 'f' ) |
| 70 | + $signature |
50 | 71 | ); |
| 72 | + |
51 | 73 | return true; |
52 | 74 | } |
53 | 75 | |
— | — | @@ -131,10 +153,15 @@ |
132 | 154 | * @see SMWDataValue::parseDBkeys |
133 | 155 | */ |
134 | 156 | protected function parseDBkeys( $args ) { |
135 | | - global $smgQPCoodFormat, $smgQPCoodDirectional; |
| 157 | + global $smgUseSpatialExtensions, $smgQPCoodFormat, $smgQPCoodDirectional; |
136 | 158 | |
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 | + } |
139 | 166 | |
140 | 167 | $this->m_caption = MapsCoordinateParser::formatCoordinates( |
141 | 168 | $this->mCoordinateSet, |
— | — | @@ -151,17 +178,22 @@ |
152 | 179 | public function getDBkeys() { |
153 | 180 | $this->unstub(); |
154 | 181 | |
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 | + } |
159 | 191 | } |
160 | 192 | |
161 | 193 | /** |
162 | 194 | * @see SMWDataValue::getSignature |
163 | 195 | */ |
164 | 196 | public function getSignature() { |
165 | | - return 'ff'; |
| 197 | + return $smgUseSpatialExtensions ? 'c' : 'ff'; |
166 | 198 | } |
167 | 199 | |
168 | 200 | /** |
— | — | @@ -170,11 +202,15 @@ |
171 | 203 | public function getShortWikiText( $linked = null ) { |
172 | 204 | if ( $this->isValid() && ( $linked !== null ) && ( $linked !== false ) ) { |
173 | 205 | SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP ); |
| 206 | + |
| 207 | + // TODO: fix lang keys so they include the space and coordinates. |
| 208 | + |
174 | 209 | return '<span class="smwttinline">' . htmlspecialchars( $this->m_caption ) . '<span class="smwttcontent">' . |
175 | 210 | htmlspecialchars ( wfMsgForContent( 'maps-latitude' ) . ' ' . $this->mCoordinateSet['lat'] ) . '<br />' . |
176 | 211 | htmlspecialchars ( wfMsgForContent( 'maps-longitude' ) . ' ' . $this->mCoordinateSet['lon'] ) . |
177 | 212 | '</span></span>'; |
178 | | - } else { |
| 213 | + } |
| 214 | + else { |
179 | 215 | return htmlspecialchars( $this->m_caption ); |
180 | 216 | } |
181 | 217 | } |
— | — | @@ -192,7 +228,8 @@ |
193 | 229 | public function getLongWikiText( $linked = null ) { |
194 | 230 | if ( !$this->isValid() ) { |
195 | 231 | return $this->getErrorText(); |
196 | | - } else { |
| 232 | + } |
| 233 | + else { |
197 | 234 | global $smgQPCoodFormat, $smgQPCoodDirectional; |
198 | 235 | return MapsCoordinateParser::formatCoordinates( $this->mCoordinateSet, $smgQPCoodFormat, $smgQPCoodDirectional ); |
199 | 236 | } |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php |
— | — | @@ -22,5 +22,7 @@ |
23 | 23 | // Hook for initializing the Geographical Coordinate type. |
24 | 24 | $wgHooks['smwInitDatatypes'][] = 'SMGeoCoordsValue::initGeoCoordsType'; |
25 | 25 | |
| 26 | +$wgHooks['SMWCustomSQLStoreFieldType'][] = 'SMGeoCoordsValue::initGeoCoordsFieldTypes'; |
| 27 | + |
26 | 28 | // Hook for defining a table to store geographical coordinates in. |
27 | 29 | $wgHooks['SMWPropertyTables'][] = 'SMGeoCoordsValue::initGeoCoordsTable'; |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_AreaValueDescription.php |
— | — | @@ -59,13 +59,8 @@ |
60 | 60 | // If the MapsGeoFunctions class is not loaded, we can not create the bounding box, |
61 | 61 | // so don't add any conditions. |
62 | 62 | if ( self::geoFunctionsAreAvailable() ) { |
63 | | - $dbKeys = $dataValue->getDBkeys(); |
64 | | - |
65 | 63 | $this->mBounds = self::getBoundingBox( |
66 | | - array( |
67 | | - 'lat' => $dbKeys[0], |
68 | | - 'lon' => $dbKeys[1] |
69 | | - ), |
| 64 | + $dataValue->getCoordinateSet(), |
70 | 65 | $radius |
71 | 66 | ); |
72 | 67 | } |
— | — | @@ -147,6 +142,8 @@ |
148 | 143 | * @return true |
149 | 144 | */ |
150 | 145 | public function getSQLCondition( $tableName, array $fieldNames, DatabaseBase $dbs ) { |
| 146 | + global $smgUseSpatialExtensions; |
| 147 | + |
151 | 148 | $dataValue = $this->getDatavalue(); |
152 | 149 | |
153 | 150 | // Only execute the query when the description's type is geographical coordinates, |
— | — | @@ -167,16 +164,22 @@ |
168 | 165 | |
169 | 166 | $isEq = $this->getComparator() == SMW_CMP_EQ; |
170 | 167 | |
171 | | - $smallerThen = $isEq ? '<' : '>='; |
172 | | - $biggerThen = $isEq ? '>' : '<='; |
173 | | - $joinCond = $isEq ? '&&' : '||'; |
174 | | - |
175 | 168 | $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"; |
180 | 169 | |
| 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 | + |
181 | 184 | return implode( " $joinCond ", $conditions ); |
182 | 185 | } |
183 | 186 | } |
\ No newline at end of file |
Index: trunk/extensions/SemanticMaps/SM_Settings.php |
— | — | @@ -52,6 +52,16 @@ |
53 | 53 | |
54 | 54 | |
55 | 55 | |
| 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 | + |
56 | 66 | # Queries |
57 | 67 | |
58 | 68 | # Boolean. The default value for the forceshow parameter. Will force a map to be shown even when there are no query results |