Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
87.50% covered (warning)
87.50%
14 / 16
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
PoolWorkArticleView
93.33% covered (success)
93.33%
14 / 15
75.00% covered (warning)
75.00%
3 / 4
4.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 doWork
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 renderRevision
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 error
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21namespace MediaWiki\PoolCounter;
22
23use MediaWiki\Logger\Spi as LoggerSpi;
24use MediaWiki\Page\ParserOutputAccess;
25use MediaWiki\Revision\RevisionRecord;
26use MediaWiki\Revision\RevisionRenderer;
27use MediaWiki\Status\Status;
28use ParserOptions;
29
30/**
31 * PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
32 * Caching behavior may be defined by subclasses.
33 *
34 * @note No audience checks are applied.
35 *
36 * @internal
37 */
38class PoolWorkArticleView extends PoolCounterWork {
39    /** @var ParserOptions */
40    protected $parserOptions;
41    /** @var RevisionRecord */
42    protected $revision;
43    /** @var RevisionRenderer */
44    private $renderer;
45    /** @var LoggerSpi */
46    protected $loggerSpi;
47
48    /**
49     * @param string $workKey
50     * @param RevisionRecord $revision Revision to render
51     * @param ParserOptions $parserOptions ParserOptions to use for the parse
52     * @param RevisionRenderer $revisionRenderer
53     * @param LoggerSpi $loggerSpi
54     */
55    public function __construct(
56        string $workKey,
57        RevisionRecord $revision,
58        ParserOptions $parserOptions,
59        RevisionRenderer $revisionRenderer,
60        LoggerSpi $loggerSpi
61    ) {
62        parent::__construct( 'ArticleView', $workKey );
63        $this->revision = $revision;
64        $this->parserOptions = $parserOptions;
65        $this->renderer = $revisionRenderer;
66        $this->loggerSpi = $loggerSpi;
67    }
68
69    /**
70     * @return Status
71     */
72    public function doWork() {
73        return $this->renderRevision();
74    }
75
76    /**
77     * Render the given revision.
78     *
79     * @see ParserOutputAccess::renderRevision
80     *
81     * @return Status with the value being a ParserOutput or null
82     */
83    public function renderRevision(): Status {
84        $renderedRevision = $this->renderer->getRenderedRevision(
85            $this->revision,
86            $this->parserOptions,
87            null,
88            [ 'audience' => RevisionRecord::RAW ]
89        );
90
91        $parserOutput = $renderedRevision->getRevisionParserOutput();
92
93        return Status::newGood( $parserOutput );
94    }
95
96    /**
97     * @param Status $status
98     * @return Status
99     */
100    public function error( $status ) {
101        return $status;
102    }
103
104}
105
106/** @deprecated class alias since 1.41 */
107class_alias( PoolWorkArticleView::class, 'PoolWorkArticleView' );