Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MediaInfoByLinkedTitleLookup | |
0.00% |
0 / 14 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getEntityIdForLinkedTitle | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace Wikibase\MediaInfo\Services; |
4 | |
5 | use MediaWiki\Title\Title; |
6 | use Wikibase\DataModel\Entity\EntityId; |
7 | use Wikibase\Lib\Store\EntityByLinkedTitleLookup; |
8 | use Wikibase\MediaInfo\DataModel\MediaInfo; |
9 | use Wikibase\Repo\WikibaseRepo; |
10 | |
11 | /** |
12 | * Lookup class for getting the MediaInfoId that corresponds to a file page. |
13 | * |
14 | * @license GPL-2.0-or-later |
15 | * @author Mark Holmquist |
16 | */ |
17 | class MediaInfoByLinkedTitleLookup implements EntityByLinkedTitleLookup { |
18 | /** |
19 | * @var EntityByLinkedTitleLookup |
20 | */ |
21 | private $defaultLookup; |
22 | |
23 | /** |
24 | * @param EntityByLinkedTitleLookup $defaultLookup |
25 | */ |
26 | public function __construct( EntityByLinkedTitleLookup $defaultLookup ) { |
27 | $this->defaultLookup = $defaultLookup; |
28 | } |
29 | |
30 | /** |
31 | * Fetch the entity ID for the file page. |
32 | * |
33 | * @param string $globalSiteId |
34 | * @param string $pageTitle |
35 | * |
36 | * @return EntityId|null |
37 | */ |
38 | public function getEntityIdForLinkedTitle( $globalSiteId, $pageTitle ) { |
39 | // Ignore site, assume title is local... |
40 | $title = Title::newFromText( $pageTitle ); |
41 | if ( !$title ) { |
42 | return null; |
43 | } |
44 | |
45 | if ( !$title->inNamespace( NS_FILE ) ) { |
46 | return $this->defaultLookup->getEntityIdForLinkedTitle( $globalSiteId, $pageTitle ); |
47 | } |
48 | |
49 | $pageId = $title->getArticleID(); |
50 | |
51 | if ( !$pageId ) { |
52 | return null; |
53 | } |
54 | |
55 | $entityId = WikibaseRepo::getEntityIdComposer()->composeEntityId( |
56 | MediaInfo::ENTITY_TYPE, |
57 | $pageId |
58 | ); |
59 | |
60 | return $entityId; |
61 | } |
62 | |
63 | } |