Completed
Push — master ( 314506...335380 )
by mw
100:54 queued 62:54
created

includes/datavalues/SMW_DV_String.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 93
	protected function parseUserValue( $value ) {
26
27 93
		if ( $value === '' ) {
28 1
			$this->addErrorMsg( 'smw_emptystring' );
29
		}
30
31 93
		$this->m_dataitem = new DIBlob( $value );
32 93
	}
33
34
	/**
35
	 * @see DataValue::loadDataItem
36
	 *
37
	 * @param SMWDataItem $dataitem
38
	 *
39
	 * @return boolean
40
	 */
41 86
	protected function loadDataItem( DataItem $dataItem ) {
42
43 86
		if ( !$dataItem instanceof DIBlob ) {
44
			return false;
45
		}
46
47 86
		$this->m_caption = false;
48 86
		$this->m_dataitem = $dataItem;
49
50 86
		return true;
51
	}
52
53
	/**
54
	 * @see DataValue::getShortWikiText
55
	 *
56
	 * @return string
57
	 */
58 80
	public function getShortWikiText( $linker = null ) {
59 80
		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 71
	public function getWikiValue() {
96 71
		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
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
126 1
		return array( rawurlencode( $this->m_dataitem->getString() ) );
127
	}
128
129
}
130