1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
use WNBY\HookRegistry; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @see https://github.com/SemanticMediaWiki/WhatsNearby/ |
7
|
|
|
* @link https://www.semantic-mediawiki.org/wiki/Extension:WhatsNearby |
8
|
|
|
* |
9
|
|
|
* @defgroup wnby WhatsNearby |
10
|
|
|
*/ |
11
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) { |
12
|
|
|
die( 'This file is part of the WhatsNearby extension, it is not a valid entry point.' ); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
if ( version_compare( $GLOBALS[ 'wgVersion' ], '1.23', 'lt' ) ) { |
16
|
|
|
die( '<b>Error:</b> This version of <a href="https://github.com/SemanticMediaWiki/WhatsNearby/">WhatsNearby</a> is only compatible with MediaWiki 1.23 or above. You need to upgrade MediaWiki first.' ); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
// Do not initialize more than once. |
20
|
|
|
if ( defined( 'WNBY_VERSION' ) ) { |
21
|
|
|
return 1; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
WhatsNearby::initExtension(); |
25
|
|
|
|
26
|
|
|
$GLOBALS['wgExtensionFunctions'][] = function() { |
27
|
|
|
WhatsNearby::onExtensionFunction(); |
28
|
|
|
}; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @codeCoverageIgnore |
32
|
|
|
*/ |
33
|
|
|
class WhatsNearby { |
|
|
|
|
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @since 1.0 |
37
|
|
|
*/ |
38
|
|
|
public static function initExtension() { |
|
|
|
|
39
|
|
|
|
40
|
|
|
// Load DefaultSettings |
41
|
|
|
require_once __DIR__ . '/DefaultSettings.php'; |
42
|
|
|
|
43
|
|
|
define( 'WNBY_VERSION', '1.0.0-alpha' ); |
44
|
|
|
|
45
|
|
|
$GLOBALS['wgExtensionCredits']['others'][] = array( |
46
|
|
|
'path' => __DIR__, |
47
|
|
|
'name' => 'Whats Nearby', |
48
|
|
|
'author' => array( 'mwjames' ), |
49
|
|
|
'url' => 'https://www.semantic-mediawiki.org/wiki/Extension:WhatsNearby', |
50
|
|
|
'descriptionmsg' => 'wnby-desc', |
51
|
|
|
'version' => WNBY_VERSION, |
52
|
|
|
'license-name' => 'GPL-2.0+', |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
// Register message files |
56
|
|
|
$GLOBALS['wgMessagesDirs']['WhatsNearby'] = __DIR__ . '/i18n'; |
57
|
|
|
$GLOBALS['wgExtensionMessagesFiles']['WhatsNearbyMagic'] = __DIR__ . '/i18n/WhatsNearby.magic.php'; |
58
|
|
|
|
59
|
|
|
$GLOBALS['wgResourceModules']['ext.whats.nearby.geoip'] = array( |
60
|
|
|
'localBasePath' => __DIR__ , |
61
|
|
|
'remoteExtPath' => 'WhatsNearby', |
62
|
|
|
'position' => 'bottom', |
63
|
|
|
'scripts' => array( |
64
|
|
|
'res/ext.whats.nearby.geoip.js' |
65
|
|
|
), |
66
|
|
|
'targets' => array( |
67
|
|
|
'mobile', |
68
|
|
|
'desktop' |
69
|
|
|
) |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$GLOBALS['wgResourceModules']['ext.whats.nearby'] = array( |
73
|
|
|
'localBasePath' => __DIR__ , |
74
|
|
|
'remoteExtPath' => 'WhatsNearby', |
75
|
|
|
'position' => 'bottom', |
76
|
|
|
'styles' => array( 'res/ext.whats.nearby.css' ), |
77
|
|
|
'scripts' => array( 'res/ext.whats.nearby.js' ), |
78
|
|
|
'dependencies' => array( |
79
|
|
|
'mediawiki.api', |
80
|
|
|
'mediawiki.api.parse', |
81
|
|
|
'ext.maps.services', |
82
|
|
|
'onoi.rangeslider', |
83
|
|
|
'onoi.blockUI', |
84
|
|
|
'onoi.md5', |
85
|
|
|
'onoi.blobstore' |
86
|
|
|
), |
87
|
|
|
'messages' => array( |
88
|
|
|
'wnby-geolocation-disabled', |
89
|
|
|
'wnby-geolocation-unsupported', |
90
|
|
|
'wnby-geolocation-unknown-error', |
91
|
|
|
'wnby-geolocation-timeout-error', |
92
|
|
|
'wnby-geolocation-position-unavailable', |
93
|
|
|
'wnby-geolocation-permission-denied', |
94
|
|
|
'wnby-no-fallback-location', |
95
|
|
|
'wnby-geolocation-geoip-fallback', |
96
|
|
|
'wnby-geolocation-geoip-no-fallback', |
97
|
|
|
'wnby-default-fallback-location', |
98
|
|
|
'wnby-invalid-coordinates-format', |
99
|
|
|
'wnby-localcache-use', |
100
|
|
|
'wnby-template-parameter-missing', |
101
|
|
|
'wnby-loading' |
102
|
|
|
), |
103
|
|
|
'targets' => array( |
104
|
|
|
'mobile', |
105
|
|
|
'desktop' |
106
|
|
|
) |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @since 1.0 |
112
|
|
|
*/ |
113
|
|
|
public static function onExtensionFunction() { |
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 WNBY_VERSION; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
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.