Completed
Push — i18ndeshim ( 6c7550 )
by
unknown
10:49 queued 54s
created

SemanticMaps.hooks.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use SMW\DataTypeRegistry;
4
5
/**
6
 * Static class for hooks handled by the Semantic Maps extension.
7
 *
8
 * @since 0.7
9
 *
10
 * @ingroup SemanticMaps
11
 *
12
 * @licence GNU GPL v2+
13
 * @author Jeroen De Dauw < [email protected] >
14
 */
15
final class SemanticMapsHooks {
16
17
	/**
18
	 * Adds a link to Admin Links page.
19
	 *
20
	 * @since 0.7
21
	 *
22
	 * @param ALTree $admin_links_tree
23
	 *
24
	 * @return boolean
25
	 */
26
	public static function addToAdminLinks( ALTree &$admin_links_tree ) {
27
	    $displaying_data_section = $admin_links_tree->getSection( wfMessage( 'smw_adminlinks_displayingdata' )->text() );
28
29
	    // Escape if SMW hasn't added links.
30
	    if ( is_null( $displaying_data_section ) ) {
31
			return true;
32
		}
33
34
	    $smw_docu_row = $displaying_data_section->getRow( 'smw' );
35
36
	    $sm_docu_label = wfMessage( 'adminlinks_documentation', 'Semantic Maps' )->text();
37
	    $smw_docu_row->addItem( AlItem::newFromExternalLink( 'http://mapping.referata.com/wiki/Semantic_Maps', $sm_docu_label ) );
38
39
	    return true;
40
	}
41
42
	/**
43
	 * Adds support for the geographical coordinates and shapes data type to Semantic MediaWiki.
44
	 *
45
	 * @since 2.0
46
	 *
47
	 * @return boolean
48
	 */
49
	public static function initGeoDataTypes() {
50
		DataTypeRegistry::getInstance()->registerDatatype(
51
			'_geo',
52
			'SMGeoCoordsValue',
53
			SMWDataItem::TYPE_GEO
54
		);
55
56
		DataTypeRegistry::getInstance()->registerDatatype(
57
			'_gpo',
58
			'SMGeoPolygonsValue',
59
			SMWDataItem::TYPE_BLOB
60
		);
61
62
		return true;
63
	}
64
65
	/**
66
	 * Set the default format to 'map' when the requested properties are
67
	 * of type geographic coordinates.
68
	 * 
69
	 * TODO: have a setting to turn this off and have it off by default for #show
70
	 * 
71
	 * @since 1.0
72
	 * 
73
	 * @param $format Mixed: The format (string), or false when not set yet 
74
	 * @param $printRequests Array: The print requests made
75
	 * @param $params Array: The parameters for the query printer
76
	 * 
77
	 * @return boolean
78
	 */
79
	public static function addGeoCoordsDefaultFormat( &$format, array $printRequests, array $params ) {
0 ignored issues
show
The parameter $params is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
		// Only set the format when not set yet. This allows other extensions to override the Semantic Maps behavior.
81
		if ( $format === false ) {
82
			// Only apply when there is more then one print request.
83
			// This way requests comming from #show are ignored. 
84
			if ( count( $printRequests ) > 1 ) {
85
				$allValid = true;
86
				$hasCoords = false;
87
				
88
				// Loop through the print requests to determine their types.
89
				foreach( $printRequests as /* SMWPrintRequest */ $printRequest ) {
90
					// Skip the first request, as it's the object.
91
					if ( $printRequest->getMode() == SMWPrintRequest::PRINT_THIS ) {
92
						continue;
93
					}
94
					
95
					$typeId = $printRequest->getTypeID();
96
					
97
					if ( $typeId == '_geo' ) {
98
						$hasCoords = true;
99
					}
100
					else {
101
						$allValid = false;
102
						break;
103
					}
104
				}
105
	
106
				// If they are all coordinates, set the result format to 'map'.
107
				if ( $allValid && $hasCoords ) {
108
					$format = 'map';
109
				}				
110
			}
111
112
		}
113
		
114
		return true;
115
	}
116
117
}
118