MediaWiki master
PoolWorkArticleView.php
Go to the documentation of this file.
1<?php
21namespace MediaWiki\PoolCounter;
22
23use MediaWiki\Logger\Spi as LoggerSpi;
33
44 protected $parserOptions;
46 protected $revision;
48 private $renderer;
50 protected $loggerSpi;
51
59 public function __construct(
60 string $workKey,
63 RevisionRenderer $revisionRenderer,
64 LoggerSpi $loggerSpi
65 ) {
66 parent::__construct( 'ArticleView', $workKey );
67 $this->revision = $revision;
68 $this->parserOptions = $parserOptions;
69 $this->renderer = $revisionRenderer;
70 $this->loggerSpi = $loggerSpi;
71 }
72
76 public function doWork() {
77 return $this->renderRevision();
78 }
79
91 public function renderRevision(
92 ?ParserOutput $previousOutput = null,
93 bool $doSample = false,
94 string $sourceLabel = ''
95 ): Status {
96 $renderedRevision = $this->renderer->getRenderedRevision(
97 $this->revision,
98 $this->parserOptions,
99 null,
100 [
101 'audience' => RevisionRecord::RAW,
102 'previous-output' => $previousOutput,
103 ]
104 );
105
106 $parserOutput = $renderedRevision->getRevisionParserOutput();
107
108 if ( $doSample ) {
109 $stats = MediaWikiServices::getInstance()->getStatsFactory();
110 $content = $this->revision->getContent( SlotRecord::MAIN );
111 $labels = [
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',
119 ];
120 $totalStat = $stats->getCounter( 'ParserCache_selective_total' );
121 $timeStat = $stats->getCounter( 'ParserCache_selective_cpu_seconds' );
122 foreach ( $labels as $key => $value ) {
123 $totalStat->setLabel( $key, $value );
124 $timeStat->setLabel( $key, $value );
125 }
126 $totalStat->increment();
127 $timeStat->incrementBy( $parserOutput->getTimeProfile( 'cpu' ) );
128 }
129
130 return Status::newGood( $parserOutput );
131 }
132
137 public function error( $status ) {
138 return $status;
139 }
140
141}
142
144class_alias( PoolWorkArticleView::class, 'PoolWorkArticleView' );
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Service for getting rendered output of a given page.
ParserOutput is a rendering of a Content object or a message.
Class for dealing with PoolCounters using class members.
PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
renderRevision(?ParserOutput $previousOutput=null, bool $doSample=false, string $sourceLabel='')
Render the given revision.
__construct(string $workKey, RevisionRecord $revision, ParserOptions $parserOptions, RevisionRenderer $revisionRenderer, LoggerSpi $loggerSpi)
Page revision base class.
The RevisionRenderer service provides access to rendered output for revisions.
Value object representing a content slot associated with a page revision.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:54
Tools for dealing with other locally-hosted wikis.
Definition WikiMap.php:31
Set options of the Parser.
Service provider interface to create \Psr\Log\LoggerInterface objects.
Definition Spi.php:64