blob: 4372f144b23ae3202fc263c32744618ab1837815 (
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
<?php
namespace SMW\DataValues;
use SMW\Message;
use SMWDataItem as DataItem;
use SMWDataValue as DataValue;
use SMWDIBlob as DIBlob;
/**
* Handling of a language dependent error message encoded by Message::encode.
*
* @license GNU GPL v2+
* @since 2.5
*
* @author mwjames
*/
class ErrorMsgTextValue extends DataValue {
/**
* @see DataValue::__construct
*/
public function __construct( $typeId = '' ) {
parent::__construct( '__errt' );
}
/**
* @see DataValue::parseUserValue
*
* @param string $value
*/
protected function parseUserValue( $value ) {
if ( $value === '' ) {
$this->addErrorMsg( 'smw_emptystring' );
}
$this->m_dataitem = new DIBlob( $value );
}
/**
* @see DataValue::loadDataItem
*
* @param SMWDataItem $dataitem
*
* @return boolean
*/
protected function loadDataItem( DataItem $dataItem ) {
if ( !$dataItem instanceof DIBlob ) {
return false;
}
$this->m_caption = false;
$this->m_dataitem = $dataItem;
return true;
}
/**
* @see DataValue::getShortWikiText
*/
public function getShortWikiText( $linker = null ) {
return $this->constructErrorText( null );
}
/**
* @see DataValue::getShortHTMLText
*/
public function getShortHTMLText( $linker = null ) {
return $this->constructErrorText( $linker );
}
/**
* @see DataValue::getLongWikiText
*/
public function getLongWikiText( $linker = null ) {
return $this->constructErrorText( $linker );
}
/**
* @see DataValue::getLongHTMLText
*/
public function getLongHTMLText( $linker = null ) {
return $this->constructErrorText( $linker );
}
/**
* @see DataValue::getWikiValue
*/
public function getWikiValue() {
return $this->constructErrorText();
}
private function constructErrorText( $linker = null ) {
if ( !$this->isValid() || $this->getDataItem() === [] ) {
return '';
}
$string = $this->getDataItem()->getString();
$type = $linker !== null ? Message::PARSE : Message::TEXT;
if ( ( $message = Message::decode( $string, $type, $this->getOption( self::OPT_USER_LANGUAGE ) ) ) !== false ) {
return $message;
}
return $string;
}
}
|