1 | <?php |
||
36 | class SpecialCrossCheck extends SpecialPage { |
||
37 | |||
38 | /** |
||
39 | * @var EntityIdParser |
||
40 | */ |
||
41 | private $entityIdParser; |
||
42 | |||
43 | /** |
||
44 | * @var EntityLookup |
||
45 | */ |
||
46 | private $entityLookup; |
||
47 | |||
48 | /** |
||
49 | * @var ValueFormatter |
||
50 | */ |
||
51 | private $dataValueFormatter; |
||
52 | |||
53 | /** |
||
54 | * @var EntityIdFormatter |
||
55 | */ |
||
56 | private $entityIdLabelFormatter; |
||
57 | |||
58 | /** |
||
59 | * @var EntityIdFormatter |
||
60 | */ |
||
61 | private $entityIdLinkFormatter; |
||
62 | |||
63 | /** |
||
64 | * @var CrossCheckInteractor |
||
65 | */ |
||
66 | private $crossCheckInteractor; |
||
67 | |||
68 | /** |
||
69 | * Creates new instance from global state. |
||
70 | * @return self |
||
71 | */ |
||
72 | public static function newFromGlobalState() { |
||
73 | $repo = WikibaseRepo::getDefaultInstance(); |
||
74 | $externalValidationServices = ExternalValidationServices::getDefaultInstance(); |
||
75 | |||
76 | return new self( |
||
77 | $repo->getEntityLookup(), |
||
78 | $repo->getTermLookup(), |
||
79 | new EntityIdLabelFormatterFactory(), |
||
80 | $repo->getEntityIdHtmlLinkFormatterFactory(), |
||
81 | $repo->getEntityIdParser(), |
||
82 | $repo->getValueFormatterFactory(), |
||
83 | $externalValidationServices->getCrossCheckInteractor() |
||
84 | ); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param EntityLookup $entityLookup |
||
89 | * @param TermLookup $termLookup |
||
90 | * @param EntityIdLabelFormatterFactory $entityIdLabelFormatterFactory |
||
91 | * @param EntityIdHtmlLinkFormatterFactory $entityIdHtmlLinkFormatterFactory |
||
92 | * @param EntityIdParser $entityIdParser |
||
93 | * @param OutputFormatValueFormatterFactory $valueFormatterFactory |
||
94 | * @param CrossCheckInteractor $crossCheckInteractor |
||
95 | */ |
||
96 | public function __construct( |
||
97 | EntityLookup $entityLookup, |
||
98 | TermLookup $termLookup, |
||
99 | EntityIdLabelFormatterFactory $entityIdLabelFormatterFactory, |
||
100 | EntityIdHtmlLinkFormatterFactory $entityIdHtmlLinkFormatterFactory, |
||
101 | EntityIdParser $entityIdParser, |
||
102 | OutputFormatValueFormatterFactory $valueFormatterFactory, |
||
103 | CrossCheckInteractor $crossCheckInteractor |
||
104 | ) { |
||
105 | parent::__construct( 'CrossCheck' ); |
||
106 | |||
107 | $this->entityLookup = $entityLookup; |
||
108 | $this->entityIdParser = $entityIdParser; |
||
109 | |||
110 | $formatterOptions = new FormatterOptions(); |
||
111 | $formatterOptions->setOption( SnakFormatter::OPT_LANG, $this->getLanguage()->getCode() ); |
||
112 | $this->dataValueFormatter = $valueFormatterFactory->getValueFormatter( SnakFormatter::FORMAT_HTML, $formatterOptions ); |
||
113 | |||
114 | $labelLookup = new LanguageLabelDescriptionLookup( $termLookup, $this->getLanguage()->getCode() ); |
||
115 | $this->entityIdLabelFormatter = $entityIdLabelFormatterFactory->getEntityIdFormatter( $labelLookup ); |
||
116 | $this->entityIdLinkFormatter = $entityIdHtmlLinkFormatterFactory->getEntityIdFormatter( $labelLookup ); |
||
117 | |||
118 | $this->crossCheckInteractor = $crossCheckInteractor; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @see SpecialPage::getGroupName |
||
123 | * |
||
124 | * @return string |
||
125 | */ |
||
126 | public function getGroupName() { |
||
129 | |||
130 | /** |
||
131 | * @see SpecialPage::getDescription |
||
132 | * |
||
133 | * @return string (plain text) |
||
134 | */ |
||
135 | public function getDescription() { |
||
138 | |||
139 | /** |
||
140 | * @see SpecialPage::execute |
||
141 | * |
||
142 | * @param string|null $subPage |
||
143 | * |
||
144 | * @throws InvalidArgumentException |
||
145 | * @throws EntityIdParsingException |
||
146 | * @throws UnexpectedValueException |
||
147 | */ |
||
148 | public function execute( $subPage ) { |
||
167 | |||
168 | /** |
||
169 | * @param string $idSerialization |
||
170 | */ |
||
171 | private function buildResult( $idSerialization ) { |
||
200 | |||
201 | /** |
||
202 | * @param EntityDocument $entity |
||
203 | * |
||
204 | * @return CrossCheckResultList|null |
||
205 | */ |
||
206 | private function getCrossCheckResultsFromEntity( EntityDocument $entity ) { |
||
213 | |||
214 | /** |
||
215 | * Builds html form for entity id input |
||
216 | */ |
||
217 | private function buildEntityIdForm() { |
||
236 | |||
237 | /** |
||
238 | * Builds infobox with explanation for this special page |
||
239 | * |
||
240 | * @return string HTML |
||
241 | */ |
||
242 | private function buildInfoBox() { |
||
258 | |||
259 | /** |
||
260 | * Builds notice with given message. Optionally notice can be handles as error by settings $error to true |
||
261 | * |
||
262 | * @param string $messageKey |
||
263 | * @param bool $error |
||
264 | * |
||
265 | * @throws InvalidArgumentException |
||
266 | * |
||
267 | * @return string HTML |
||
268 | */ |
||
269 | private function buildNotice( $messageKey, $error = false ) { |
||
282 | |||
283 | /** |
||
284 | * Returns html text of the result header |
||
285 | * |
||
286 | * @param EntityId $entityId |
||
287 | * |
||
288 | * @return string HTML |
||
289 | */ |
||
290 | private function buildResultHeader( EntityId $entityId ) { |
||
304 | |||
305 | /** |
||
306 | * Builds summary from given results |
||
307 | * |
||
308 | * @param CrossCheckResult[] $results |
||
309 | * |
||
310 | * @return string HTML |
||
311 | */ |
||
312 | private function buildSummary( $results ) { |
||
336 | |||
337 | /** |
||
338 | * Formats given status to html |
||
339 | * |
||
340 | * @param string $status (plain text) |
||
341 | * |
||
342 | * @throws InvalidArgumentException |
||
343 | * |
||
344 | * @return string HTML |
||
345 | */ |
||
346 | private function formatStatus( $status ) { |
||
360 | |||
361 | /** |
||
362 | * Parses data values to human-readable string |
||
363 | * |
||
364 | * @param DataValue|array $dataValues |
||
365 | * @param bool $linking |
||
366 | * @param string $separator HTML |
||
367 | * |
||
368 | * @throws InvalidArgumentException |
||
369 | * |
||
370 | * @return string HTML |
||
371 | */ |
||
372 | private function formatDataValues( $dataValues, $linking = true, $separator = null ) { |
||
396 | |||
397 | /** |
||
398 | * @param CrossCheckResult[] $results |
||
399 | * |
||
400 | * @return string HTML |
||
401 | */ |
||
402 | private function buildResultTable( $results ) { |
||
463 | |||
464 | } |
||
465 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: