Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
FlaggedRevsParserCache | |
0.00% |
0 / 10 |
|
0.00% |
0 / 5 |
42 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
get | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDirty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
save | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
makeKey | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 |
1 | <?php |
2 | |
3 | use MediaWiki\Page\PageRecord; |
4 | use MediaWiki\Parser\ParserCache; |
5 | use MediaWiki\Parser\ParserOptions; |
6 | use MediaWiki\Parser\ParserOutput; |
7 | |
8 | /** |
9 | * Encapsulate FlaggedRevs's ParserCache |
10 | */ |
11 | class FlaggedRevsParserCache { |
12 | |
13 | /** @var ParserCache */ |
14 | private $stableParserCache; |
15 | |
16 | /** |
17 | * Instantiate this class using one of: |
18 | * * $services->getService( 'FlaggedRevsParserCache' ) |
19 | * * $services->getService( 'FlaggedRevsParsoidParserCache' ) |
20 | * |
21 | * @param ParserCache $stableParserCache |
22 | */ |
23 | public function __construct( ParserCache $stableParserCache ) { |
24 | $this->stableParserCache = $stableParserCache; |
25 | } |
26 | |
27 | /** |
28 | * Fetch from the cache. |
29 | * |
30 | * @param PageRecord $page Identifies the page to fetch. |
31 | * @param ParserOptions $parserOptions Encodes the audience, language, etc. |
32 | * @return ParserOutput|false |
33 | */ |
34 | public function get( PageRecord $page, ParserOptions $parserOptions ) { |
35 | return $this->stableParserCache->get( $page, $parserOptions ); |
36 | } |
37 | |
38 | /** |
39 | * Fetch from the cache, allowing stale content. |
40 | * |
41 | * @param PageRecord $page Identifies the page to fetch. |
42 | * @param ParserOptions $parserOptions Encodes the audience, language, etc. |
43 | * @return ParserOutput|false |
44 | */ |
45 | public function getDirty( PageRecord $page, ParserOptions $parserOptions ) { |
46 | return $this->stableParserCache->getDirty( $page, $parserOptions ); |
47 | } |
48 | |
49 | /** |
50 | * Store to the cache. |
51 | * |
52 | * @param ParserOutput $output Parsed content to store. |
53 | * @param PageRecord $page Identifies the page that was parsed. |
54 | * @param ParserOptions $parserOptions Encodes the audience, language, etc. |
55 | */ |
56 | public function save( ParserOutput $output, PageRecord $page, |
57 | ParserOptions $parserOptions |
58 | ): void { |
59 | $this->stableParserCache->save( $output, $page, $parserOptions ); |
60 | } |
61 | |
62 | /** |
63 | * Return a key that will be unique to this page and the requested parser options. |
64 | * |
65 | * @param PageRecord $page Identifies the page that was parsed. |
66 | * @param ParserOptions $parserOptions Encodes the audience, language, etc. |
67 | * @return string |
68 | */ |
69 | public function makeKey( PageRecord $page, ParserOptions $parserOptions ): string { |
70 | $parserCacheMetadata = $this->stableParserCache->getMetadata( $page ); |
71 | return $this->stableParserCache->makeParserOutputKey( |
72 | $page, |
73 | $parserOptions, |
74 | $parserCacheMetadata ? $parserCacheMetadata->getUsedOptions() : null |
75 | ); |
76 | } |
77 | } |