Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
DatabaseIndexContentLookup | |
0.00% |
0 / 12 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
isIndexTitleInCache | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getIndexContentForTitle | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 |
1 | <?php |
2 | |
3 | namespace ProofreadPage\Index; |
4 | |
5 | use MediaWiki\MediaWikiServices; |
6 | use MediaWiki\Revision\SlotRecord; |
7 | use MediaWiki\Title\Title; |
8 | |
9 | /** |
10 | * @license GPL-2.0-or-later |
11 | * |
12 | * Allows to retrieve the content of the Index: page |
13 | */ |
14 | class DatabaseIndexContentLookup implements IndexContentLookup { |
15 | |
16 | /** @var IndexContent[] */ |
17 | private $cache = []; |
18 | |
19 | /** |
20 | * @inheritDoc |
21 | */ |
22 | public function isIndexTitleInCache( Title $indexTitle ): bool { |
23 | return array_key_exists( $indexTitle->getDBkey(), $this->cache ); |
24 | } |
25 | |
26 | /** |
27 | * @inheritDoc |
28 | */ |
29 | public function getIndexContentForTitle( Title $indexTitle ) { |
30 | $cacheKey = $indexTitle->getDBkey(); |
31 | |
32 | if ( !array_key_exists( $cacheKey, $this->cache ) ) { |
33 | $revision = MediaWikiServices::getInstance()->getRevisionStore() |
34 | ->getRevisionByTitle( $indexTitle ); |
35 | if ( $revision === null ) { |
36 | $this->cache[$cacheKey] = new IndexContent( [] ); |
37 | } else { |
38 | $content = $revision->getContent( SlotRecord::MAIN ); |
39 | if ( $content instanceof IndexContent ) { |
40 | $this->cache[$cacheKey] = $content; |
41 | } else { |
42 | $this->cache[$cacheKey] = new IndexContent( [] ); |
43 | } |
44 | } |
45 | } |
46 | |
47 | return $this->cache[$cacheKey]; |
48 | } |
49 | } |