Project:
Semantic Maps
Code Location:
https://gerrit.wikimedia.org/r/p/mediawiki/extensions/SemanticMaps.gitmaster
/
SemanticMaps.hooks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php /** * Static class for hooks handled by the Semantic Maps extension. * * @since 0.7 * * @ingroup SemanticMaps * * @licence GNU GPL v2+ * @author Jeroen De Dauw < jeroendedauw@gmail.com > */ final class SemanticMapsHooks { /** * Adds a link to Admin Links page. * * @since 0.7 * * @param ALTree $admin_links_tree * * @return boolean */ public static function addToAdminLinks( ALTree &$admin_links_tree ) { $displaying_data_section = $admin_links_tree->getSection( wfMessage( 'smw_adminlinks_displayingdata' )->text() ); // Escape if SMW hasn't added links. if ( is_null( $displaying_data_section ) ) { return true; } $smw_docu_row = $displaying_data_section->getRow( 'smw' ); $sm_docu_label = wfMessage( 'adminlinks_documentation', 'Semantic Maps' )->text(); $smw_docu_row->addItem( AlItem::newFromExternalLink( 'http://mapping.referata.com/wiki/Semantic_Maps', $sm_docu_label ) ); return true; } /** * Hook to add PHPUnit test cases. * @see https://www.mediawiki.org/wiki/Manual:Hooks/UnitTestsList * * @since 2.0 * * @param array $files * * @return boolean */ public static function registerUnitTests( array &$files ) { $testFiles = array( 'printers/KMLPrinter', 'printers/MapPrinter', ); foreach ( $testFiles as $file ) { $files[] = __DIR__ . '/tests/phpunit/' . $file . 'Test.php'; } return true; } /** * Adds support for the geographical coordinates and shapes data type to Semantic MediaWiki. * * @since 2.0 * * @return boolean */ public static function initGeoDataTypes() { SMWDataValueFactory::registerDatatype( '_geo', 'SMGeoCoordsValue', SMWDataItem::TYPE_GEO ); SMWDataValueFactory::registerDatatype( '_gpo', 'SMGeoPolygonsValue', SMWDataItem::TYPE_BLOB ); return true; } /** * Set the default format to 'map' when the requested properties are * of type geographic coordinates. * * TODO: have a setting to turn this off and have it off by default for #show * * @since 1.0 * * @param $format Mixed: The format (string), or false when not set yet * @param $printRequests Array: The print requests made * @param $params Array: The parameters for the query printer * * @return boolean */ public static function addGeoCoordsDefaultFormat( &$format, array $printRequests, array $params ) { // Only set the format when not set yet. This allows other extensions to override the Semantic Maps behavior. if ( $format === false ) { // Only apply when there is more then one print request. // This way requests comming from #show are ignored. if ( count( $printRequests ) > 1 ) { $allValid = true; $hasCoords = false; // Loop through the print requests to determine their types. foreach( $printRequests as /* SMWPrintRequest */ $printRequest ) { // Skip the first request, as it's the object. if ( $printRequest->getMode() == SMWPrintRequest::PRINT_THIS ) { continue; } $typeId = $printRequest->getTypeID(); if ( $typeId == '_geo' ) { $hasCoords = true; } else { $allValid = false; break; } } // If they are all coordinates, set the result format to 'map'. if ( $allValid && $hasCoords ) { $format = 'map'; } } } return true; } }
