83 $mainSlot = $revRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
84 $modelId = $mainSlot->getModel();
85 $format = $mainSlot->getFormat();
87 if ( $format ===
null ) {
88 $format = MediaWikiServices::getInstance()
89 ->getContentHandlerFactory()
90 ->getContentHandler( $modelId )
109 throw new InvalidArgumentException(
'$revid parameter mismatches $revision parameter' );
114 throw new InvalidArgumentException(
'$page parameter mismatches $revision parameter' );
119 $this->renderer = MediaWikiServices::getInstance()->getRevisionRenderer();
120 $this->revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
121 $this->parserCache = MediaWikiServices::getInstance()->getParserCache();
125 $this->cacheable = $useParserCache;
130 $keyPrefix = $this->cacheKey ?: ObjectCache::getLocalClusterInstance()->makeKey(
131 'articleview',
'missingcachekey'
134 parent::__construct(
'ArticleView', $keyPrefix .
':revid:' .
$revid );
182 $isCurrent = $this->revid === $this->page->getLatest();
187 if ( $this->revision !==
null ) {
189 } elseif ( $isCurrent ) {
190 $rev = $this->page->getRevisionRecord();
192 $rev = $this->revisionStore->getRevisionByTitle( $this->page->getTitle(), $this->revid );
200 $renderedRevision = $this->renderer->getRenderedRevision(
202 $this->parserOptions,
207 if ( !$renderedRevision ) {
215 $time = -microtime(
true );
216 $this->parserOutput = $renderedRevision->getRevisionParserOutput();
217 $time += microtime(
true );
222 $logger = MediaWiki\Logger\LoggerFactory::getInstance(
'slow-parse' );
223 $logger->info(
'{time} {title}', [
224 'time' => number_format( $time, 2 ),
225 'title' => $this->page->getTitle()->getPrefixedDBkey(),
226 'ns' => $this->page->getTitle()->getNamespace(),
231 if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) {
232 $this->parserCache->save(
233 $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid );
239 if ( !$this->parserOutput->isCacheable() ) {
244 $this->page->triggerOpportunisticLinksUpdate( $this->parserOutput );
254 $this->parserOutput = $this->parserCache->get( $this->page, $this->parserOptions );
256 if ( $this->parserOutput ===
false ) {
257 wfDebug( __METHOD__ .
": parser cache miss" );
260 wfDebug( __METHOD__ .
": parser cache hit" );
270 $this->parserOutput = $this->parserCache->getDirty( $this->page, $this->parserOptions );
273 if ( $this->parserOutput && $fast ) {
283 $lastWriteTime = MediaWikiServices::getInstance()->getDBLoadBalancerFactory()
284 ->getChronologyProtectorTouched();
285 $cacheTime = MWTimestamp::convert( TS_UNIX, $this->parserOutput->getCacheTime() );
286 if ( $lastWriteTime && $cacheTime <= $lastWriteTime ) {
287 wfDebugLog(
'dirty',
"declining to send dirty output since cache time " .
288 $cacheTime .
" is before last write time $lastWriteTime" );
292 $this->parserOutput =
false;
295 $this->isFast =
true;
299 if ( $this->parserOutput ===
false ) {
303 wfDebugLog(
'dirty',
"{$fastMsg}dirty output {$this->cacheKey}" );
304 $this->isDirty =
true;
314 $this->
error = $status;
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Set options of the Parser.
Class for dealing with PoolCounters using class members.
RevisionStore $revisionStore
RevisionRenderer $renderer
getError()
Get a Status object in case of error or false otherwise.
ParserOutput bool $parserOutput
ParserOptions $parserOptions
getParserOutput()
Get the ParserOutput from this object, or false in case of failure.
getIsDirty()
Get whether the ParserOutput is a dirty one (i.e.
getIsFastStale()
Get whether the ParserOutput was retrieved in fast stale mode.
RevisionRecord null $revision
__construct(WikiPage $page, ParserOptions $parserOptions, $revid, $useParserCache, $revision=null, $audience=RevisionRecord::FOR_PUBLIC)
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Class representing a MediaWiki article and history.
getTitle()
Get the title object of the article.
getRevisionRecord()
Get the latest revision.
Base interface for content objects.