r104580 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104579‎ | r104580 | r104581 >
Date:19:03, 29 November 2011
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
some initial work on bug 32698
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_GeoCoord.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/RELEASE-NOTES
@@ -14,14 +14,17 @@
1515 * Added alpha version of native SMW Ask API with moudles ask and askargs.
1616 * Added setting to choose which optional special properties are enabled ($smwgPageSpecialProperties).
1717 * Added creation date special property (disabled by default) (bug 32165).
 18+* Added support for altitudes in geographic coordinates (bug 32698).
 19+* Dropped compatibility with MediaWiki 1.15.x (and earlier).
 20+* Dropped compatibility with old-style (SMW < 1.6) query printers.
1821 * Fixed separator and filename parameters for the DSV format.
1922 * Fixed display of properties of type URL (bug 30912).
2023 * Fixed hide query functionality on Special:Ask (bug 30768).
2124 * Fixed display of internal SMW helper constants in certain queries (bug 30969).
2225 * Fixed some issues with the category result format (including bug 30761).
2326 * Fixed email validation issue (bug 32295).
24 -* Dropped compatibility with MediaWiki 1.15.x (and earlier).
25 -* Dropped compatibility with old-style (SMW < 1.6) query printers.
 27+* Fixed incorrect handling of sort and order parameters on Special:Ask (bug 32706).
 28+* Fixed several more issues not listed here.
2629
2730 == SMW 1.6.1 ==
2831
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -2499,8 +2499,8 @@
25002500
25012501 self::$prop_tables['smw_coords'] = new SMWSQLStore2Table(
25022502 'sm_coords',
2503 - array( 'lat' => 'f', 'lon' => 'f' ),
2504 - array( 'lat', 'lon' )
 2503+ array( 'lat' => 'f', 'lon' => 'f', 'alt' => 'f' ),
 2504+ array( 'lat', 'lon', 'alt' )
25052505 );
25062506
25072507 wfRunHooks( 'SMWPropertyTables', array( &self::$prop_tables ) );
Index: trunk/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_GeoCoord.php
@@ -13,16 +13,67 @@
1414 */
1515 class SMWDIGeoCoord extends SMWDataItem {
1616
17 - protected $coordinateSet;
 17+ /**
 18+ * The locations latitude.
 19+ *
 20+ * @since 1.6
 21+ * @var float
 22+ */
 23+ protected $latitude;
 24+
 25+ /**
 26+ * The locations longitude.
 27+ *
 28+ * @since 1.6
 29+ * @var float
 30+ */
 31+ protected $longitude;
 32+
 33+ /**
 34+ * The locations altitude.
 35+ *
 36+ * @since 1.7
 37+ * @var float|null
 38+ */
 39+ protected $altitude = null;
1840
1941 /**
2042 * Constructor.
 43+ * Takes a latitude and longitude, and optionally an altitude. These can be provided in 2 forms:
 44+ * * An associative array with lat, lon and alt keys
 45+ * * Lat, lon and alt arguments
2146 *
22 - * @param $coords array Array with lat and long keys pointing to float values.
23 - * @param $typeid string
 47+ * The second way to provide the arguments, as well as the altitude argument, where introduced in SMW 1.7.
2448 */
25 - public function __construct( array $coords ) {
26 - $this->coordinateSet = $coords;
 49+ public function __construct() {
 50+ $args = func_get_args();
 51+
 52+ $count = count( $args );
 53+
 54+ if ( $count === 1 && is_array( $args[0] ) ) {
 55+ if ( array_key_exists( 'lat', $args[0] ) && array_key_exists( 'lon', $args[0] ) ) {
 56+ $this->latitude = (float)$args[0]['lat'];
 57+ $this->longitude = (float)$args[0]['lon'];
 58+
 59+ if ( array_key_exists( 'alt', $args[0] ) ) {
 60+ $this->altitude = (float)$args[0]['alt'];
 61+ }
 62+ }
 63+ else {
 64+ throw new SMWDataItemException( 'Invalid coordinate data passed to the SMWDIGeoCoord constructor' );
 65+ }
 66+ }
 67+ elseif ( $count === 2 || $count === 3 ) {
 68+ $this->latitude = (float)$args[0];
 69+ $this->longitude = (float)$args[1];
 70+
 71+ if ( $count === 3 ) {
 72+ $this->altitude = (float)$args[2];
 73+ }
 74+ }
 75+ else {
 76+ throw new SMWDataItemException( 'Invalid coordinate data passed to the SMWDIGeoCoord constructor' );
 77+ }
2778 }
2879
2980 /**
@@ -34,7 +85,7 @@
3586 }
3687
3788 /**
38 - * Returns the coordinate set as an array with lat and long keys
 89+ * Returns the coordinate set as an array with lat and long (and alt) keys
3990 * pointing to float values.
4091 *
4192 * @since 1.6
@@ -42,7 +93,13 @@
4394 * @return array
4495 */
4596 public function getCoordinateSet() {
46 - return $this->coordinateSet;
 97+ $coords = array( 'lat' => $this->latitude, 'lon' => $this->longitude );
 98+
 99+ if ( !is_null( $this->altitude ) ) {
 100+ $coords['alt'] = $this->altitude;
 101+ }
 102+
 103+ return $coords;
47104 }
48105
49106 /**
@@ -50,7 +107,8 @@
51108 * @see SMWDataItem::getSortKey()
52109 */
53110 public function getSortKey() {
54 - return $this->coordinateSet['lat']; // TODO
 111+ // Maybe also add longitude here? Or is there a more meaningfull value we can return?
 112+ return $this->latitude;
55113 }
56114
57115 /**
@@ -58,7 +116,7 @@
59117 * @see SMWDataItem::getSerialization()
60118 */
61119 public function getSerialization() {
62 - return $this->coordinateSet['lat'] . ',' . $this->coordinateSet['lon'];
 120+ return implode( ',', $this->getCoordinateSet() );
63121 }
64122
65123 /**
@@ -75,12 +133,19 @@
76134 */
77135 public static function doUnserialize( $serialization ) {
78136 $parts = explode( ',', $serialization );
79 -
80 - if ( count( $parts ) != 2 ) {
 137+ $count = count( $parts );
 138+
 139+ if ( $count !== 2 && $count !== 3 ) {
81140 throw new SMWDataItemException( 'Unserialization of coordinates failed' );
82141 }
 142+
 143+ $coords = array( 'lat' => (float)$parts[0], 'lon' => (float)$parts[1] );
 144+
 145+ if ( $count === 3 ) {
 146+ $coords['alt'] = (float)$parts[2];
 147+ }
83148
84 - return new self( array( 'lat' => (float)$parts[0], 'lon' => (float)$parts[1], ) );
 149+ return new self( $coords );
85150 }
86151
87152 /**
@@ -91,7 +156,7 @@
92157 * @return float
93158 */
94159 public function getLatitude() {
95 - return $this->coordinateSet['lat'];
 160+ return $this->latitude;
96161 }
97162
98163 /**
@@ -102,7 +167,18 @@
103168 * @return float
104169 */
105170 public function getLongitude() {
106 - return $this->coordinateSet['lon'];
 171+ return $this->longitude;
107172 }
 173+
 174+ /**
 175+ * Returns the altitude if set, null otherwise.
 176+ *
 177+ * @since 1.7
 178+ *
 179+ * @return float|null
 180+ */
 181+ public function getAltitude() {
 182+ return $this->altitude;
 183+ }
108184
109185 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r104599Follow up to r104580;jeroendedauw21:47, 29 November 2011

Comments

#Comment by Raymond (talk | contribs)   19:18, 29 November 2011

https://translatewiki.net/wiki/User:Boniface

Invalid coordinate data passed to the SMWDIGeoCoord constructor

Backtrace:

#0 /www/w/extensions/SemanticMaps/includes/SM_GeoCoordsValue.php(105): SMWDIGeoCoord->__construct(Array)
#1 /www/w/extensions/SemanticMaps/includes/SM_GeoCoordsValue.php(51): SMGeoCoordsValue->parseUserValueOrQuery('{{{1}}}')
#2 /www/w/extensions/SemanticMediaWiki/includes/datavalues/SMW_DataValue.php(169): SMGeoCoordsValue->parseUserValue('{{{1}}}')
#3 /www/w/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php(113): SMWDataValue->setUserValue('{{{1}}}', false)
#4 /www/w/extensions/SemanticMediaWiki/includes/SMW_DataValueFactory.php(177): SMWDataValueFactory::newTypeIdValue('_geo', '{{{1}}}', false, Object(SMWDIProperty), Object(SMWDIWikiPage))
#5 /www/w/extensions/SemanticMediaWiki/includes/SMW_ParseData.php(113): SMWDataValueFactory::newPropertyObjectValue(Object(SMWDIProperty), '{{{1}}}', false, Object(SMWDIWikiPage))
#6 /www/w/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php(165): SMWParseData::addProperty('Coordinates', '{{{1}}}', false, Object(Parser), true)
#7 /www/w/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php(112): SMWParserExtensions::parsePropertiesCallback(Array)
#8 [internal function]: SMWParserExtensions::simpleParsePropertiesCallback(Array)
#9 /www/w/extensions/SemanticMediaWiki/includes/SMW_ParserExtensions.php(71): preg_replace_callback('/\[\[ ...', Array, '<span style="di...')
#10 [internal function]: SMWParserExtensions::onInternalParseBeforeLinks(Object(Parser), '<span style="di...', Object(StripState))
#11 /www/w/includes/Hooks.php(216): call_user_func_array('SMWParserExtens...', Array)
#12 /www/w/includes/GlobalFunctions.php(3730): Hooks::run('InternalParseBe...', Array)
#13 /www/w/includes/parser/Parser.php(1073): wfRunHooks('InternalParseBe...', Array)
#14 /www/w/includes/parser/Parser.php(345): Parser->internalParse('{{Location}}?{{...')
#15 /www/w/includes/WikiPage.php(2827): Parser->parse('{{Location}}?{{...', Object(Title), Object(ParserOptions), true, true, 3133281)
#16 /www/w/includes/PoolCounter.php(187): PoolWorkArticleView->doWork()
#17 /www/w/includes/Article.php(556): PoolCounterWork->execute()
#18 /www/w/includes/Wiki.php(495): Article->view()
#19 /www/w/includes/Wiki.php(266): MediaWiki->performAction(Object(Article))
#20 /www/w/includes/Wiki.php(619): MediaWiki->performRequest()
#21 /www/w/includes/Wiki.php(538): MediaWiki->main()
#22 /www/w/index.php(58): MediaWiki->run()
#23 {main}
#Comment by Jeroen De Dauw (talk | contribs)   20:32, 29 November 2011

wtf... I don't see anything wrong w/ the code.

Very useful stack trace, fails to list on which line the exception is thrown >_>

Can you run update.php and see if it goes away? There was some schema change, so not running it might be the reason for this error.

#Comment by 😂 (talk | contribs)   20:34, 29 November 2011
Very useful stack trace, fails to list on which line the exception is thrown >_>
  1. 0 /www/w/extensions/SemanticMaps/includes/SM_GeoCoordsValue.php(105): SMWDIGeoCoord->__construct(Array)
#Comment by Jeroen De Dauw (talk | contribs)   21:42, 29 November 2011

Which is not the line where the exception is thrown.

#Comment by Raymond (talk | contribs)   20:35, 29 November 2011

Sorry about missing the line. From #mediawiki-i18n channel: mediawiki-bw_: /wiki/User:Boniface Exception from line 63 of /www/w/extensions/SemanticMediaWiki/includes/dataitems/SMW_DI_GeoCoord.php: Invalid coordinate data passed to the SMWDIGeoCoord constructor

Schema change? In which revision?

#Comment by Jeroen De Dauw (talk | contribs)   21:48, 29 November 2011

The schema change was in this revision, see the changes to SMW_SQLStore2. I think I fixed the issue in the follow up rev though.

#Comment by Raymond (talk | contribs)   22:20, 29 November 2011

Thanks, works again.

BTW: It would be helpful to announce a schema change in the commit message. Thanks.

#Comment by Jeroen De Dauw (talk | contribs)   23:20, 29 November 2011

Sure, I ought to do that. I just realized that you need to run SMW update script rather then update.php though.

Status & tagging log