MediaWiki 1.44.0
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 PoolCounter $poolCounter,
63 RevisionRenderer $revisionRenderer,
64 LoggerSpi $loggerSpi
65 ) {
66 parent::__construct(
67 $poolCounter->getType(),
68 $poolCounter->getKey(),
69 $poolCounter
70 );
71 $this->revision = $revision;
72 $this->parserOptions = $parserOptions;
73 $this->renderer = $revisionRenderer;
74 $this->loggerSpi = $loggerSpi;
75 }
76
80 public function doWork() {
81 return $this->renderRevision();
82 }
83
95 public function renderRevision(
96 ?ParserOutput $previousOutput = null,
97 bool $doSample = false,
98 string $sourceLabel = ''
99 ): Status {
100 $renderedRevision = $this->renderer->getRenderedRevision(
101 $this->revision,
102 $this->parserOptions,
103 null,
104 [
105 'audience' => RevisionRecord::RAW,
106 'previous-output' => $previousOutput,
107 ]
108 );
109
110 $parserOutput = $renderedRevision->getRevisionParserOutput();
111
112 if ( $doSample ) {
113 $stats = MediaWikiServices::getInstance()->getStatsFactory();
114 $content = $this->revision->getContent( SlotRecord::MAIN );
115 $labels = [
116 'source' => $sourceLabel,
117 'type' => $previousOutput === null ? 'full' : 'selective',
118 'reason' => $this->parserOptions->getRenderReason(),
119 'parser' => $this->parserOptions->getUseParsoid() ? 'parsoid' : 'legacy',
120 'opportunistic' => 'false',
121 'wiki' => WikiMap::getCurrentWikiId(),
122 'model' => $content ? $content->getModel() : 'unknown',
123 ];
124 $stats
125 ->getCounter( 'ParserCache_selective_total' )
126 ->setLabels( $labels )
127 ->increment();
128 $stats
129 ->getCounter( 'ParserCache_selective_cpu_seconds' )
130 ->setLabels( $labels )
131 ->incrementBy( $parserOutput->getTimeProfile( 'cpu' ) );
132 }
133
134 return Status::newGood( $parserOutput );
135 }
136
141 public function error( $status ) {
142 return $status;
143 }
144
145}
146
148class_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.
Set options of the Parser.
ParserOutput is a rendering of a Content object or a message.
Class for dealing with PoolCounters using class members.
Semaphore semantics to restrict how many workers may concurrently perform a task.
PoolCounter protected work wrapping RenderedRevision->getRevisionParserOutput.
renderRevision(?ParserOutput $previousOutput=null, bool $doSample=false, string $sourceLabel='')
Render the given revision.
__construct(PoolCounter $poolCounter, 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
Service provider interface to create \Psr\Log\LoggerInterface objects.
Definition Spi.php:64