| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\PoolCounter; |
| 22 |
|
| 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; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
class PoolWorkArticleView extends PoolCounterWork { |
| 43 |
|
| 44 |
protected $parserOptions; |
| 45 |
|
| 46 |
protected $revision; |
| 47 |
|
| 48 |
private $renderer; |
| 49 |
|
| 50 |
protected $loggerSpi; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
public function __construct( |
| 60 |
string $workKey, |
| 61 |
RevisionRecord $revision, |
| 62 |
ParserOptions $parserOptions, |
| 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 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public function doWork() { |
| 77 |
return $this->renderRevision(); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 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 |
$stats |
| 121 |
->getCounter( 'ParserCache_selective_total' ) |
| 122 |
->setLabels( $labels ) |
| 123 |
->increment(); |
| 124 |
$stats |
| 125 |
->getCounter( 'ParserCache_selective_cpu_seconds' ) |
| 126 |
->setLabels( $labels ) |
| 127 |
->incrementBy( $parserOutput->getTimeProfile( 'cpu' ) ); |
| 128 |
} |
| 129 |
|
| 130 |
return Status::newGood( $parserOutput ); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public function error( $status ) { |
| 138 |
return $status; |
| 139 |
} |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
|
| 144 |
class_alias( PoolWorkArticleView::class, 'PoolWorkArticleView' ); |