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