1 | <?php |
||
12 | class NamespaceManager { |
||
13 | |||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | protected $globalVars; |
||
18 | |||
19 | /** |
||
20 | * @since 1.9 |
||
21 | * |
||
22 | * @param array &$globalVars |
||
23 | */ |
||
24 | 6 | public function __construct( &$globalVars ) { |
|
25 | 6 | $this->globalVars =& $globalVars; |
|
26 | 6 | } |
|
27 | |||
28 | /** |
||
29 | * @since 1.9 |
||
30 | */ |
||
31 | 4 | public function init() { |
|
32 | |||
33 | 4 | if ( !$this->isDefinedConstant( 'SMW_NS_PROPERTY' ) ) { |
|
34 | 1 | $this->initCustomNamespace( $this->globalVars ); |
|
35 | } |
||
36 | |||
37 | 4 | if ( empty( $this->globalVars['smwgContLang'] ) ) { |
|
38 | 4 | $this->globalVars['smwgContLang'] = ExtraneousLanguage::getInstance()->fetchByLanguageCode( $this->globalVars['wgLanguageCode'] ); |
|
39 | } |
||
40 | |||
41 | 4 | $this->addNamespaceSettings(); |
|
42 | |||
43 | 4 | return true; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @since 2.4 |
||
48 | * |
||
49 | * @param string $languageCode |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | 233 | public static function getNamespacesByLanguageCode( $languageCode ) { |
|
57 | |||
58 | /** |
||
59 | * @see Hooks:CanonicalNamespaces |
||
60 | * |
||
61 | * @since 1.9 |
||
62 | * |
||
63 | * @return array |
||
64 | */ |
||
65 | 270 | public static function getCanonicalNames() { |
|
78 | |||
79 | /** |
||
80 | * @since 1.9 |
||
81 | * |
||
82 | * @param integer offset |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | 4 | public static function buildNamespaceIndex( $offset ) { |
|
101 | |||
102 | /** |
||
103 | * 100 and 101 used to be occupied by SMW's now obsolete namespaces |
||
104 | * "Relation" and "Relation_Talk" |
||
105 | * |
||
106 | * 106 and 107 are occupied by the Semantic Forms, we define them here |
||
107 | * to offer some (easy but useful) support to SF |
||
108 | * |
||
109 | * @since 1.9 |
||
110 | * |
||
111 | * @param array $globalVars |
||
112 | */ |
||
113 | 2 | public static function initCustomNamespace( &$globalVars ) { |
|
129 | |||
130 | 4 | protected function addNamespaceSettings() { |
|
175 | |||
176 | 4 | protected function isValidConfigurationOrSetDefault( $element, $default ) { |
|
181 | |||
182 | 5 | protected function isDefinedConstant( $constant ) { |
|
185 | |||
186 | } |
||
187 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: