1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
use SFS\HookRegistry; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* @see https://github.com/SemanticMediaWiki/SemanticFormsSelect/ |
7
|
|
|
* |
8
|
|
|
* @defgroup SemanticFormsSelect Semantic Forms Select |
9
|
|
|
*/ |
10
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) { |
11
|
|
|
die( 'Not an entry point.' ); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
if ( defined( 'SFS_VERSION' ) ) { |
15
|
|
|
// Do not initialize more than once. |
16
|
|
|
return 1; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
SemanticFormsSelect::initExtension(); |
20
|
|
|
|
21
|
|
|
$GLOBALS['wgExtensionFunctions'][] = function() { |
22
|
|
|
SemanticFormsSelect::onExtensionFunction(); |
23
|
|
|
}; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @codeCoverageIgnore |
27
|
|
|
*/ |
28
|
|
|
class SemanticFormsSelect { |
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @since 1.0 |
32
|
|
|
*/ |
33
|
|
|
public static function initExtension() { |
|
|
|
|
34
|
|
|
|
35
|
|
|
define( 'SFS_VERSION', '1.4.0-alpha' ); |
36
|
|
|
|
37
|
|
|
$GLOBALS['wgExtensionCredits']['semantic'][] = array( |
38
|
|
|
'path' => __FILE__, |
39
|
|
|
'name' => 'Semantic Forms Select', |
40
|
|
|
'author' =>array( 'Jason Zhang', 'Toni Hermoso Pulido', '...' ), |
41
|
|
|
'url' => 'https://www.mediawiki.org/wiki/Extension:SemanticFormsSelect', |
42
|
|
|
'description' => 'Allows to generate a select field in a semantic form whose values are retrieved from a query', |
43
|
|
|
'version' => SFS_VERSION, |
44
|
|
|
'license-name' => 'GPL-2.0+', |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
// Api modules |
48
|
|
|
$GLOBALS['wgAPIModules']['sformsselect'] = 'SFS\ApiSemanticFormsSelect'; |
49
|
|
|
|
50
|
|
|
$GLOBALS['wgScriptSelectCount'] = 0; |
51
|
|
|
$GLOBALS['wgSF_Select_debug'] = 0; |
52
|
|
|
|
53
|
|
|
// Register resource files |
54
|
|
|
$GLOBALS['wgResourceModules']['ext.sf_select.scriptselect'] = array( |
55
|
|
|
'localBasePath' => __DIR__ , |
56
|
|
|
'remoteExtPath' => 'SemanticFormsSelect', |
57
|
|
|
'position' => 'bottom', |
58
|
|
|
'scripts' => array( 'res/scriptSelect.js' ), |
59
|
|
|
'dependencies' => array( |
60
|
|
|
'ext.semanticforms.main' |
61
|
|
|
) |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @since 1.0 |
67
|
|
|
*/ |
68
|
|
|
public static function onExtensionFunction() { |
|
|
|
|
69
|
|
|
|
70
|
|
|
if ( !defined( 'SF_VERSION' ) ) { |
71
|
|
|
die( '<b>Error:</b><a href="https://github.com/SemanticMediaWiki/SemanticFormsSelect/">Semantic Forms Select</a> requires the <a href="https://www.mediawiki.org/wiki/Extension:SemanticForms">Semantic Forms</a> extension. Please install and activate this extension first.' ); |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if ( isset( $GLOBALS['sfgFormPrinter'] )) { |
75
|
|
|
$GLOBALS['sfgFormPrinter']->setInputTypeHook( 'SF_Select', '\SFS\SemanticFormsSelect::init', array() ); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @since 1.0 |
81
|
|
|
* |
82
|
|
|
* @return string|null |
83
|
|
|
*/ |
84
|
|
|
public static function getVersion() { |
85
|
|
|
return SFS_VERSION; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
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.