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.
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.
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
21 namespace MediaWiki\PoolCounter
;
23 use MediaWiki\Logger\Spi
as LoggerSpi
;
24 use MediaWiki\MediaWikiServices
;
25 use MediaWiki\Page\ParserOutputAccess
;
26 use MediaWiki\Parser\ParserOptions
;
27 use MediaWiki\Parser\ParserOutput
;
28 use MediaWiki\Revision\RevisionRecord
;
29 use MediaWiki\Revision\RevisionRenderer
;
30 use MediaWiki\Revision\SlotRecord
;
31 use MediaWiki\Status\Status
;
32 use MediaWiki\WikiMap\WikiMap
;
35 * PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
36 * Caching behavior may be defined by subclasses.
38 * @note No audience checks are applied.
42 class PoolWorkArticleView
extends PoolCounterWork
{
43 /** @var ParserOptions */
44 protected $parserOptions;
45 /** @var RevisionRecord */
47 /** @var RevisionRenderer */
53 * @param string $workKey
54 * @param RevisionRecord $revision Revision to render
55 * @param ParserOptions $parserOptions ParserOptions to use for the parse
56 * @param RevisionRenderer $revisionRenderer
57 * @param LoggerSpi $loggerSpi
59 public function __construct(
61 RevisionRecord
$revision,
62 ParserOptions
$parserOptions,
63 RevisionRenderer
$revisionRenderer,
66 parent
::__construct( 'ArticleView', $workKey );
67 $this->revision
= $revision;
68 $this->parserOptions
= $parserOptions;
69 $this->renderer
= $revisionRenderer;
70 $this->loggerSpi
= $loggerSpi;
76 public function doWork() {
77 return $this->renderRevision();
81 * Render the given revision.
83 * @see ParserOutputAccess::renderRevision
85 * @param ?ParserOutput $previousOutput previously-cached output for this
86 * page (used by Parsoid for selective updates)
87 * @param bool $doSample Whether to collect statistics on this render
88 * @param string $sourceLabel the source label to use on the statistics
89 * @return Status with the value being a ParserOutput or null
91 public function renderRevision(
92 ?ParserOutput
$previousOutput = null,
93 bool $doSample = false,
94 string $sourceLabel = ''
96 $renderedRevision = $this->renderer
->getRenderedRevision(
101 'audience' => RevisionRecord
::RAW
,
102 'previous-output' => $previousOutput,
106 $parserOutput = $renderedRevision->getRevisionParserOutput();
109 $stats = MediaWikiServices
::getInstance()->getStatsFactory();
110 $content = $this->revision
->getContent( SlotRecord
::MAIN
);
112 'source' => $sourceLabel,
113 'type' => $previousOutput === null ?
'full' : 'selective',
114 'reason' => $this->parserOptions
->getRenderReason(),
115 'parser' => $this->parserOptions
->getUseParsoid() ?
'parsoid' : 'legacy',
116 'opportunistic' => 'false',
117 'wiki' => WikiMap
::getCurrentWikiId(),
118 'model' => $content ?
$content->getModel() : 'unknown',
121 ->getCounter( 'ParserCache_selective_total' )
122 ->setLabels( $labels )
125 ->getCounter( 'ParserCache_selective_cpu_seconds' )
126 ->setLabels( $labels )
127 ->incrementBy( $parserOutput->getTimeProfile( 'cpu' ) );
130 return Status
::newGood( $parserOutput );
134 * @param Status $status
137 public function error( $status ) {
143 /** @deprecated class alias since 1.42 */
144 class_alias( PoolWorkArticleView
::class, 'PoolWorkArticleView' );