blob: bc7bbd8e59a8dfa0df75fce1a0dcfa1dfd53fe85 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<?php
namespace SMW\PropertyAnnotators;
use SMW\PropertyAnnotator;
/**
* @license GNU GPL v2+
* @since 2.4
*
* @author mwjames
*/
class DisplayTitlePropertyAnnotator extends PropertyAnnotatorDecorator {
/**
* @var string|false
*/
private $displayTitle;
/**
* @var string
*/
private $defaultSort;
/**
* @var boolean
*/
private $canCreateAnnotation = true;
/**
* @since 2.4
*
* @param PropertyAnnotator $propertyAnnotator
* @param string|false $displayTitle
* @param string $defaultSort
*/
public function __construct( PropertyAnnotator $propertyAnnotator, $displayTitle = false, $defaultSort = '' ) {
parent::__construct( $propertyAnnotator );
$this->displayTitle = $displayTitle;
$this->defaultSort = $defaultSort;
}
/**
* @see SMW_DV_WPV_DTITLE in $GLOBALS['smwgDVFeatures']
*
* @since 2.5
*
* @param boolean $canCreateAnnotation
*/
public function canCreateAnnotation( $canCreateAnnotation ) {
$this->canCreateAnnotation = (bool)$canCreateAnnotation;
}
protected function addPropertyValues() {
if ( !$this->canCreateAnnotation || !$this->displayTitle || $this->displayTitle === '' ) {
return;
}
// #1439, #1611
$dataItem = $this->dataItemFactory->newDIBlob(
strip_tags( htmlspecialchars_decode( $this->displayTitle, ENT_QUOTES ) )
);
$this->getSemanticData()->addPropertyObjectValue(
$this->dataItemFactory->newDIProperty( '_DTITLE' ),
$dataItem
);
// If the defaultSort is empty then no explicit sortKey was expected
// therefore use the title content before the SortKeyPropertyAnnotator
if ( $this->defaultSort === '' ) {
$this->getSemanticData()->addPropertyObjectValue(
$this->dataItemFactory->newDIProperty( '_SKEY' ),
$dataItem
);
}
}
}
|