|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SESP\PropertyAnnotators; |
|
4
|
|
|
|
|
5
|
|
|
use SESP\AppFactory; |
|
6
|
|
|
use SESP\PropertyAnnotator; |
|
7
|
|
|
use SESP\DatabaseLogReader; |
|
8
|
|
|
use SMW\DIWikiPage; |
|
9
|
|
|
use SMWDataItem as DataItem; |
|
10
|
|
|
use SMW\DIProperty; |
|
11
|
|
|
use SMW\SemanticData; |
|
12
|
|
|
use Title; |
|
13
|
|
|
use User; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @private |
|
17
|
|
|
* @ingroup SESP |
|
18
|
|
|
* |
|
19
|
|
|
* @license GNU GPL v2+ |
|
20
|
|
|
*/ |
|
21
|
|
|
class ApprovedByPropertyAnnotator implements PropertyAnnotator { |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Predefined property ID |
|
25
|
|
|
*/ |
|
26
|
|
|
const PROP_ID = '___APPROVEDBY'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var AppFactory |
|
30
|
|
|
*/ |
|
31
|
|
|
private $appFactory; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var Integer|null |
|
35
|
|
|
*/ |
|
36
|
|
|
private $approvedBy; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param AppFactory $appFactory |
|
40
|
|
|
*/ |
|
41
|
4 |
|
public function __construct( AppFactory $appFactory ) { |
|
42
|
4 |
|
$this->appFactory = $appFactory; |
|
43
|
4 |
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @since 2.0 |
|
47
|
|
|
* |
|
48
|
|
|
* @param User $approvedBy |
|
49
|
|
|
*/ |
|
50
|
2 |
|
public function setApprovedBy( $approvedBy ) { |
|
51
|
2 |
|
$this->approvedBy = $approvedBy; |
|
|
|
|
|
|
52
|
2 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* {@inheritDoc} |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function isAnnotatorFor( DIProperty $property ) { |
|
58
|
1 |
|
return $property->getKey() === self::PROP_ID; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
2 |
|
public function getDataItem() { |
|
62
|
2 |
|
if ( $this->approvedBy instanceof User ) { |
|
|
|
|
|
|
63
|
1 |
|
$userPage = $this->approvedBy->getUserPage(); |
|
64
|
|
|
|
|
65
|
1 |
|
if ( $userPage instanceof Title ) { |
|
|
|
|
|
|
66
|
1 |
|
return DIWikiPage::newFromTitle( $userPage ); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritDoc} |
|
73
|
|
|
*/ |
|
74
|
2 |
|
public function addAnnotation( |
|
75
|
|
|
DIProperty $property, SemanticData $semanticData |
|
76
|
|
|
) { |
|
77
|
2 |
|
if ( $this->approvedBy === null && class_exists( 'ApprovedRevs' ) ) { |
|
78
|
|
|
$logReader = $this->appFactory->newDatabaseLogReader( |
|
79
|
|
|
$semanticData->getSubject()->getTitle(), 'approval' |
|
80
|
|
|
); |
|
81
|
|
|
$this->approvedBy = $logReader->getUserForLogEntry(); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
2 |
|
$dataItem = $this->getDataItem(); |
|
85
|
2 |
|
if ( $dataItem ) { |
|
86
|
1 |
|
$semanticData->addPropertyObjectValue( $property, $dataItem ); |
|
87
|
1 |
|
} else { |
|
88
|
1 |
|
$semanticData->removeProperty( $property ); |
|
89
|
|
|
} |
|
90
|
2 |
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..