These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
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
|
|||
35 | |||
36 | /** |
||
37 | * @since 1.3 |
||
38 | */ |
||
39 | public static function initExtension() { |
||
0 ignored issues
–
show
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);
}
}
![]() |
|||
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
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);
}
}
![]() |
|||
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 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.