1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
use SMT\HookRegistry; |
4
|
|
|
use SMT\Options; |
5
|
|
|
use SMW\ApplicationFactory; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticMetaTags/ |
9
|
|
|
* |
10
|
|
|
* @defgroup SMT Semantic Meta Tags |
11
|
|
|
*/ |
12
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) { |
13
|
|
|
die( 'This file is part of the SemanticMetaTags extension, it is not a valid entry point.' ); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
if ( defined( 'SMT_VERSION' ) ) { |
17
|
|
|
// Do not initialize more than once. |
18
|
|
|
return 1; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
SemanticMetaTags::load(); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @codeCoverageIgnore |
25
|
|
|
*/ |
26
|
|
|
class SemanticMetaTags { |
|
|
|
|
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
|
|
|
// Load DefaultSettings |
38
|
|
|
require_once __DIR__ . '/DefaultSettings.php'; |
39
|
|
|
|
40
|
|
|
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
41
|
|
|
include_once __DIR__ . '/vendor/autoload.php'; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// In case extension.json is being used, the the succeeding steps will |
45
|
|
|
// 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() { |
|
|
|
|
57
|
|
|
|
58
|
|
|
define( 'SMT_VERSION', '1.4.0-alpha' ); |
59
|
|
|
|
60
|
|
|
// Register extension info |
61
|
|
|
$GLOBALS['wgExtensionCredits']['semantic'][] = array( |
62
|
|
|
'path' => __FILE__, |
63
|
|
|
'name' => 'Semantic Meta Tags', |
64
|
|
|
'author' => array( 'James Hong Kong' ), |
65
|
|
|
'url' => 'https://github.com/SemanticMediaWiki/SemanticMetaTags/', |
66
|
|
|
'descriptionmsg' => 'smt-desc', |
67
|
|
|
'version' => SMT_VERSION, |
68
|
|
|
'license-name' => 'GPL-2.0+', |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
// Register message files |
72
|
|
|
$GLOBALS['wgMessagesDirs']['SemanticMetaTags'] = __DIR__ . '/i18n'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @since 1.4 |
77
|
|
|
*/ |
78
|
|
|
public static function doCheckRequirements() { |
|
|
|
|
79
|
|
|
|
80
|
|
|
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.27', 'lt' ) ) { |
81
|
|
|
die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/SemanticMetaTags/">SemanticMetaTags</a> is only compatible with MediaWiki 1.27 or above. You need to upgrade MediaWiki first.' ); |
|
|
|
|
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @since 1.0 |
87
|
|
|
*/ |
88
|
|
|
public static function onExtensionFunction() { |
|
|
|
|
89
|
|
|
|
90
|
|
|
// Check requirements after LocalSetting.php has been processed |
91
|
|
|
self::doCheckRequirements(); |
92
|
|
|
|
93
|
|
|
$configuration = array( |
94
|
|
|
'metaTagsContentPropertySelector' => $GLOBALS['smtgTagsProperties'], |
95
|
|
|
'metaTagsStaticContentDescriptor' => $GLOBALS['smtgTagsStrings'], |
96
|
|
|
'metaTagsBlacklist' => $GLOBALS['smtgTagsBlacklist'], |
97
|
|
|
'metaTagsFallbackUseForMultipleProperties' => $GLOBALS['smtgTagsPropertyFallbackUsage'], |
98
|
|
|
'metaTagsMetaPropertyPrefixes' => $GLOBALS['smtgMetaPropertyPrefixes'] |
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$hookRegistry = new HookRegistry( |
102
|
|
|
ApplicationFactory::getInstance()->getStore(), |
103
|
|
|
new Options( $configuration ) |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$hookRegistry->register(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @since 1.0 |
111
|
|
|
* |
112
|
|
|
* @return string|null |
113
|
|
|
*/ |
114
|
|
|
public static function getVersion() { |
115
|
|
|
return SMT_VERSION; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
} |
119
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.