Completed
Push — move ( 875a6f )
by Jeroen De
04:17
created

MapsHooks   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 53
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addToAdminLinks() 0 19 2
A onMakeGlobalVariablesScript() 0 10 1
1
<?php
2
3
namespace Maps\MediaWiki;
4
5
use AlItem;
6
use ALTree;
7
8
/**
9
 * Static class for hooks handled by the Maps extension.
10
 *
11
 * @since 0.7
12
 *
13
 * @licence GNU GPL v2+
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
final class MapsHooks {
17
18
	/**
19
	 * Adds a link to Admin Links page.
20
	 *
21
	 * @since 0.7
22
	 *
23
	 * @param ALTree $admin_links_tree
24
	 *
25
	 * @return boolean
26
	 */
27
	public static function addToAdminLinks( ALTree &$admin_links_tree ) {
28
		$displaying_data_section = $admin_links_tree->getSection(
29
			wfMessage( 'smw_adminlinks_displayingdata' )->text()
30
		);
31
32
		// Escape if SMW hasn't added links.
33
		if ( is_null( $displaying_data_section ) ) {
34
			return true;
35
		}
36
37
		$smw_docu_row = $displaying_data_section->getRow( 'smw' );
38
39
		$maps_docu_label = wfMessage( 'adminlinks_documentation', 'Maps' )->text();
40
		$smw_docu_row->addItem(
41
			AlItem::newFromExternalLink( 'https://www.semantic-mediawiki.org/wiki/Extension:Maps', $maps_docu_label )
42
		);
43
44
		return true;
45
	}
46
47
	/**
48
	 * Adds global JavaScript variables.
49
	 *
50
	 * @since 1.0
51
	 * @see http://www.mediawiki.org/wiki/Manual:Hooks/MakeGlobalVariablesScript
52
	 *
53
	 * @param array &$vars Variables to be added into the output
54
	 *
55
	 * @return boolean true in all cases
56
	 */
57
	public static function onMakeGlobalVariablesScript( array &$vars ) {
0 ignored issues
show
Coding Style introduced by
onMakeGlobalVariablesScript uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
58
		$vars['egMapsScriptPath'] = $GLOBALS['wgScriptPath'] . '/extensions/Maps/'; // TODO: wgExtensionDirectory?
59
		$vars['egMapsDebugJS'] = $GLOBALS['egMapsDebugJS'];
60
		$vars['egMapsAvailableServices'] = $GLOBALS['egMapsAvailableServices'];
61
		$vars['egMapsLeafletLayersApiKeys'] = $GLOBALS['egMapsLeafletLayersApiKeys'];
62
63
		$vars += $GLOBALS['egMapsGlobalJSVars'];
64
65
		return true;
66
	}
67
68
}
69