Completed
Push — remove-labels-descriptions-met... ( f6767d )
by Bene
03:16
created

Entity::getDescription()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Wikibase\DataModel\Entity;
4
5
use Comparable;
6
use Wikibase\DataModel\Statement\Statement;
7
use Wikibase\DataModel\Term\AliasGroup;
8
use Wikibase\DataModel\Term\AliasGroupList;
9
use Wikibase\DataModel\Term\FingerprintHolder;
10
use Wikibase\DataModel\Term\TermList;
11
12
/**
13
 * Represents a single Wikibase entity.
14
 * See https://www.mediawiki.org/wiki/Wikibase/DataModel#Values
15
 *
16
 * @deprecated since 1.0 - do not type hint against Entity. See
17
 * https://lists.wikimedia.org/pipermail/wikidata-tech/2014-June/000489.html
18
 *
19
 * @licence GNU GPL v2+
20
 * @author Jeroen De Dauw < [email protected] >
21
 */
22
abstract class Entity implements Comparable, FingerprintHolder, EntityDocument {
23
24
	/**
25
	 * Sets the value for the label in a certain value.
26
	 *
27
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
28
	 *
29
	 * @param string $languageCode
30
	 * @param string $value
31
	 */
32
	public function setLabel( $languageCode, $value ) {
33
		$this->getFingerprint()->setLabel( $languageCode, $value );
34
	}
35
36
	/**
37
	 * Sets the value for the description in a certain value.
38
	 *
39
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
40
	 *
41
	 * @param string $languageCode
42
	 * @param string $value
43
	 */
44
	public function setDescription( $languageCode, $value ) {
45
		$this->getFingerprint()->setDescription( $languageCode, $value );
46
	}
47
48
	/**
49
	 * Removes the labels in the specified languages.
50
	 *
51
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
52
	 *
53
	 * @param string $languageCode
54
	 */
55
	public function removeLabel( $languageCode ) {
56
		$this->getFingerprint()->removeLabel( $languageCode );
57
	}
58
59
	/**
60
	 * Removes the descriptions in the specified languages.
61
	 *
62
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
63
	 *
64
	 * @param string $languageCode
65
	 */
66
	public function removeDescription( $languageCode ) {
67
		$this->getFingerprint()->removeDescription( $languageCode );
68
	}
69
70
	/**
71
	 * Returns the aliases for the item in the language with the specified code.
72
	 *
73
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
74
	 *
75
	 * @param string $languageCode
76
	 *
77
	 * @return string[]
78
	 */
79
	public function getAliases( $languageCode ) {
80
		$aliases = $this->getFingerprint()->getAliasGroups();
81
82
		if ( $aliases->hasGroupForLanguage( $languageCode ) ) {
83
			return $aliases->getByLanguage( $languageCode )->getAliases();
84
		}
85
86
		return array();
87
	}
88
89
	/**
90
	 * Returns all the aliases for the item.
91
	 * The result is an array with language codes pointing to an array of aliases in the language they specify.
92
	 *
93
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
94
	 *
95
	 * @param string[]|null $languageCodes
96
	 *
97
	 * @return array[]
98
	 */
99
	public function getAllAliases( array $languageCodes = null ) {
100
		$aliases = $this->getFingerprint()->getAliasGroups();
101
102
		$textLists = array();
103
104
		/**
105
		 * @var AliasGroup $aliasGroup
106
		 */
107
		foreach ( $aliases as $languageCode => $aliasGroup ) {
108
			if ( $languageCodes === null || in_array( $languageCode, $languageCodes ) ) {
109
				$textLists[$languageCode] = $aliasGroup->getAliases();
110
			}
111
		}
112
113
		return $textLists;
114
	}
115
116
	/**
117
	 * Sets the aliases for the item in the language with the specified code.
118
	 *
119
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
120
	 *
121
	 * @param string $languageCode
122
	 * @param string[] $aliases
123
	 */
124
	public function setAliases( $languageCode, array $aliases ) {
125
		$this->getFingerprint()->setAliasGroup( $languageCode, $aliases );
126
	}
127
128
	/**
129
	 * Add the provided aliases to the aliases list of the item in the language with the specified code.
130
	 *
131
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
132
	 *
133
	 * @param string $languageCode
134
	 * @param string[] $aliases
135
	 */
136
	public function addAliases( $languageCode, array $aliases ) {
137
		$this->setAliases(
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
138
			$languageCode,
139
			array_merge(
140
				$this->getAliases( $languageCode ),
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
141
				$aliases
142
			)
143
		);
144
	}
145
146
	/**
147
	 * Removed the provided aliases from the aliases list of the item in the language with the specified code.
148
	 *
149
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
150
	 *
151
	 * @param string $languageCode
152
	 * @param string[] $aliases
153
	 */
154
	public function removeAliases( $languageCode, array $aliases ) {
155
		$this->setAliases(
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
156
			$languageCode,
157
			array_diff(
158
				$this->getAliases( $languageCode ),
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::getAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
159
				$aliases
160
			)
161
		);
162
	}
163
164
	/**
165
	 * Returns the description of the entity in the language with the provided code,
166
	 * or false in cases there is none in this language.
167
	 *
168
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
169
	 *
170
	 * @param string $languageCode
171
	 *
172
	 * @return string|bool
173
	 */
174
	public function getDescription( $languageCode ) {
175
		if ( !$this->getFingerprint()->hasDescription( $languageCode ) ) {
176
			return false;
177
		}
178
179
		return $this->getFingerprint()->getDescription( $languageCode )->getText();
180
	}
181
182
	/**
183
	 * Returns the label of the entity in the language with the provided code,
184
	 * or false in cases there is none in this language.
185
	 *
186
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
187
	 *
188
	 * @param string $languageCode
189
	 *
190
	 * @return string|bool
191
	 */
192
	public function getLabel( $languageCode ) {
193
		if ( !$this->getFingerprint()->hasLabel( $languageCode ) ) {
194
			return false;
195
		}
196
197
		return $this->getFingerprint()->getLabel( $languageCode )->getText();
198
	}
199
200
	/**
201
	 * Replaces the currently set aliases with the provided ones.
202
	 * The aliases are provided as an associative array where the keys are
203
	 * language codes pointing to an array value that holds the aliases
204
	 * in that language.
205
	 *
206
	 * @since 0.4
207
	 * @deprecated since 0.7.3 - use getFingerprint and setFingerprint
208
	 *
209
	 * @param array[] $aliasLists
210
	 */
211
	public function setAllAliases( array $aliasLists ) {
212
		$this->getFingerprint()->setAliasGroups( new AliasGroupList() );
213
214
		foreach ( $aliasLists as $languageCode => $aliasList ) {
215
			$this->setAliases( $languageCode, $aliasList );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\DataModel\Entity\Entity::setAliases() has been deprecated with message: since 0.7.3 - use getFingerprint and setFingerprint

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
216
		}
217
	}
218
219
	/**
220
	 * Returns a deep copy of the entity.
221
	 *
222
	 * @since 0.1
223
	 *
224
	 * @return self
225
	 */
226
	public function copy() {
227
		return unserialize( serialize( $this ) );
228
	}
229
230
	/**
231
	 * @since 0.3
232
	 * @deprecated since 1.0, use getStatements()->toArray() instead.
233
	 *
234
	 * @return Statement[]
235
	 */
236
	public function getClaims() {
237
		return array();
238
	}
239
240
	/**
241
	 * Removes all content from the Entity.
242
	 * The id is not part of the content.
243
	 *
244
	 * @since 0.1
245
	 * @deprecated since 1.0
246
	 */
247
	public abstract function clear();
248
249
}
250