r69678 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69677‎ | r69678 | r69679 >
Date:13:24, 21 July 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r69662 - re-implemented default format support for coordinate requests
Modified paths:
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoordsValue.php
@@ -30,18 +30,44 @@
3131 protected $wikiValue;
3232
3333 /**
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.
3736 *
3837 * @since 0.6.5
3938 *
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
4142 *
4243 * @return true
4344 */
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+
4672 return true;
4773 }
4874
Index: trunk/extensions/SemanticMaps/GeoCoords/SM_GeoCoords.php
@@ -29,4 +29,4 @@
3030 $wgHooks['SMWPropertyTables'][] = 'SMGeoCoordsValue::initGeoCoordsTable';
3131
3232 // 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

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r69662Removed default format support I added earlier on. A single hook that allows ...jeroendedauw10:00, 21 July 2010

Status & tagging log