1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SIL; |
4
|
|
|
|
5
|
|
|
use SMW\ParserData; |
6
|
|
|
use SMW\Subobject; |
7
|
|
|
use SMW\DIProperty; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @license GNU GPL v2+ |
11
|
|
|
* @since 1.0 |
12
|
|
|
* |
13
|
|
|
* @author mwjames |
14
|
|
|
*/ |
15
|
|
|
class LanguageLinkAnnotator { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var ParserData |
19
|
|
|
*/ |
20
|
|
|
private $parserData; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @since 1.0 |
24
|
|
|
* |
25
|
|
|
* @param ParserData $parserData |
26
|
|
|
*/ |
27
|
8 |
|
public function __construct( ParserData $parserData ) { |
28
|
8 |
|
$this->parserData = $parserData; |
29
|
8 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @since 1.0 |
33
|
|
|
* |
34
|
|
|
* @param InterlanguageLink $interlanguageLink |
35
|
|
|
* |
36
|
|
|
* @return boolean |
37
|
|
|
*/ |
38
|
4 |
|
public function hasDifferentLanguageAnnotation( InterlanguageLink $interlanguageLink ) { |
39
|
|
|
|
40
|
4 |
|
$propertyValues = $this->parserData->getSemanticData()->getPropertyValues( |
41
|
4 |
|
new DIProperty( PropertyRegistry::SIL_CONTAINER ) |
42
|
|
|
); |
43
|
|
|
|
44
|
4 |
|
foreach ( $propertyValues as $value ) { |
45
|
1 |
|
if ( $value->getSubobjectname() !== $interlanguageLink->getContainerId() ) { |
46
|
1 |
|
return true; |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
3 |
|
return false; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @since 1.3 |
55
|
|
|
* |
56
|
|
|
* @return boolean |
57
|
|
|
*/ |
58
|
3 |
|
public function canAddAnnotation() { |
59
|
|
|
|
60
|
3 |
|
if ( method_exists( $this->parserData, 'canModifySemanticData' ) ) { |
61
|
|
|
return $this->parserData->canModifySemanticData(); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// SMW 3.0 |
65
|
3 |
|
if ( method_exists( $this->parserData, 'canUse' ) ) { |
66
|
3 |
|
return $this->parserData->canUse(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return true; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @since 1.0 |
74
|
|
|
* |
75
|
|
|
* @param InterlanguageLink $interlanguageLink |
76
|
|
|
*/ |
77
|
3 |
|
public function addAnnotationForInterlanguageLink( InterlanguageLink $interlanguageLink ) { |
78
|
|
|
|
79
|
3 |
|
$subobject = new Subobject( $this->parserData->getTitle() ); |
80
|
3 |
|
$subobject->setEmptyContainerForId( $interlanguageLink->getContainerId() ); |
81
|
|
|
|
82
|
3 |
|
$subobject->getSemanticData()->addDataValue( |
83
|
3 |
|
$interlanguageLink->newLanguageDataValue() |
84
|
|
|
); |
85
|
|
|
|
86
|
3 |
|
$subobject->getSemanticData()->addDataValue( |
87
|
3 |
|
$interlanguageLink->newLinkReferenceDataValue() |
88
|
|
|
); |
89
|
|
|
|
90
|
3 |
|
$this->parserData->getSemanticData()->addPropertyObjectValue( |
91
|
3 |
|
$interlanguageLink->newContainerProperty(), |
92
|
3 |
|
$subobject->getContainer() |
93
|
|
|
); |
94
|
|
|
|
95
|
3 |
|
$this->parserData->pushSemanticDataToParserOutput(); |
|
|
|
|
96
|
3 |
|
$this->parserData->setSemanticDataStateToParserOutputProperty(); |
|
|
|
|
97
|
3 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @since 1.0 |
101
|
|
|
* |
102
|
|
|
* @param InterwikiLanguageLink $interwikiLanguageLink |
103
|
|
|
*/ |
104
|
1 |
|
public function addAnnotationForInterwikiLanguageLink( InterwikiLanguageLink $interwikiLanguageLink ) { |
105
|
|
|
|
106
|
1 |
|
$subobject = new Subobject( $this->parserData->getTitle() ); |
107
|
1 |
|
$subobject->setEmptyContainerForId( $interwikiLanguageLink->getContainerId() ); |
108
|
|
|
|
109
|
1 |
|
$subobject->getSemanticData()->addDataValue( |
110
|
1 |
|
$interwikiLanguageLink->newLanguageDataValue() |
111
|
|
|
); |
112
|
|
|
|
113
|
1 |
|
$subobject->getSemanticData()->addDataValue( |
114
|
1 |
|
$interwikiLanguageLink->newInterwikiReferenceDataValue() |
115
|
|
|
); |
116
|
|
|
|
117
|
1 |
|
$this->parserData->getSemanticData()->addPropertyObjectValue( |
118
|
1 |
|
$interwikiLanguageLink->newContainerProperty(), |
119
|
1 |
|
$subobject->getContainer() |
120
|
|
|
); |
121
|
|
|
|
122
|
1 |
|
$this->parserData->pushSemanticDataToParserOutput(); |
|
|
|
|
123
|
1 |
|
$this->parserData->setSemanticDataStateToParserOutputProperty(); |
|
|
|
|
124
|
1 |
|
} |
125
|
|
|
|
126
|
|
|
} |
127
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.