Completed
Push — master ( 0d503f...c36494 )
by Jeroen De
04:05 queued 11s
created

Maps.hooks.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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