Completed
Push — geojsonsmw ( 4cff82 )
by Jeroen De
03:44
created

MapsHooks::onBeforeDisplayNoArticleText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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