Completed
Push — master ( 564666...efaf30 )
by Jeroen De
03:01
created

MapsHooks::onShowMissingArticle()   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 3
cp 0
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Maps\MediaWiki;
4
5
use AlItem;
6
use ALTree;
7
use Maps\MediaWiki\Content\GeoJsonContent;
8
use Maps\Presentation\GeoJsonPage;
9
use SkinTemplate;
10
11
/**
12
 * Static class for hooks handled by the Maps extension.
13
 *
14
 * @since 0.7
15
 *
16
 * @licence GNU GPL v2+
17
 * @author Jeroen De Dauw < [email protected] >
18
 */
19
final class MapsHooks {
20
21
	/**
22
	 * Adds a link to Admin Links page.
23
	 *
24
	 * @since 0.7
25
	 *
26
	 * @param ALTree $admin_links_tree
27
	 *
28
	 * @return boolean
29
	 */
30
	public static function addToAdminLinks( ALTree &$admin_links_tree ) {
31
		$displaying_data_section = $admin_links_tree->getSection(
32
			wfMessage( 'smw_adminlinks_displayingdata' )->text()
33
		);
34
35
		// Escape if SMW hasn't added links.
36
		if ( is_null( $displaying_data_section ) ) {
37
			return true;
38
		}
39
40
		$smw_docu_row = $displaying_data_section->getRow( 'smw' );
41
42
		$maps_docu_label = wfMessage( 'adminlinks_documentation', 'Maps' )->text();
43
		$smw_docu_row->addItem(
44
			AlItem::newFromExternalLink( 'https://www.semantic-mediawiki.org/wiki/Extension:Maps', $maps_docu_label )
45
		);
46
47
		return true;
48
	}
49
50
	/**
51
	 * Adds global JavaScript variables.
52
	 *
53
	 * @since 1.0
54
	 * @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
55
	 *
56
	 * @param array &$vars Variables to be added into the output
57
	 *
58
	 * @return boolean true in all cases
59
	 */
60
	public static function onMakeGlobalVariablesScript( array &$vars ) {
61
		$vars['egMapsScriptPath'] = $GLOBALS['wgScriptPath'] . '/extensions/Maps/'; // TODO: wgExtensionDirectory?
62
		$vars['egMapsDebugJS'] = $GLOBALS['egMapsDebugJS'];
63
		$vars['egMapsAvailableServices'] = $GLOBALS['egMapsAvailableServices'];
64
		$vars['egMapsLeafletLayersApiKeys'] = $GLOBALS['egMapsLeafletLayersApiKeys'];
65
66
		$vars += $GLOBALS['egMapsGlobalJSVars'];
67
68
		return true;
69
	}
70
71
	public static function onSkinTemplateNavigation( SkinTemplate $skinTemplate, array &$links ) {
72
		if ( $skinTemplate->getTitle() === null ) {
73
			return true;
74
		}
75
76
		if ( $skinTemplate->getTitle()->getNamespace() === NS_GEO_JSON ) {
77
			if ( array_key_exists( 'edit', $links['views'] ) ) {
78
				$links['views']['edit']['text'] = wfMessage(
79
					$skinTemplate->getTitle()->exists() ? 'maps-geo-json-edit-source': 'maps-geo-json-create-source'
80
				);
81
			}
82
		}
83
84
		return true;
85
	}
86
87
	public static function onBeforeDisplayNoArticleText( \Article $article ) {
88
		return $article->getTitle()->getNamespace() !== NS_GEO_JSON;
89
	}
90
91
	public static function onShowMissingArticle( \Article $article ) {
0 ignored issues
show
Unused Code introduced by
The parameter $article 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...
92
		// TODO: save does not work on new page yet: API response says "missing"
93
		// TODO: show below UI only after clicking "create new page with visual map editor"
94
95
//		$geoJsonPage = new GeoJsonPage(
96
//			GeoJsonContent::newEmptyContentString()
97
//		);
98
//
99
//		$geoJsonPage->addToOutputPage( $article->getContext()->getOutput() );
100
101
		return true;
102
	}
103
104
}
105