1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SG; |
4
|
|
|
|
5
|
|
|
use SMW\PropertyRegistry; |
6
|
|
|
|
7
|
|
|
define( 'SG_PROP_GLT', 'Glossary-Term' ); |
8
|
|
|
define( 'SG_PROP_GLD', 'Glossary-Definition' ); |
9
|
|
|
define( 'SG_PROP_GLL', 'Glossary-Link' ); |
10
|
|
|
define( 'SG_PROP_GLS', 'Glossary-Style' ); |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @ingroup SemanticGlossary |
14
|
|
|
* |
15
|
|
|
* @license GNU GPL v2+ |
16
|
|
|
* @since 1.0 |
17
|
|
|
* |
18
|
|
|
* @author mwjames |
19
|
|
|
*/ |
20
|
|
|
class PropertyRegistrationHelper { |
21
|
|
|
|
22
|
|
|
const SG_TERM = '___glt'; |
23
|
|
|
const SG_DEFINITION = '___gld'; |
24
|
|
|
const SG_LINK = '___gll'; |
25
|
|
|
const SG_STYLE = '___gls'; |
26
|
|
|
|
27
|
|
|
private $propertyRegistry; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* PropertyRegistry constructor. |
31
|
|
|
* |
32
|
|
|
* @param PropertyRegistry $propertyRegistry |
33
|
|
|
*/ |
34
|
4 |
|
public function __construct( PropertyRegistry $propertyRegistry ) { |
35
|
4 |
|
$this->propertyRegistry = $propertyRegistry; |
36
|
4 |
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @since 1.0 |
40
|
|
|
* |
41
|
|
|
* @return boolean |
42
|
|
|
*/ |
43
|
3 |
|
public function registerProperties() { |
44
|
|
|
|
45
|
|
|
$propertyDefinitions = array( |
46
|
3 |
|
self::SG_TERM => array( |
47
|
3 |
|
'label' => SG_PROP_GLT, |
48
|
3 |
|
'type' => '_txt', |
49
|
3 |
|
'alias' => wfMessage( 'semanticglossary-prop-glt' )->text() |
50
|
|
|
), |
51
|
3 |
|
self::SG_DEFINITION => array( |
52
|
3 |
|
'label' => SG_PROP_GLD, |
53
|
3 |
|
'type' => '_txt', |
54
|
3 |
|
'alias' => wfMessage( 'semanticglossary-prop-gld' )->text() |
55
|
|
|
), |
56
|
3 |
|
self::SG_LINK => array( |
57
|
3 |
|
'label' => SG_PROP_GLL, |
58
|
3 |
|
'type' => '_txt', |
59
|
3 |
|
'alias' => wfMessage( 'semanticglossary-prop-gll' )->text() |
60
|
|
|
), |
61
|
3 |
|
self::SG_STYLE => array( |
62
|
3 |
|
'label' => SG_PROP_GLS, |
63
|
3 |
|
'type' => '_txt', |
64
|
3 |
|
'alias' => wfMessage( 'semanticglossary-prop-gls' )->text() |
65
|
|
|
) |
66
|
|
|
); |
67
|
|
|
|
68
|
3 |
|
return $this->registerPropertiesFromList( $propertyDefinitions ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param string[][] $propertyList |
73
|
|
|
* @return bool |
74
|
|
|
*/ |
75
|
3 |
|
protected function registerPropertiesFromList( array $propertyList ) { |
76
|
|
|
|
77
|
3 |
|
foreach ( $propertyList as $propertyId => $definition ) { |
78
|
|
|
|
79
|
3 |
|
$this->propertyRegistry->registerProperty( |
80
|
3 |
|
$propertyId, |
81
|
3 |
|
$definition['type'], |
82
|
3 |
|
$definition['label'], |
83
|
3 |
|
true |
84
|
|
|
); |
85
|
|
|
|
86
|
3 |
|
$this->propertyRegistry->registerPropertyAlias( |
87
|
3 |
|
$propertyId, |
88
|
3 |
|
$definition['alias'] |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
3 |
|
return true; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
} |
96
|
|
|
|