summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/DataValues/ValueFormatters/DataValueFormatter.php
blob: 8ffdf555ff923d5756609040f4a03a9d2aa83f25 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php

namespace SMW\DataValues\ValueFormatters;

use SMW\Options;
use SMWDataValue as DataValue;

/**
 * @license GNU GPL v2+
 * @since 2.4
 *
 * @author mwjames
 */
abstract class DataValueFormatter implements ValueFormatter {

	/**
	 * Return the plain wiki version of the value, or FALSE if no such version
	 * is available. The returned string suffices to reobtain the same DataValue
	 * when passing it as an input string to DataValue::setUserValue.
	 */
	const VALUE = 0;

	/**
	 * Returns a short textual representation for this data value. If the value
	 * was initialised from a user supplied string, then this original string
	 * should be reflected in this short version (i.e. no normalisation should
	 * normally happen). There might, however, be additional parts such as code
	 * for generating tooltips. The output is in wiki text.
	 */
	const WIKI_SHORT = 1;

	/**
	 * Returns a short textual representation for this data value. If the value
	 * was initialised from a user supplied string, then this original string
	 * should be reflected in this short version (i.e. no normalisation should
	 * normally happen). There might, however, be additional parts such as code
	 * for generating tooltips. The output is in HTML text.
	 */
	const HTML_SHORT = 2;

	/**
	 * Return the long textual description of the value, as printed for example
	 * in the factbox. If errors occurred, return the error message. The result
	 * is always a wiki-source string.
	 */
	const WIKI_LONG = 3;

	/**
	 * Return the long textual description of the value, as printed for
	 * example in the factbox. If errors occurred, return the error message
	 * The result always is an HTML string.
	 */
	const HTML_LONG = 4;

	/**
	 * @var DataValue
	 */
	protected $dataValue;

	/**
	 * @var Options
	 */
	private $options = null;

	/**
	 * @since 2.4
	 *
	 * @param DataValue|null $dataValue
	 */
	public function __construct( DataValue $dataValue = null ) {
		$this->dataValue = $dataValue;
	}

	/**
	 * @since 2.4
	 *
	 * @param DataValue $dataValue
	 *
	 * @return boolean
	 */
	abstract public function isFormatterFor( DataValue $dataValue );

	/**
	 * @since 2.4
	 *
	 * @param DataValue $dataValue
	 */
	public function setDataValue( DataValue $dataValue ) {
		$this->dataValue = $dataValue;
		$this->options = null;
	}

	/**
	 * @since 2.4
	 *
	 * @return array
	 */
	public function getErrors() {
		return $this->dataValue->getErrors();
	}

	/**
	 * @since 2.4
	 *
	 * @param string $key
	 * @param mixed $value
	 */
	public function setOption( $key, $value ) {

		if ( $this->options === null ) {
			$this->options = new Options();
		}

		$this->options->set( $key, $value );
	}

	/**
	 * @since 2.4
	 *
	 * @param string $key
	 *
	 * @return mixed|false
	 */
	public function getOption( $key ) {

		if ( $this->options !== null && $this->options->has( $key ) ) {
			return $this->options->get( $key );
		}

		return false;
	}

}