1 | <?php |
||
23 | class InfoActionHookHandler implements InfoActionHook { |
||
24 | |||
25 | /** |
||
26 | * @var NamespaceChecker |
||
27 | */ |
||
28 | private $namespaceChecker; |
||
29 | |||
30 | /** |
||
31 | * @var RepoLinker |
||
32 | */ |
||
33 | private $repoLinker; |
||
34 | |||
35 | /** |
||
36 | * @var SiteLinkLookup |
||
37 | */ |
||
38 | private $siteLinkLookup; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $siteId; |
||
44 | |||
45 | /** |
||
46 | * @var UsageLookup |
||
47 | */ |
||
48 | private $usageLookup; |
||
49 | |||
50 | /** |
||
51 | * @var LanguageFallbackLabelDescriptionLookupFactory |
||
52 | */ |
||
53 | private $labelDescriptionLookupFactory; |
||
54 | |||
55 | /** |
||
56 | * @var EntityIdParser |
||
57 | */ |
||
58 | private $idParser; |
||
59 | |||
60 | /** |
||
61 | * @var DescriptionLookup |
||
62 | */ |
||
63 | private $descriptionLookup; |
||
64 | |||
65 | public function __construct( |
||
84 | |||
85 | public static function factory(): self { |
||
86 | $wikibaseClient = WikibaseClient::getDefaultInstance(); |
||
87 | $settings = $wikibaseClient->getSettings(); |
||
88 | |||
89 | $namespaceChecker = $wikibaseClient->getNamespaceChecker(); |
||
90 | $usageLookup = $wikibaseClient->getStore()->getUsageLookup(); |
||
91 | $labelDescriptionLookupFactory = new LanguageFallbackLabelDescriptionLookupFactory( |
||
92 | $wikibaseClient->getLanguageFallbackChainFactory(), |
||
93 | $wikibaseClient->getTermLookup(), |
||
94 | $wikibaseClient->getTermBuffer() |
||
95 | ); |
||
96 | $idParser = $wikibaseClient->getEntityIdParser(); |
||
97 | $descriptionLookup = $wikibaseClient->getDescriptionLookup(); |
||
98 | |||
99 | return new self( |
||
100 | $namespaceChecker, |
||
101 | $wikibaseClient->newRepoLinker(), |
||
102 | $wikibaseClient->getStore()->getSiteLinkLookup(), |
||
103 | $settings->getSetting( 'siteGlobalID' ), |
||
104 | $usageLookup, |
||
105 | $labelDescriptionLookupFactory, |
||
106 | $idParser, |
||
107 | $descriptionLookup |
||
108 | ); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Adds the Entity ID of the corresponding Wikidata item in action=info |
||
113 | * |
||
114 | * @param IContextSource $context |
||
115 | * @param array[] &$pageInfo |
||
116 | */ |
||
117 | public function onInfoAction( $context, &$pageInfo ) { |
||
142 | |||
143 | /** |
||
144 | * @param IContextSource $context |
||
145 | * @param Title $title |
||
146 | * |
||
147 | * @return string[] |
||
148 | */ |
||
149 | private function getPageInfoRow( IContextSource $context, Title $title ) { |
||
160 | |||
161 | /** |
||
162 | * @param IContextSource $context |
||
163 | * @param string $description |
||
164 | * @param string $source |
||
165 | * |
||
166 | * @return string[] |
||
167 | */ |
||
168 | private function getDescriptionInfoRow( $context, $description, $source ) { |
||
175 | |||
176 | /** |
||
177 | * Creating a Repo link with Item ID as anchor text |
||
178 | * |
||
179 | * @param IContextSource $context |
||
180 | * @param ItemId $itemId |
||
181 | * |
||
182 | * @return string[] |
||
183 | */ |
||
184 | private function getItemPageInfo( IContextSource $context, ItemId $itemId ) { |
||
195 | |||
196 | /** |
||
197 | * @param IContextSource $context |
||
198 | * |
||
199 | * @return string[] |
||
200 | */ |
||
201 | private function getUnconnectedItemPageInfo( IContextSource $context ) { |
||
207 | |||
208 | /** |
||
209 | * @param string[][] $aspects |
||
210 | * @param IContextSource $context |
||
211 | * @return string |
||
212 | */ |
||
213 | private function formatAspects( array $aspects, IContextSource $context ) { |
||
239 | |||
240 | /** |
||
241 | * @param IContextSource $context |
||
242 | * @param array $usage |
||
243 | * |
||
244 | * @return string[] |
||
245 | */ |
||
246 | private function formatEntityUsage( IContextSource $context, array $usage ) { |
||
286 | |||
287 | } |
||
288 |
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: