Completed
Push — master ( 4b277a...9a74be )
by mw
03:10 queued 38s
created

SemanticBreadcrumbLinks::getVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 34 and the first side effect is on line 13.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use SBL\HookRegistry;
4
use SBL\Options;
5
use SMW\ApplicationFactory;
6
7
/**
8
 * @see https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/
9
 *
10
 * @defgroup SBL Semantic Breadcrumb Links
11
 */
12
if ( !defined( 'MEDIAWIKI' ) ) {
13
	die( 'This file is part of the SemanticBreadcrumbLinks extension, it is not a valid entry point.' );
14
}
15
16
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) {
17
	die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/">SemanticBreadcrumbLinks</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' );
18
}
19
20
if ( defined( 'SBL_VERSION' ) ) {
21
	// Do not initialize more than once.
22
	return 1;
23
}
24
25
SemanticBreadcrumbLinks::initExtension();
26
27
$GLOBALS['wgExtensionFunctions'][] = function() {
28
	SemanticBreadcrumbLinks::onExtensionFunction();
29
};
30
31
/**
32
 * @codeCoverageIgnore
33
 */
34
class SemanticBreadcrumbLinks {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
35
36
	/**
37
	 * @since 1.3
38
	 */
39
	public static function initExtension() {
0 ignored issues
show
Coding Style introduced by
initExtension 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...
40
41
		// Load DefaultSettings
42
		require_once __DIR__ . '/DefaultSettings.php';
43
44
		define( 'SBL_VERSION', '1.3.0-alpha' );
45
46
		define( 'SBL_PROP_PARENTPAGE', 'Has parent page' );
47
48
		// Register the extension
49
		$GLOBALS['wgExtensionCredits']['semantic'][ ] = array(
50
			'path'           => __DIR__,
51
			'name'           => 'Semantic Breadcrumb Links',
52
			'author'         => array( 'James Hong Kong' ),
53
			'url'            => 'https://github.com/SemanticMediaWiki/SemanticBreadcrumbLinks/',
54
			'descriptionmsg' => 'sbl-desc',
55
			'version'        => SBL_VERSION,
56
			'license-name'   => 'GPL-2.0+',
57
		);
58
59
		// Register message files
60
		$GLOBALS['wgMessagesDirs']['SemanticBreadcrumbLinks'] = __DIR__ . '/i18n';
61
62
		// Register resource files
63
		$GLOBALS['wgResourceModules']['ext.semanticbreadcrumblinks'] = array(
64
			'styles'  => 'res/sbl.styles.css',
65
			'scripts' => 'res/sbl.tooltip.js',
66
			'localBasePath' => __DIR__ ,
67
			'remoteExtPath' => 'SemanticBreadcrumbLinks',
68
			'position' => 'top',
69
			'group'    => 'ext.smw',
70
			'dependencies'  => array(
71
				'onoi.qtip'
72
			),
73
			'targets' => array(
74
				'mobile',
75
				'desktop'
76
			)
77
		);
78
	}
79
80
	/**
81
	 * @since 1.3
82
	 */
83
	public static function onExtensionFunction() {
0 ignored issues
show
Coding Style introduced by
onExtensionFunction 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...
84
85
		// Default values are defined at this point to ensure
86
		// NS contants are specified prior
87
		$defaultPropertySearchPatternByNamespace = array(
88
			NS_CATEGORY => array(
89
				'_SUBC',
90
				'_SUBC',
91
				'_SUBC'
92
			),
93
			SMW_NS_PROPERTY => array(
94
				'_SUBP',
95
				'_SUBP',
96
				'_SUBP'
97
			),
98
			NS_MAIN => array(
99
				SBL_PROP_PARENTPAGE,
100
				SBL_PROP_PARENTPAGE,
101
				SBL_PROP_PARENTPAGE
102
			),
103
			NS_HELP => array(
104
				SBL_PROP_PARENTPAGE,
105
				SBL_PROP_PARENTPAGE,
106
				SBL_PROP_PARENTPAGE
107
			)
108
		);
109
110
		$configuration = array(
111
			'hideSubpageParent' => $GLOBALS['egSBLPageTitleToHideSubpageParent'],
112
			'breadcrumbTrailStyleClass' => $GLOBALS['egSBLBreadcrumbTrailStyleClass'],
113
			'breadcrumbDividerStyleClass' => $GLOBALS['egSBLBreadcrumbDividerStyleClass'],
114
			'tryToFindClosestDescendant' => $GLOBALS['egSBLTryToFindClosestDescendant'],
115
			'useSubpageFinderFallback' => $GLOBALS['egSBLUseSubpageFinderFallback'],
116
			'enabledSubpageParentAnnotation' => $GLOBALS['egSBLEnabledSubpageParentAnnotation'],
117
			'wgNamespacesWithSubpages' => $GLOBALS['wgNamespacesWithSubpages'],
118
			'propertySearchPatternByNamespace' => $GLOBALS['egSBLPropertySearchPatternByNamespace'] + $defaultPropertySearchPatternByNamespace
119
		);
120
121
		$hookRegistry = new HookRegistry(
122
			ApplicationFactory::getInstance()->getStore(),
123
			new Options( $configuration )
124
		);
125
126
		$hookRegistry->register();
127
	}
128
129
	/**
130
	 * @since 1.3
131
	 *
132
	 * @return string|null
133
	 */
134
	public static function getVersion() {
135
		return SBL_VERSION;
136
	}
137
138
}
139