1 | <?php |
||
24 | class SemanticScribunto { |
||
25 | |||
26 | /** |
||
27 | * @since 1.0 |
||
28 | * |
||
29 | * @note It is expected that this function is loaded before LocalSettings.php |
||
30 | * to ensure that settings and global functions are available by the time |
||
31 | * the extension is activated. |
||
32 | */ |
||
33 | public static function load() { |
||
34 | |||
35 | if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) { |
||
36 | include_once __DIR__ . '/vendor/autoload.php'; |
||
37 | } |
||
38 | |||
39 | // In case extension.json is being used, the the succeeding steps will |
||
40 | // be handled by the ExtensionRegistry |
||
41 | self::initExtension(); |
||
42 | |||
43 | $GLOBALS['wgExtensionFunctions'][] = function() { |
||
44 | self::onExtensionFunction(); |
||
45 | }; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @since 1.0 |
||
50 | */ |
||
51 | public static function initExtension() { |
||
52 | |||
53 | define( 'SMW_SCRIBUNTO_VERSION', '1.0.0-alpha' ); |
||
54 | |||
55 | // Register extension info |
||
56 | $GLOBALS['wgExtensionCredits']['semantic'][] = array( |
||
57 | 'path' => __FILE__, |
||
58 | 'name' => 'Semantic Scribunto', |
||
59 | 'author' => array( |
||
60 | 'James Hong Kong', |
||
61 | '[https://www.semantic-mediawiki.org/wiki/User:Oetterer Tobias Oetterer]', |
||
62 | ), |
||
63 | 'url' => 'https://github.com/SemanticMediaWiki/SemanticScribunto/', |
||
64 | 'descriptionmsg' => 'smw-scribunto-desc', |
||
65 | 'version' => SMW_SCRIBUNTO_VERSION, |
||
66 | 'license-name' => 'GPL-2.0+', |
||
67 | ); |
||
68 | |||
69 | // MW 1.26+ |
||
70 | if ( !function_exists( 'wfGlobalCacheKey' ) ) { |
||
71 | function wfGlobalCacheKey( /*...*/ ) { |
||
76 | } |
||
77 | |||
81 | |||
82 | /** |
||
83 | * @since 1.0 |
||
84 | */ |
||
85 | public static function checkRequirements() { |
||
100 | |||
101 | /** |
||
102 | * @since 1.0 |
||
103 | */ |
||
104 | public static function onExtensionFunction() { |
||
112 | |||
113 | /** |
||
114 | * @since 1.0 |
||
115 | * |
||
116 | * @return string|null |
||
117 | */ |
||
118 | public static function getVersion() { |
||
121 | |||
122 | } |
||
123 |
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.