Index: trunk/extensions/SemanticMaps/includes/SM_GeoCoordsValue.php |
— | — | @@ -9,7 +9,8 @@ |
10 | 10 | * @ingroup SemanticMaps |
11 | 11 | * @ingroup SMWDataValues |
12 | 12 | * |
13 | | - * @author Jeroen De Dauw |
| 13 | + * @licence GNU GPL v3 |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 15 | * @author Markus Krötzsch |
15 | 16 | */ |
16 | 17 | class SMGeoCoordsValue extends SMWDataValue { |
— | — | @@ -18,113 +19,6 @@ |
19 | 20 | protected $wikiValue; |
20 | 21 | |
21 | 22 | /** |
22 | | - * Set the default format to 'map' when the requested properties are |
23 | | - * of type geographic coordinates. |
24 | | - * |
25 | | - * TODO: have a setting to turn this off and have it off by default for #show |
26 | | - * |
27 | | - * @since 0.6.5 |
28 | | - * |
29 | | - * @param $format Mixed: The format (string), or false when not set yet |
30 | | - * @param $printRequests Array: The print requests made |
31 | | - * @param $params Array: The parameters for the query printer |
32 | | - * |
33 | | - * @return true |
34 | | - */ |
35 | | - public static function addGeoCoordsDefaultFormat( &$format, array $printRequests, array $params ) { |
36 | | - // Only set the format when not set yet. This allows other extensions to override the Semantic Maps behaviour. |
37 | | - if ( $format === false ) { |
38 | | - // Only apply when there is more then one print request. |
39 | | - // This way requests comming from #show are ignored. |
40 | | - if ( count( $printRequests ) > 1 ) { |
41 | | - $allCoords = true; |
42 | | - $first = true; |
43 | | - |
44 | | - // Loop through the print requests to determine their types. |
45 | | - foreach( $printRequests as $printRequest ) { |
46 | | - // Skip the first request, as it's the object. |
47 | | - if ( $first ) { |
48 | | - $first = false; |
49 | | - continue; |
50 | | - } |
51 | | - |
52 | | - $typeId = $printRequest->getTypeID(); |
53 | | - |
54 | | - if ( $typeId != '_geo' ) { |
55 | | - $allCoords = false; |
56 | | - break; |
57 | | - } |
58 | | - } |
59 | | - |
60 | | - // If they are all coordinates, set the result format to 'map'. |
61 | | - if ( $allCoords ) { |
62 | | - $format = 'map'; |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - } |
67 | | - |
68 | | - return true; |
69 | | - } |
70 | | - |
71 | | - /** |
72 | | - * Adds support for the geographical coordinate data type to Semantic MediaWiki. |
73 | | - * |
74 | | - * @since 0.6 |
75 | | - * |
76 | | - * TODO: i18n keys still need to be moved |
77 | | - * |
78 | | - * @return true |
79 | | - */ |
80 | | - public static function initGeoCoordsType() { |
81 | | - SMWDataValueFactory::registerDatatype( '_geo', __CLASS__, 'Geographic coordinate' ); |
82 | | - return true; |
83 | | - } |
84 | | - |
85 | | - /** |
86 | | - * Defines the signature for geographical fields needed for the smw_coords table. |
87 | | - * |
88 | | - * @since 0.6 |
89 | | - * |
90 | | - * @param array $fieldTypes The field types defined by SMW, passed by reference. |
91 | | - * |
92 | | - * @return true |
93 | | - */ |
94 | | - public static function initGeoCoordsFieldTypes( array $fieldTypes ) { |
95 | | - global $smgUseSpatialExtensions; |
96 | | - |
97 | | - // Only add the table when the SQL store is not a postgres database, and it has not been added by SMW itself. |
98 | | - if ( $smgUseSpatialExtensions && !array_key_exists( 'c', $fieldTypes ) ) { |
99 | | - $fieldTypes['c'] = 'Point NOT NULL'; |
100 | | - } |
101 | | - |
102 | | - return true; |
103 | | - } |
104 | | - |
105 | | - /** |
106 | | - * Defines the layout for the smw_coords table which is used to store value of the GeoCoords type. |
107 | | - * |
108 | | - * @since 0.6 |
109 | | - * |
110 | | - * @param array $propertyTables The property tables defined by SMW, passed by reference. |
111 | | - */ |
112 | | - public static function initGeoCoordsTable( array $propertyTables ) { |
113 | | - global $smgUseSpatialExtensions; |
114 | | - |
115 | | - // No spatial extensions support for postgres yet, so just store as 2 float fields. |
116 | | - $signature = $smgUseSpatialExtensions ? array( 'point' => 'c' ) : array( 'lat' => 'f', 'lon' => 'f' ); |
117 | | - $indexes = $smgUseSpatialExtensions ? array( array( 'point', 'SPATIAL INDEX' ) ) : array_keys( $signature ); |
118 | | - |
119 | | - $propertyTables['smw_coords'] = new SMWSQLStore2Table( |
120 | | - 'sm_coords', |
121 | | - $signature, |
122 | | - $indexes // These are the fields that should be indexed. |
123 | | - ); |
124 | | - |
125 | | - return true; |
126 | | - } |
127 | | - |
128 | | - /** |
129 | 23 | * @see SMWDataValue::parseUserValue |
130 | 24 | * |
131 | 25 | * @since 0.6 |
— | — | @@ -388,4 +282,4 @@ |
389 | 283 | return 0; |
390 | 284 | } |
391 | 285 | |
392 | | -} |
\ No newline at end of file |
| 286 | +} |
Index: trunk/extensions/SemanticMaps/includes/SM_GeoCoordsHooks.php |
— | — | @@ -0,0 +1,123 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Implementation of datavalues that are geographic coordinates. |
| 6 | + * |
| 7 | + * @since 0.8 |
| 8 | + * |
| 9 | + * @file SM_GeoCoordsHooks.php |
| 10 | + * @ingroup SemanticMaps |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +final class SMGeoCoordsHooks { |
| 16 | + |
| 17 | + /** |
| 18 | + * Set the default format to 'map' when the requested properties are |
| 19 | + * of type geographic coordinates. |
| 20 | + * |
| 21 | + * TODO: have a setting to turn this off and have it off by default for #show |
| 22 | + * |
| 23 | + * @since 0.8 |
| 24 | + * |
| 25 | + * @param $format Mixed: The format (string), or false when not set yet |
| 26 | + * @param $printRequests Array: The print requests made |
| 27 | + * @param $params Array: The parameters for the query printer |
| 28 | + * |
| 29 | + * @return true |
| 30 | + */ |
| 31 | + public static function addGeoCoordsDefaultFormat( &$format, array $printRequests, array $params ) { |
| 32 | + // Only set the format when not set yet. This allows other extensions to override the Semantic Maps behaviour. |
| 33 | + if ( $format === false ) { |
| 34 | + // Only apply when there is more then one print request. |
| 35 | + // This way requests comming from #show are ignored. |
| 36 | + if ( count( $printRequests ) > 1 ) { |
| 37 | + $allCoords = true; |
| 38 | + $first = true; |
| 39 | + |
| 40 | + // Loop through the print requests to determine their types. |
| 41 | + foreach( $printRequests as $printRequest ) { |
| 42 | + // Skip the first request, as it's the object. |
| 43 | + if ( $first ) { |
| 44 | + $first = false; |
| 45 | + continue; |
| 46 | + } |
| 47 | + |
| 48 | + $typeId = $printRequest->getTypeID(); |
| 49 | + |
| 50 | + if ( $typeId != '_geo' ) { |
| 51 | + $allCoords = false; |
| 52 | + break; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + // If they are all coordinates, set the result format to 'map'. |
| 57 | + if ( $allCoords ) { |
| 58 | + $format = 'map'; |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + return true; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Adds support for the geographical coordinate data type to Semantic MediaWiki. |
| 69 | + * |
| 70 | + * @since 0.8 |
| 71 | + * |
| 72 | + * TODO: i18n keys still need to be moved |
| 73 | + * |
| 74 | + * @return true |
| 75 | + */ |
| 76 | + public static function initGeoCoordsType() { |
| 77 | + SMWDataValueFactory::registerDatatype( '_geo', __CLASS__, 'Geographic coordinate' ); |
| 78 | + return true; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Defines the signature for geographical fields needed for the smw_coords table. |
| 83 | + * |
| 84 | + * @since 0.8 |
| 85 | + * |
| 86 | + * @param array $fieldTypes The field types defined by SMW, passed by reference. |
| 87 | + * |
| 88 | + * @return true |
| 89 | + */ |
| 90 | + public static function initGeoCoordsFieldTypes( array $fieldTypes ) { |
| 91 | + global $smgUseSpatialExtensions; |
| 92 | + |
| 93 | + // Only add the table when the SQL store is not a postgres database, and it has not been added by SMW itself. |
| 94 | + if ( $smgUseSpatialExtensions && !array_key_exists( 'c', $fieldTypes ) ) { |
| 95 | + $fieldTypes['c'] = 'Point NOT NULL'; |
| 96 | + } |
| 97 | + |
| 98 | + return true; |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Defines the layout for the smw_coords table which is used to store value of the GeoCoords type. |
| 103 | + * |
| 104 | + * @since 0.8 |
| 105 | + * |
| 106 | + * @param array $propertyTables The property tables defined by SMW, passed by reference. |
| 107 | + */ |
| 108 | + public static function initGeoCoordsTable( array $propertyTables ) { |
| 109 | + global $smgUseSpatialExtensions; |
| 110 | + |
| 111 | + // No spatial extensions support for postgres yet, so just store as 2 float fields. |
| 112 | + $signature = $smgUseSpatialExtensions ? array( 'point' => 'c' ) : array( 'lat' => 'f', 'lon' => 'f' ); |
| 113 | + $indexes = $smgUseSpatialExtensions ? array( array( 'point', 'SPATIAL INDEX' ) ) : array_keys( $signature ); |
| 114 | + |
| 115 | + $propertyTables['smw_coords'] = new SMWSQLStore2Table( |
| 116 | + 'sm_coords', |
| 117 | + $signature, |
| 118 | + $indexes // These are the fields that should be indexed. |
| 119 | + ); |
| 120 | + |
| 121 | + return true; |
| 122 | + } |
| 123 | + |
| 124 | +} |
Property changes on: trunk/extensions/SemanticMaps/includes/SM_GeoCoordsHooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 125 | + native |
Index: trunk/extensions/SemanticMaps/SemanticMaps.php |
— | — | @@ -86,6 +86,8 @@ |
87 | 87 | |
88 | 88 | $incDir = dirname( __FILE__ ) . '/includes/'; |
89 | 89 | |
| 90 | +$wgAutoloadClasses['SMGeoCoordsHooks'] = $incDir . 'SM_GeoCoordsHooks.php'; |
| 91 | + |
90 | 92 | // Data values |
91 | 93 | $wgAutoloadClasses['SMGeoCoordsValue'] = $incDir . 'SM_GeoCoordsValue.php'; |
92 | 94 | |
— | — | @@ -96,16 +98,16 @@ |
97 | 99 | $wgAutoloadClasses['SemanticMapsHooks'] = dirname( __FILE__ ) . '/SemanticMaps.hooks.php'; |
98 | 100 | |
99 | 101 | // Hook for initializing the Geographical Coordinate type. |
100 | | -$wgHooks['smwInitDatatypes'][] = 'SMGeoCoordsValue::initGeoCoordsType'; |
| 102 | +$wgHooks['smwInitDatatypes'][] = 'SMGeoCoordsHooks::initGeoCoordsType'; |
101 | 103 | |
102 | 104 | // Hook for initializing the field types needed by Geographical Coordinates. |
103 | | -$wgHooks['SMWCustomSQLStoreFieldType'][] = 'SMGeoCoordsValue::initGeoCoordsFieldTypes'; |
| 105 | +$wgHooks['SMWCustomSQLStoreFieldType'][] = 'SMGeoCoordsHooks::initGeoCoordsFieldTypes'; |
104 | 106 | |
105 | 107 | // Hook for defining a table to store geographical coordinates in. |
106 | | -$wgHooks['SMWPropertyTables'][] = 'SMGeoCoordsValue::initGeoCoordsTable'; |
| 108 | +$wgHooks['SMWPropertyTables'][] = 'SMGeoCoordsHooks::initGeoCoordsTable'; |
107 | 109 | |
108 | 110 | // Hook for defining the default query printer for queries that ask for geographical coordinates. |
109 | | -$wgHooks['SMWResultFormat'][] = 'SMGeoCoordsValue::addGeoCoordsDefaultFormat'; |
| 111 | +$wgHooks['SMWResultFormat'][] = 'SMGeoCoordsHooks::addGeoCoordsDefaultFormat'; |
110 | 112 | |
111 | 113 | // Hook for adding a Semantic Maps links to the Admin Links extension. |
112 | 114 | $wgHooks['AdminLinks'][] = 'SemanticMapsHooks::addToAdminLinks'; |