Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FlaggedRevsParserCacheFactory | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getParserCache | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types=1 ); |
| 4 | namespace MediaWiki\Extension\FlaggedRevs\Backend; |
| 5 | |
| 6 | use MediaWiki\Config\Config; |
| 7 | use MediaWiki\MainConfigNames; |
| 8 | use MediaWiki\Parser\ParserCache; |
| 9 | use MediaWiki\Parser\ParserCacheFactory; |
| 10 | use MediaWiki\Parser\ParserOptions; |
| 11 | |
| 12 | class FlaggedRevsParserCacheFactory { |
| 13 | /** |
| 14 | * @internal Only for use by ServiceWiring.php or when locating the service, in which case its value |
| 15 | * is stable to use. |
| 16 | */ |
| 17 | public const SERVICE_NAME = 'FlaggedRevsParserCacheFactory'; |
| 18 | /** |
| 19 | * The name of the ParserCache to use for stable revisions caching. |
| 20 | * |
| 21 | * @note This name is used as a part of the ParserCache key, so |
| 22 | * changing it will invalidate the parser cache for stable revisions. |
| 23 | */ |
| 24 | private const STABLE_PARSER_CACHE_NAME = 'stable-pcache'; |
| 25 | private const STABLE_PARSOID_PARSER_CACHE_NAME = 'stable-parsoid-pcache'; |
| 26 | |
| 27 | public function __construct( |
| 28 | private readonly ParserCacheFactory $parserCacheFactory, |
| 29 | private readonly Config $config, |
| 30 | ) { |
| 31 | } |
| 32 | |
| 33 | public function getParserCache( ParserOptions $pOpts ): ParserCache { |
| 34 | $cacheName = $pOpts->getUseParsoid() && |
| 35 | $this->config->get( MainConfigNames::SplitParsoidParserCache ) ? |
| 36 | self::STABLE_PARSOID_PARSER_CACHE_NAME : |
| 37 | self::STABLE_PARSER_CACHE_NAME; |
| 38 | if ( $pOpts->getPostproc() ) { |
| 39 | $cacheName .= '-postproc'; |
| 40 | } |
| 41 | return $this->parserCacheFactory->getParserCache( $cacheName ); |
| 42 | } |
| 43 | } |