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 SMW\Notifications\HookRegistry; |
||
4 | |||
5 | /** |
||
6 | * @see https://github.com/SemanticMediaWiki/SemanticNotifications/ |
||
7 | * |
||
8 | * @defgroup SemanticNotifications Semantic Notifications |
||
9 | */ |
||
10 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
11 | die( 'This file is part of the Semantic Notifications extension, it is not a valid entry point.' ); |
||
12 | } |
||
13 | |||
14 | if ( defined( 'SMW_NOTIFICATIONS_VERSION' ) ) { |
||
15 | // Do not initialize more than once. |
||
16 | return 1; |
||
17 | } |
||
18 | |||
19 | SemanticNotifications::load(); |
||
20 | |||
21 | /** |
||
22 | * @codeCoverageIgnore |
||
23 | */ |
||
24 | class SemanticNotifications { |
||
25 | |||
26 | /** |
||
27 | * @since 1.0 |
||
28 | * |
||
29 | * @note It is expected that this function is loaded before LocalSettings.php |
||
30 | * to ensure that settings and global functions are available by the time |
||
31 | * the extension is activated. |
||
32 | */ |
||
33 | public static function load() { |
||
34 | |||
35 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
36 | include_once __DIR__ . '/vendor/autoload.php'; |
||
37 | } |
||
38 | |||
39 | $GLOBALS['snogChangeNotificationDetectionPropertyExemptionList'] = array( |
||
40 | '_MDAT', |
||
41 | '_REDI' |
||
42 | ); |
||
43 | |||
44 | // In case extension.json is being used, the succeeding steps are |
||
45 | // expected to be handled by the ExtensionRegistry |
||
46 | self::initExtension(); |
||
47 | |||
48 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
49 | self::onExtensionFunction(); |
||
50 | }; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @since 1.0 |
||
55 | */ |
||
56 | public static function initExtension() { |
||
0 ignored issues
–
show
|
|||
57 | |||
58 | define( 'SMW_NOTIFICATIONS_VERSION', '1.0.0-alpha' ); |
||
59 | |||
60 | // Register extension info |
||
61 | $GLOBALS['wgExtensionCredits']['semantic'][] = array( |
||
62 | 'path' => __FILE__, |
||
63 | 'name' => 'Semantic Notifications', |
||
64 | 'author' => array( 'James Hong Kong' ), |
||
65 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticNotifications/', |
||
66 | 'descriptionmsg' => 'smw-notifications-desc', |
||
67 | 'version' => SMW_NOTIFICATIONS_VERSION, |
||
68 | 'license-name' => 'GPL-2.0-or-later' |
||
69 | ); |
||
70 | |||
71 | // Register message files |
||
72 | $GLOBALS['wgMessagesDirs']['SemanticNotifications'] = __DIR__ . '/i18n'; |
||
73 | |||
74 | self::onBeforeCreateEchoEvent(); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Register the hook before the execution of ExtensionFunction |
||
79 | * |
||
80 | * @since 1.0 |
||
81 | */ |
||
82 | public static function onBeforeCreateEchoEvent() { |
||
0 ignored issues
–
show
onBeforeCreateEchoEvent 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);
}
}
![]() |
|||
83 | $GLOBALS['wgHooks']['BeforeCreateEchoEvent'][] = "\SMW\Notifications\EchoNotificationsManager::initNotificationsDefinitions"; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @since 1.0 |
||
88 | */ |
||
89 | public static function doCheckRequirements() { |
||
0 ignored issues
–
show
doCheckRequirements 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);
}
}
![]() |
|||
90 | |||
91 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.27', 'lt' ) ) { |
||
92 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticNotifications/">Semantic Notifications</a> is only compatible with MediaWiki 1.27 or above. You need to upgrade MediaWiki first.' ); |
||
0 ignored issues
–
show
The method
doCheckRequirements() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
93 | } |
||
94 | |||
95 | // There is no good way to detect whether Echo is available or not without |
||
96 | // making a class_exists, what should I say ... |
||
97 | if ( !isset( $GLOBALS['wgMessagesDirs']['Echo'] ) ) { |
||
98 | die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticNotifications/">Semantic Notifications</a> requires the Echo extension, please enable or install <a href="https://www.mediawiki.org/wiki/Extension:Echo">Echo(Notifications)</a> first.' ); |
||
0 ignored issues
–
show
The method
doCheckRequirements() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
99 | } |
||
100 | |||
101 | if ( !defined( 'SMW_VERSION' ) ) { |
||
102 | die( '<b>Error:</b> <a href="https://github.com/SemanticMediaWiki/SemanticNotifications/">Semantic Notifications</a> requires the Semantic MediaWiki extension, please enable or install <a href="https://github.com/SemanticMediaWiki/SemanticMediaWiki/">Semantic MediaWiki</a> first.' ); |
||
0 ignored issues
–
show
The method
doCheckRequirements() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
103 | } |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @since 1.0 |
||
108 | */ |
||
109 | public static function onExtensionFunction() { |
||
110 | |||
111 | // Check requirements after LocalSetting.php has been processed |
||
112 | self::doCheckRequirements(); |
||
113 | |||
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 SMW_NOTIFICATIONS_VERSION; |
||
125 | } |
||
126 | |||
127 | } |
||
128 |
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: