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 WNBY\HookRegistry; |
||
4 | |||
5 | /** |
||
6 | * @see https://github.com/SemanticMediaWiki/WhatsNearby/ |
||
7 | * @link https://www.semantic-mediawiki.org/wiki/Extension:WhatsNearby |
||
8 | * |
||
9 | * @defgroup wnby WhatsNearby |
||
10 | */ |
||
11 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
12 | die( 'This file is part of the WhatsNearby extension, it is not a valid entry point.' ); |
||
13 | } |
||
14 | |||
15 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) { |
||
16 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/WhatsNearby/">WhatsNearby</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' ); |
||
17 | } |
||
18 | |||
19 | // Do not initialize more than once. |
||
20 | if ( defined( 'WNBY_VERSION' ) ) { |
||
21 | return 1; |
||
22 | } |
||
23 | |||
24 | WhatsNearby::initExtension(); |
||
25 | |||
26 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
27 | WhatsNearby::onExtensionFunction(); |
||
28 | }; |
||
29 | |||
30 | /** |
||
31 | * @codeCoverageIgnore |
||
32 | */ |
||
33 | class WhatsNearby { |
||
0 ignored issues
–
show
|
|||
34 | |||
35 | /** |
||
36 | * @since 1.0 |
||
37 | */ |
||
38 | 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);
}
}
![]() |
|||
39 | |||
40 | // Load DefaultSettings |
||
41 | require_once __DIR__ . '/DefaultSettings.php'; |
||
42 | |||
43 | define( 'WNBY_VERSION', '1.0.0-alpha' ); |
||
44 | |||
45 | $GLOBALS['wgExtensionCredits']['others'][] = array( |
||
46 | 'path' => __DIR__, |
||
47 | 'name' => 'Whats Nearby', |
||
48 | 'author' => array( 'mwjames' ), |
||
49 | 'url' => 'https://www.semantic-mediawiki.org/wiki/Extension:WhatsNearby', |
||
50 | 'descriptionmsg' => 'wnby-desc', |
||
51 | 'version' => WNBY_VERSION, |
||
52 | 'license-name' => 'GPL-2.0+', |
||
53 | ); |
||
54 | |||
55 | // Register message files |
||
56 | $GLOBALS['wgMessagesDirs']['WhatsNearby'] = __DIR__ . '/i18n'; |
||
57 | $GLOBALS['wgExtensionMessagesFiles']['WhatsNearbyMagic'] = __DIR__ . '/i18n/WhatsNearby.magic.php'; |
||
58 | |||
59 | $GLOBALS['wgResourceModules']['ext.whats.nearby.geoip'] = array( |
||
60 | 'localBasePath' => __DIR__ , |
||
61 | 'remoteExtPath' => 'WhatsNearby', |
||
62 | 'position' => 'bottom', |
||
63 | 'scripts' => array( |
||
64 | 'res/ext.whats.nearby.geoip.js' |
||
65 | ), |
||
66 | 'targets' => array( |
||
67 | 'mobile', |
||
68 | 'desktop' |
||
69 | ) |
||
70 | ); |
||
71 | |||
72 | $GLOBALS['wgResourceModules']['ext.whats.nearby'] = array( |
||
73 | 'localBasePath' => __DIR__ , |
||
74 | 'remoteExtPath' => 'WhatsNearby', |
||
75 | 'position' => 'bottom', |
||
76 | 'styles' => array( 'res/ext.whats.nearby.css' ), |
||
77 | 'scripts' => array( 'res/ext.whats.nearby.js' ), |
||
78 | 'dependencies' => array( |
||
79 | 'mediawiki.api', |
||
80 | 'mediawiki.api.parse', |
||
81 | 'ext.maps.services', |
||
82 | 'onoi.rangeslider', |
||
83 | 'onoi.blockUI', |
||
84 | 'onoi.md5', |
||
85 | 'onoi.blobstore' |
||
86 | ), |
||
87 | 'messages' => array( |
||
88 | 'wnby-geolocation-disabled', |
||
89 | 'wnby-geolocation-unsupported', |
||
90 | 'wnby-geolocation-unknown-error', |
||
91 | 'wnby-geolocation-timeout-error', |
||
92 | 'wnby-geolocation-position-unavailable', |
||
93 | 'wnby-geolocation-permission-denied', |
||
94 | 'wnby-no-fallback-location', |
||
95 | 'wnby-geolocation-geoip-fallback', |
||
96 | 'wnby-geolocation-geoip-no-fallback', |
||
97 | 'wnby-default-fallback-location', |
||
98 | 'wnby-invalid-coordinates-format', |
||
99 | 'wnby-localcache-use', |
||
100 | 'wnby-template-parameter-missing', |
||
101 | 'wnby-loading' |
||
102 | ), |
||
103 | 'targets' => array( |
||
104 | 'mobile', |
||
105 | 'desktop' |
||
106 | ) |
||
107 | ); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * @since 1.0 |
||
112 | */ |
||
113 | public static function onExtensionFunction() { |
||
114 | $hookRegistry = new HookRegistry(); |
||
115 | $hookRegistry->register(); |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * @since 1.0 |
||
120 | * |
||
121 | * @return string|null |
||
122 | */ |
||
123 | public static function getVersion() { |
||
124 | return WNBY_VERSION; |
||
125 | } |
||
126 | |||
127 | } |
||
128 |
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.