Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php |
— | — | @@ -30,18 +30,44 @@ |
31 | 31 | protected $wikiValue; |
32 | 32 | |
33 | 33 | /** |
34 | | - * Adds the map format as default for queries that have geocoords as only output. |
35 | | - * This feature was added in SMW 1.5.2, and requires the setting $smwgUseResultDefaults |
36 | | - * to be set to true. |
| 34 | + * Set the default format to 'map' when the requested properties are |
| 35 | + * of type geographic coordinates. |
37 | 36 | * |
38 | 37 | * @since 0.6.5 |
39 | 38 | * |
40 | | - * @param array $formats |
| 39 | + * @param $format Mixed: The format (string), or false when not set yet |
| 40 | + * @param $printRequests Array: The print requests made |
| 41 | + * @param $params Array: The parameters for the query printer |
41 | 42 | * |
42 | 43 | * @return true |
43 | 44 | */ |
44 | | - public static function addGeoCoordsDefaultFormat( array $formats ) { |
45 | | - $formats['_geo'] = 'map'; |
| 45 | + public static function addGeoCoordsDefaultFormat( &$format, array $printRequests, array $params ) { |
| 46 | + // Only set the format when not set yet. This allows other extensions to override the Semantic Maps behaviour. |
| 47 | + if ( $format === false ) { |
| 48 | + $allCoords = true; |
| 49 | + $hasNonPage = false; |
| 50 | + |
| 51 | + // Loop through the print requests to determine their types. |
| 52 | + foreach( $printRequests as $printRequest ) { |
| 53 | + $typeId = $printRequest->getTypeID(); |
| 54 | + |
| 55 | + // Ignore the page type. |
| 56 | + if ( $typeId != '_wpg' ) { |
| 57 | + $hasNonPage = true; |
| 58 | + |
| 59 | + if ( $typeId != '_geo' ) { |
| 60 | + $allCoords = false; |
| 61 | + break; |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + // If they are all coordinates, set the result format to 'map'. |
| 67 | + if ( $allCoords && $hasNonPage ) { |
| 68 | + $format = 'map'; |
| 69 | + } |
| 70 | + } |
| 71 | + |
46 | 72 | return true; |
47 | 73 | } |
48 | 74 | |
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php |
— | — | @@ -29,4 +29,4 @@ |
30 | 30 | $wgHooks['SMWPropertyTables'][] = 'SMGeoCoordsValue::initGeoCoordsTable'; |
31 | 31 | |
32 | 32 | // Hook for defining the default query printer for queries that ask for geographical coordinates. |
33 | | -$wgHooks['SMWResultDefaults'][] = 'SMGeoCoordsValue::addGeoCoordsDefaultFormat'; |
\ No newline at end of file |
| 33 | +$wgHooks['SMWResultFormat'][] = 'SMGeoCoordsValue::addGeoCoordsDefaultFormat'; |
\ No newline at end of file |