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 SESP\HookRegistry; |
||
4 | |||
5 | /** |
||
6 | * Extension SemanticExtraSpecialProperties - Adds some extra special properties to all pages. |
||
7 | * |
||
8 | * @see https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties |
||
9 | * |
||
10 | * @defgroup SemanticExtraSpecialProperties Semantic Extra Special Properties |
||
11 | */ |
||
12 | if ( !defined( 'MEDIAWIKI' ) ) { |
||
13 | die( 'This file is part of the SemanticExtraSpecialProperties extension, it is not a valid entry point.' ); |
||
14 | } |
||
15 | |||
16 | if ( defined( 'SESP_VERSION' ) ) { |
||
17 | // Do not initialize more than once. |
||
18 | return 1; |
||
19 | } |
||
20 | |||
21 | SemanticExtraSpecialProperties::load(); |
||
22 | |||
23 | /** |
||
24 | * @codeCoverageIgnore |
||
25 | */ |
||
26 | class SemanticExtraSpecialProperties { |
||
27 | |||
28 | /** |
||
29 | * @since 1.4 |
||
30 | * |
||
31 | * @note It is expected that this function is loaded before LocalSettings.php |
||
32 | * to ensure that settings and global functions are available by the time |
||
33 | * the extension is activated. |
||
34 | */ |
||
35 | public static function load() { |
||
36 | |||
37 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
38 | include_once __DIR__ . '/vendor/autoload.php'; |
||
39 | } |
||
40 | |||
41 | foreach ( include __DIR__ . '/DefaultSettings.php' as $key => $value ) { |
||
42 | if ( !isset( $GLOBALS[$key] ) ) { |
||
43 | $GLOBALS[$key] = $value; |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @since 1.4 |
||
50 | */ |
||
51 | public static function initExtension( $credits = array() ) { |
||
52 | |||
53 | // See https://phabricator.wikimedia.org/T151136 |
||
54 | define( 'SESP_VERSION', isset( $credits['version'] ) ? $credits['version'] : 'UNKNOWN' ); |
||
55 | |||
56 | $GLOBALS['wgMessagesDirs']['SemanticExtraSpecialProperties'] = __DIR__ . '/i18n'; |
||
57 | |||
58 | // Register hooks that require to be listed as soon as possible and preferable |
||
59 | // before the execution of onExtensionFunction |
||
60 | HookRegistry::initExtension( $GLOBALS ); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @since 1.4 |
||
65 | */ |
||
66 | public static function onExtensionFunction() { |
||
67 | |||
68 | if ( !defined( 'SMW_VERSION' ) ) { |
||
69 | if ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' ) { |
||
70 | die( "\nThe 'Semantic Extra Special Properties' extension requires 'Semantic MediaWiki' to be installed and enabled.\n" ); |
||
0 ignored issues
–
show
|
|||
71 | } else { |
||
72 | die( '<b>Error:</b> The <a href="https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties/">Semantic Extra Special Properties</a> extension requires <a href="https://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> to be installed and enabled.<br />' ); |
||
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...
|
|||
73 | } |
||
74 | } |
||
75 | |||
76 | $config = [ |
||
77 | 'wgDisableCounters' => $GLOBALS['wgDisableCounters'], |
||
78 | 'sespUseAsFixedTables' => $GLOBALS['sespUseAsFixedTables'], |
||
79 | 'sespSpecialProperties' => $GLOBALS['sespSpecialProperties'], |
||
80 | 'wgSESPExcludeBots' => $GLOBALS['wgSESPExcludeBots'], |
||
81 | 'wgShortUrlPrefix' => $GLOBALS['wgShortUrlPrefix'], |
||
82 | 'sespPropertyDefinitionFile' => $GLOBALS['sespPropertyDefinitionFile'], |
||
83 | 'sespLocalPropertyDefinitions' => $GLOBALS['sespLocalPropertyDefinitions'], |
||
84 | 'sespLabelCacheVersion' => $GLOBALS['sespLabelCacheVersion'], |
||
85 | 'sespPropertyDefinitions' => [], |
||
86 | ]; |
||
87 | |||
88 | $hookRegistry = new HookRegistry( |
||
89 | $config |
||
90 | ); |
||
91 | |||
92 | $hookRegistry->register(); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @since 1.4 |
||
97 | * |
||
98 | * @return string|null |
||
99 | */ |
||
100 | public static function getVersion() { |
||
101 | |||
102 | if ( !defined( 'SESP_VERSION' ) ) { |
||
103 | return null; |
||
104 | } |
||
105 | |||
106 | return SESP_VERSION; |
||
107 | } |
||
108 | |||
109 | } |
||
110 |
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
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.