r86438 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86437‎ | r86438 | r86439 >
Date:22:07, 19 April 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
matching DataValue/DataItem changes in SMW
Modified paths:
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)
  • /trunk/extensions/SemanticMaps/includes/SM_DI_GeoCoord.php (added) (history)
  • /trunk/extensions/SemanticMaps/includes/SM_GeoCoordsHooks.php (modified) (history)
  • /trunk/extensions/SemanticMaps/includes/SM_GeoCoordsValue.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/includes/SM_DI_GeoCoord.php
@@ -0,0 +1,66 @@
 2+<?php
 3+
 4+/**
 5+ * Implementation of dataitems that are geographic coordinates.
 6+ *
 7+ * @since 0.8
 8+ *
 9+ * @file SM_DI_GeoCoord.php
 10+ * @ingroup SemanticMaps
 11+ *
 12+ * @licence GNU GPL v3
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class SMDIGeoCoord extends SMWDataItem {
 16+
 17+ protected $coordinateSet;
 18+ protected $wikiValue;
 19+
 20+ public function __construct( array $coords, $typeid = '_geo' ) {
 21+ parent::__construct( $typeid );
 22+
 23+ $this->coordinateSet = $coords;
 24+
 25+ //throw new SMWDataItemException( "Initialisation value '$number' is not a number." );
 26+ }
 27+
 28+ public function getDIType() {
 29+ return SMWDataItem::TYPE_GEO;
 30+ }
 31+
 32+ /**
 33+ * @since 0.8
 34+ *
 35+ * @return array
 36+ */
 37+ public function getCoordinateSet() {
 38+ return $this->coordinateSet;
 39+ }
 40+
 41+ public function getSortKey() {
 42+ return $this->coordinateSet['lat']; // TODO
 43+ }
 44+
 45+ public function getSerialization() {
 46+ global $smgQPCoodFormat, $smgQPCoodDirectional;
 47+ return MapsCoordinateParser::formatCoordinates( $this->coordinateSet, $smgQPCoodFormat, $smgQPCoodDirectional );
 48+ }
 49+
 50+ /**
 51+ * Create a data item from the provided serialization string and type
 52+ * ID.
 53+ * @note PHP can convert any string to some number, so we do not do
 54+ * validation here (because this would require less efficient parsing).
 55+ * @return SMWDINumber
 56+ */
 57+ public static function doUnserialize( $serialization, $typeid ) {
 58+ $parsedCoords = MapsCoordinateParser::parseCoordinates( $serialization );
 59+
 60+ if ( $parsedCoords === false || !is_array( $parsedCoords ) ) {
 61+ throw new Exception( 'Unserialization of coordinates failed' );
 62+ }
 63+
 64+ return new self( $parsedCoords, $typeid );
 65+ }
 66+
 67+}
Index: trunk/extensions/SemanticMaps/includes/SM_GeoCoordsValue.php
@@ -15,7 +15,6 @@
1616 */
1717 class SMGeoCoordsValue extends SMWDataValue {
1818
19 - protected $coordinateSet;
2019 protected $wikiValue;
2120
2221 /**
@@ -75,7 +74,7 @@
7675 if ( $value == '' ) {
7776 $this->addError( wfMsg( 'smw_novalues' ) );
7877 } else {
79 - SMWDataValue::prepareValue( $value, $comparator );
 78+ SMWDataValue::prepareValue( $value, $comparator );
8079
8180 $parts = explode( '(', $value );
8281
@@ -93,14 +92,15 @@
9493
9594 $parsedCoords = MapsCoordinateParser::parseCoordinates( $coordinates );
9695 if ( $parsedCoords ) {
97 - $this->coordinateSet = $parsedCoords;
98 -
 96+ $this->m_dataitem = new SMDIGeoCoord( $parsedCoords, $this->m_typeid );
 97+
9998 if ( $this->m_caption === false && !$asQuery ) {
10099 global $smgQPCoodFormat, $smgQPCoodDirectional;
101100 $this->m_caption = MapsCoordinateParser::formatCoordinates( $parsedCoords, $smgQPCoodFormat, $smgQPCoodDirectional );
102101 }
103102 } else {
104103 $this->addError( wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $coordinates, 1 ) );
 104+ $this->m_dataitem = new SMDIGeoCoord( array(0, 0), $this->m_typeid ); // make sure this is always set
105105 }
106106 }
107107
@@ -127,17 +127,8 @@
128128 * @since 0.6
129129 */
130130 protected function parseDBkeys( $args ) {
131 - global $smgQPCoodFormat, $smgQPCoodDirectional;
132 -
133 - $this->coordinateSet['lat'] = (float)$args[0];
134 - $this->coordinateSet['lon'] = (float)$args[1];
135 -
136 - $this->m_caption = MapsCoordinateParser::formatCoordinates(
137 - $this->coordinateSet,
138 - $smgQPCoodFormat,
139 - $smgQPCoodDirectional
140 - );
141 -
 131+ $this->setDataItem( new SMDIGeoCoord( array( (float)$args[0], (float)$args[1] ), $this->m_typeid ) );
 132+ $this->m_caption = $this->m_dataitem->getSerialization();
142133 $this->wikiValue = $this->m_caption;
143134 }
144135
@@ -148,10 +139,11 @@
149140 */
150141 public function getDBkeys() {
151142 $this->unstub();
152 -
 143+ $coordinateSet = $this->m_dataitem->getCoordinateSet();
 144+
153145 return array(
154 - $this->coordinateSet['lat'],
155 - $this->coordinateSet['lon']
 146+ $coordinateSet['lat'],
 147+ $coordinateSet['lon']
156148 );
157149 }
158150
@@ -174,10 +166,11 @@
175167 SMWOutputs::requireHeadItem( SMW_HEADER_TOOLTIP );
176168
177169 // TODO: fix lang keys so they include the space and coordinates.
178 -
 170+ $coordinateSet = $this->m_dataitem->getCoordinateSet();
 171+
179172 return '<span class="smwttinline">' . htmlspecialchars( $this->m_caption ) . '<span class="smwttcontent">' .
180 - htmlspecialchars ( wfMsgForContent( 'maps-latitude' ) . ' ' . $this->coordinateSet['lat'] ) . '<br />' .
181 - htmlspecialchars ( wfMsgForContent( 'maps-longitude' ) . ' ' . $this->coordinateSet['lon'] ) .
 173+ htmlspecialchars ( wfMsgForContent( 'maps-latitude' ) . ' ' . $coordinateSet['lat'] ) . '<br />' .
 174+ htmlspecialchars ( wfMsgForContent( 'maps-longitude' ) . ' ' . $coordinateSet['lon'] ) .
182175 '</span></span>';
183176 }
184177 else {
@@ -205,7 +198,7 @@
206199 }
207200 else {
208201 global $smgQPCoodFormat, $smgQPCoodDirectional;
209 - return MapsCoordinateParser::formatCoordinates( $this->coordinateSet, $smgQPCoodFormat, $smgQPCoodDirectional );
 202+ return MapsCoordinateParser::formatCoordinates( $this->m_dataitem->getCoordinateSet(), $smgQPCoodFormat, $smgQPCoodDirectional );
210203 }
211204 }
212205
@@ -237,7 +230,7 @@
238231 if ( $this->isValid() ) {
239232 global $smgQPCoodFormat, $smgQPCoodDirectional;
240233 $lit = new SMWExpLiteral(
241 - MapsCoordinateParser::formatCoordinates( $this->coordinateSet, $smgQPCoodFormat, $smgQPCoodDirectional ),
 234+ MapsCoordinateParser::formatCoordinates( $this->m_dataitem->getCoordinateSet(), $smgQPCoodFormat, $smgQPCoodDirectional ),
242235 $this,
243236 'http://www.w3.org/2001/XMLSchema#string'
244237 );
@@ -261,24 +254,16 @@
262255 * @return array
263256 */
264257 protected function getServiceLinkParams() {
 258+ $coordinateSet = $this->m_dataitem->getCoordinateSet();
265259 return array(
266 - MapsCoordinateParser::formatCoordinates( $this->coordinateSet, 'float', false ),
267 - MapsCoordinateParser::formatCoordinates( $this->coordinateSet, 'dms', true ),
268 - $this->coordinateSet['lat'],
269 - $this->coordinateSet['lon']
 260+ MapsCoordinateParser::formatCoordinates( $coordinateSet, 'float', false ),
 261+ MapsCoordinateParser::formatCoordinates( $coordinateSet, 'dms', true ),
 262+ $coordinateSet['lat'],
 263+ $coordinateSet['lon']
270264 );
271265 }
272266
273267 /**
274 - * @since 0.6
275 - *
276 - * @return array
277 - */
278 - public function getCoordinateSet() {
279 - return $this->coordinateSet;
280 - }
281 -
282 - /**
283268 * @see SMWDataValue::getValueIndex
284269 *
285270 * @since 0.6
Index: trunk/extensions/SemanticMaps/includes/SM_GeoCoordsHooks.php
@@ -74,6 +74,7 @@
7575 */
7676 public static function initGeoCoordsType() {
7777 SMWDataValueFactory::registerDatatype( '_geo', 'SMGeoCoordsValue', 'Geographic coordinate' );
 78+ SMWDataValueFactory::registerDataItem( '_geo', 'SMDIGeoCoord' );
7879 return true;
7980 }
8081
Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -88,6 +88,9 @@
8989
9090 $wgAutoloadClasses['SMGeoCoordsHooks'] = $incDir . 'SM_GeoCoordsHooks.php';
9191
 92+// Data items
 93+$wgAutoloadClasses['SMDIGeoCoord'] = $incDir . 'SM_DI_GeoCoord.php';
 94+
9295 // Data values
9396 $wgAutoloadClasses['SMGeoCoordsValue'] = $incDir . 'SM_GeoCoordsValue.php';
9497

Status & tagging log