Completed
Push — master ( 23e7c9...9653c4 )
by Jeroen De
03:47 queued 10s
created

MapsHooks::onResourceLoaderTestModules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
4
namespace Maps\MediaWiki;
5
6
use AlItem;
7
use ALTree;
8
use Maps\Presentation\GeoJsonNewPageUi;
9
use Maps\Presentation\OutputFacade;
10
use SkinTemplate;
11
12
/**
13
 * Static class for hooks handled by the Maps extension.
14
 *
15
 * @since 0.7
16
 *
17
 * @licence GNU GPL v2+
18
 * @author Jeroen De Dauw < [email protected] >
19
 */
20
final class MapsHooks {
21
22
	/**
23
	 * Adds a link to Admin Links page.
24
	 *
25
	 * @since 0.7
26
	 *
27
	 * @param ALTree $admin_links_tree
28
	 *
29
	 * @return boolean
30
	 */
31
	public static function addToAdminLinks( ALTree &$admin_links_tree ) {
32
		$displaying_data_section = $admin_links_tree->getSection(
33
			wfMessage( 'smw_adminlinks_displayingdata' )->text()
34
		);
35
36
		// Escape if SMW hasn't added links.
37
		if ( is_null( $displaying_data_section ) ) {
38
			return true;
39
		}
40
41
		$smw_docu_row = $displaying_data_section->getRow( 'smw' );
42
43
		$maps_docu_label = wfMessage( 'adminlinks_documentation', 'Maps' )->text();
44
		$smw_docu_row->addItem(
45
			AlItem::newFromExternalLink( 'https://www.semantic-mediawiki.org/wiki/Extension:Maps', $maps_docu_label )
46
		);
47
48
		return true;
49
	}
50
51
	/**
52
	 * Adds global JavaScript variables.
53
	 *
54
	 * @since 1.0
55
	 * @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
56
	 *
57
	 * @param array &$vars Variables to be added into the output
58
	 *
59
	 * @return boolean true in all cases
60
	 */
61
	public static function onMakeGlobalVariablesScript( array &$vars ) {
62
		$vars['egMapsScriptPath'] = $GLOBALS['wgScriptPath'] . '/extensions/Maps/'; // TODO: wgExtensionDirectory?
63
		$vars['egMapsDebugJS'] = $GLOBALS['egMapsDebugJS'];
64
		$vars['egMapsAvailableServices'] = $GLOBALS['egMapsAvailableServices'];
65
		$vars['egMapsLeafletLayersApiKeys'] = $GLOBALS['egMapsLeafletLayersApiKeys'];
66
		$vars['egMapsLeafletLayersDark'] = $GLOBALS['egMapsLeafletLayersDark'];
67
68
		$vars += $GLOBALS['egMapsGlobalJSVars'];
69
70
		return true;
71
	}
72
73
	public static function onSkinTemplateNavigation( SkinTemplate $skinTemplate, array &$links ) {
74
		if ( $skinTemplate->getTitle() === null ) {
75
			return true;
76
		}
77
78
		if ( $skinTemplate->getTitle()->getNamespace() === NS_GEO_JSON ) {
79
			if ( array_key_exists( 'edit', $links['views'] ) ) {
80
				$links['views']['edit']['text'] = wfMessage(
81
					$skinTemplate->getTitle()->exists() ? 'maps-geo-json-edit-source': 'maps-geo-json-create-source'
82
				);
83
			}
84
		}
85
86
		return true;
87
	}
88
89
	public static function onBeforeDisplayNoArticleText( \Article $article ) {
90
		return !self::shouldShowGeoJsonCreatePageUi( $article );
91
	}
92
93
	public static function onShowMissingArticle( \Article $article ) {
94
		if ( self::shouldShowGeoJsonCreatePageUi( $article ) ) {
95
			$ui = new GeoJsonNewPageUi( OutputFacade::newFromOutputPage( $article->getContext()->getOutput() ) );
96
			$ui->addToOutput();
97
		}
98
99
		return true;
100
	}
101
102
	private static function shouldShowGeoJsonCreatePageUi( \Article $article ): bool {
103
		return $article->getTitle()->getNamespace() === NS_GEO_JSON
104
			&& $article->getContext()->getUser()->isAllowed( 'createpage' );
105
	}
106
107
	public static function onRegisterTags( array &$tags ) {
108
		$tags[] = 'maps-visual-edit';
109
		return true;
110
	}
111
112
	public static function onChangeTagsAllowedAdd( array &$allowedTags, array $tags, \User $user = null ) {
0 ignored issues
show
Unused Code introduced by
The parameter $tags 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...
Unused Code introduced by
The parameter $user 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...
113
		$allowedTags[] = 'maps-visual-edit';
114
	}
115
116
	public static function onResourceLoaderTestModules( array &$modules, $resourceLoader ) {
0 ignored issues
show
Unused Code introduced by
The parameter $resourceLoader 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...
117
		$modules['qunit']['ext.maps.test'] = [
118
			'scripts' => [
119
				'tests/js/leaflet/GeoJsonTest.js',
120
			],
121
			'dependencies' => [
122
				'ext.maps.leaflet.geojson',
123
			],
124
			'localBasePath' => __DIR__ . '/../../',
125
			'remoteExtPath' => 'Maps'
126
		];
127
	}
128
129
}
130