SemanticMediaWiki /
SemanticNotifications
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::initExtension(); |
||
| 20 | |||
| 21 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
| 22 | SemanticNotifications::onExtensionFunction(); |
||
| 23 | }; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @codeCoverageIgnore |
||
| 27 | */ |
||
| 28 | class SemanticNotifications { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @since 1.0 |
||
| 32 | */ |
||
| 33 | public static function initExtension() { |
||
| 34 | |||
| 35 | define( 'SMW_NOTIFICATIONS_VERSION', '1.0.0-alpha' ); |
||
| 36 | |||
| 37 | // Register extension info |
||
| 38 | $GLOBALS['wgExtensionCredits']['semantic'][] = array( |
||
| 39 | 'path' => __FILE__, |
||
| 40 | 'name' => 'Semantic Notifications', |
||
| 41 | 'author' => array( 'James Hong Kong' ), |
||
| 42 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticNotifications/', |
||
| 43 | 'descriptionmsg' => 'smw-notifications-desc', |
||
| 44 | 'version' => SMW_NOTIFICATIONS_VERSION, |
||
| 45 | 'license-name' => 'GPL-2.0+', |
||
| 46 | ); |
||
| 47 | |||
| 48 | // Register message files |
||
| 49 | $GLOBALS['wgMessagesDirs']['SemanticNotifications'] = __DIR__ . '/i18n'; |
||
| 50 | |||
| 51 | $GLOBALS['snogChangeNotificationDetectionPropertyExemptionList'] = array( |
||
| 52 | '_MDAT', |
||
| 53 | '_REDI' |
||
| 54 | ); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @since 1.0 |
||
| 59 | */ |
||
| 60 | public static function onExtensionFunction() { |
||
|
0 ignored issues
–
show
|
|||
| 61 | |||
| 62 | if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.26', 'lt' ) ) { |
||
| 63 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticNotifications/">Semantic Notifications</a> is only compatible with MediaWiki 1.26 or above. You need to upgrade MediaWiki first.' ); |
||
|
0 ignored issues
–
show
The method
onExtensionFunction() 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 Loading history...
|
|||
| 64 | } |
||
| 65 | |||
| 66 | // There is no good way to detect whether Echo is available or not without |
||
| 67 | // making a class_exists, what should I say ... |
||
| 68 | if ( !isset( $GLOBALS['wgMessagesDirs']['Echo'] ) ) { |
||
| 69 | 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
onExtensionFunction() 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 Loading history...
|
|||
| 70 | } |
||
| 71 | |||
| 72 | if ( !defined( 'SMW_VERSION' ) ) { |
||
| 73 | 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
onExtensionFunction() 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 Loading history...
|
|||
| 74 | } |
||
| 75 | |||
| 76 | $hookRegistry = new HookRegistry(); |
||
| 77 | $hookRegistry->register(); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @since 1.0 |
||
| 82 | * |
||
| 83 | * @return string|null |
||
| 84 | */ |
||
| 85 | public static function getVersion() { |
||
| 86 | return SMW_NOTIFICATIONS_VERSION; |
||
| 87 | } |
||
| 88 | |||
| 89 | } |
||
| 90 |
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: