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 | // In case extension.json is being used, the the succeeding steps will |
||
48 | // be handled by the ExtensionRegistry |
||
49 | self::initExtension(); |
||
50 | |||
51 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
52 | self::onExtensionFunction(); |
||
53 | }; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @since 1.4 |
||
58 | */ |
||
59 | public static function initExtension() { |
||
60 | |||
61 | define( 'SESP_VERSION', '2.0.0-alpha' ); |
||
62 | |||
63 | // Register extension info |
||
64 | $GLOBALS['wgExtensionCredits']['semantic'][] = array( |
||
65 | 'path' => __FILE__, |
||
66 | 'name' => 'Semantic Extra Special Properties', |
||
67 | 'author' => array( |
||
68 | '[https://www.semantic-mediawiki.org/wiki/User:MWJames James Hong Kong]', |
||
69 | '...' |
||
70 | ), |
||
71 | 'version' => SESP_VERSION, |
||
72 | 'url' => 'https://www.mediawiki.org/wiki/Extension:SemanticExtraSpecialProperties', |
||
73 | 'descriptionmsg' => 'sesp-desc', |
||
74 | 'license-name' => 'GPL-2.0+' |
||
75 | ); |
||
76 | |||
77 | $GLOBALS['wgMessagesDirs']['SemanticExtraSpecialProperties'] = __DIR__ . '/i18n'; |
||
78 | $GLOBALS['wgExtensionMessagesFiles']['SemanticExtraSpecialProperties'] = __DIR__ . '/i18n/SemanticExtraSpecialProperties.i18n.php'; |
||
79 | |||
80 | self::onBeforeExtensionFunction(); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * Register hooks that require to be listed as soon as possible and preferable |
||
85 | * before the execution of onExtensionFunction |
||
86 | * |
||
87 | * @since 1.4 |
||
88 | */ |
||
89 | public static function onBeforeExtensionFunction() { |
||
90 | $GLOBALS['wgHooks']['SMW::Config::BeforeCompletion'][] = '\SESP\HookRegistry::onBeforeConfigCompletion'; |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @since 2.0 |
||
95 | */ |
||
96 | public static function doCheckRequirements() { |
||
97 | |||
98 | if ( version_compare( $GLOBALS['wgVersion'], '1.25', '<' ) ) { |
||
99 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties/">Semantic Extra Special Properties</a> requires MediaWiki 1.25 or above.' ); |
||
0 ignored issues
–
show
|
|||
100 | } |
||
101 | |||
102 | if ( !defined( 'SMW_VERSION' ) ) { |
||
103 | die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticExtraSpecialProperties/">Semantic Extra Special Properties</a> requires <a href="http://www.semantic-mediawiki.org/wiki/Semantic_MediaWiki">Semantic MediaWiki</a> installed.<br />' ); |
||
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 ![]() |
|||
104 | } |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * @since 1.4 |
||
109 | */ |
||
110 | public static function onExtensionFunction() { |
||
111 | |||
112 | // Check requirements after LocalSetting.php has been processed |
||
113 | self::doCheckRequirements(); |
||
114 | |||
115 | $configuration = array( |
||
116 | 'wgDisableCounters' => $GLOBALS['wgDisableCounters'], |
||
117 | 'sespUseAsFixedTables' => $GLOBALS['sespUseAsFixedTables'], |
||
118 | 'sespSpecialProperties' => $GLOBALS['sespSpecialProperties'], |
||
119 | 'wgSESPExcludeBots' => $GLOBALS['wgSESPExcludeBots'], |
||
120 | 'wgShortUrlPrefix' => $GLOBALS['wgShortUrlPrefix'], |
||
121 | 'sespPropertyDefinitionFile' => $GLOBALS['sespPropertyDefinitionFile'], |
||
122 | 'sespLocalPropertyDefinitions' => $GLOBALS['sespLocalPropertyDefinitions'], |
||
123 | 'sespLabelCacheVersion' => $GLOBALS['sespLabelCacheVersion'], |
||
124 | 'sespPropertyDefinitions' => array(), |
||
125 | ); |
||
126 | |||
127 | $hookRegistry = new HookRegistry( |
||
128 | $configuration |
||
129 | ); |
||
130 | |||
131 | $hookRegistry->register(); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @since 1.4 |
||
136 | * |
||
137 | * @return string|null |
||
138 | */ |
||
139 | public static function getVersion() { |
||
140 | return SESP_VERSION; |
||
141 | } |
||
142 | |||
143 | } |
||
144 |
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.