1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SMW\DataValues\ValueFormatters\DataValueFormatter; |
4
|
|
|
use SMWDataItem as DataItem; |
5
|
|
|
use SMWDataValue as DataValue; |
6
|
|
|
use SMWDIBlob as DIBlob; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* This datavalue implements String-Datavalues suitable for defining |
10
|
|
|
* String-types of properties. |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.6 |
14
|
|
|
* |
15
|
|
|
* @author Nikolas Iwan |
16
|
|
|
* @author Markus Krötzsch |
17
|
|
|
*/ |
18
|
|
|
class SMWStringValue extends DataValue { |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @see DataValue::parseUserValue |
22
|
|
|
* |
23
|
|
|
* @param string $value |
24
|
|
|
*/ |
25
|
85 |
|
protected function parseUserValue( $value ) { |
26
|
|
|
|
27
|
85 |
|
if ( $value === '' ) { |
28
|
1 |
|
$this->addErrorMsg( 'smw_emptystring' ); |
29
|
|
|
} |
30
|
|
|
|
31
|
85 |
|
$this->m_dataitem = new DIBlob( $value ); |
32
|
85 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @see DataValue::loadDataItem |
36
|
|
|
* |
37
|
|
|
* @param SMWDataItem $dataitem |
|
|
|
|
38
|
|
|
* |
39
|
|
|
* @return boolean |
40
|
|
|
*/ |
41
|
80 |
|
protected function loadDataItem( DataItem $dataItem ) { |
42
|
|
|
|
43
|
80 |
|
if ( !$dataItem instanceof DIBlob ) { |
44
|
|
|
return false; |
45
|
|
|
} |
46
|
|
|
|
47
|
80 |
|
$this->m_caption = false; |
|
|
|
|
48
|
80 |
|
$this->m_dataitem = $dataItem; |
49
|
|
|
|
50
|
80 |
|
return true; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @see DataValue::getShortWikiText |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
73 |
|
public function getShortWikiText( $linker = null ) { |
59
|
73 |
|
return $this->getDataValueFormatter()->format( DataValueFormatter::WIKI_SHORT, $linker ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @see DataValue::getShortHTMLText |
64
|
|
|
* |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
1 |
|
public function getShortHTMLText( $linker = null ) { |
68
|
1 |
|
return $this->getDataValueFormatter()->format( DataValueFormatter::HTML_SHORT, $linker ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @see DataValue::getLongWikiText |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getLongWikiText( $linker = null ) { |
77
|
|
|
return $this->getDataValueFormatter()->format( DataValueFormatter::WIKI_LONG, $linker ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @todo Rather parse input to obtain properly formatted HTML. |
82
|
|
|
* @see DataValue::getLongHTMLText |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
2 |
|
public function getLongHTMLText( $linker = null ) { |
87
|
2 |
|
return $this->getDataValueFormatter()->format( DataValueFormatter::HTML_LONG, $linker ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @see DataValue::getWikiValue |
92
|
|
|
* |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
68 |
|
public function getWikiValue() { |
96
|
68 |
|
return $this->getDataValueFormatter()->format( DataValueFormatter::VALUE ); |
97
|
|
|
} |
98
|
|
|
|
99
|
2 |
|
public function getWikiValueByLengthOf( $length ) { |
100
|
|
|
|
101
|
2 |
|
if ( mb_strlen( $this->getWikiValue() ) > $length ) { |
102
|
1 |
|
return mb_substr( $this->getWikiValue(), 0, $length ); |
103
|
|
|
} |
104
|
|
|
|
105
|
2 |
|
return $this->getWikiValue(); |
106
|
|
|
} |
107
|
|
|
|
108
|
1 |
|
public function getInfolinks() { |
109
|
|
|
|
110
|
1 |
|
if ( $this->m_typeid != '_cod' ) { |
111
|
1 |
|
return parent::getInfolinks(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return array(); |
115
|
|
|
} |
116
|
|
|
|
117
|
1 |
|
protected function getServiceLinkParams() { |
118
|
|
|
|
119
|
1 |
|
if ( !$this->isValid() ) { |
120
|
|
|
return false; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// Create links to mapping services based on a wiki-editable message. The parameters |
124
|
|
|
// available to the message are: |
125
|
|
|
// $1: urlencoded string |
|
|
|
|
126
|
1 |
|
return array( rawurlencode( $this->m_dataitem->getString() ) ); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
} |
130
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.