| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Linter; |
| 22 |
|
| 23 |
use MediaWiki\Content\TextContent; |
| 24 |
use MediaWiki\Deferred\DataUpdate; |
| 25 |
use MediaWiki\Logger\LoggerFactory; |
| 26 |
use MediaWiki\Page\ParserOutputAccess; |
| 27 |
use MediaWiki\Page\WikiPageFactory; |
| 28 |
use MediaWiki\Revision\RenderedRevision; |
| 29 |
use MediaWiki\Revision\RevisionRecord; |
| 30 |
use MediaWiki\Revision\SlotRecord; |
| 31 |
|
| 32 |
class LintUpdate extends DataUpdate { |
| 33 |
|
| 34 |
private WikiPageFactory $wikiPageFactory; |
| 35 |
private ParserOutputAccess $parserOutputAccess; |
| 36 |
private RenderedRevision $renderedRevision; |
| 37 |
|
| 38 |
public function __construct( |
| 39 |
WikiPageFactory $wikiPageFactory, |
| 40 |
ParserOutputAccess $parserOutputAccess, |
| 41 |
RenderedRevision $renderedRevision |
| 42 |
) { |
| 43 |
parent::__construct(); |
| 44 |
$this->wikiPageFactory = $wikiPageFactory; |
| 45 |
$this->parserOutputAccess = $parserOutputAccess; |
| 46 |
$this->renderedRevision = $renderedRevision; |
| 47 |
} |
| 48 |
|
| 49 |
public function doUpdate() { |
| 50 |
$rev = $this->renderedRevision->getRevision(); |
| 51 |
$mainSlot = $rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW ); |
| 52 |
|
| 53 |
$page = $this->wikiPageFactory->newFromTitle( $rev->getPage() ); |
| 54 |
|
| 55 |
if ( $page->getLatest() !== $rev->getId() ) { |
| 56 |
|
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
$content = $mainSlot->getContent(); |
| 61 |
if ( !$content instanceof TextContent ) { |
| 62 |
|
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
$pOptions = $page->makeParserOptions( 'canonical' ); |
| 67 |
$pOptions->setUseParsoid(); |
| 68 |
$pOptions->setRenderReason( 'LintUpdate' ); |
| 69 |
|
| 70 |
LoggerFactory::getInstance( 'Linter' )->debug( |
| 71 |
'{method}: Parsing {page}', |
| 72 |
[ |
| 73 |
'method' => __METHOD__, |
| 74 |
'page' => $page->getTitle()->getPrefixedDBkey(), |
| 75 |
'touched' => $page->getTouched() |
| 76 |
] |
| 77 |
); |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
$this->parserOutputAccess->getParserOutput( |
| 87 |
$page, $pOptions, $rev, |
| 88 |
ParserOutputAccess::OPT_NO_UPDATE_CACHE |
| 89 |
); |
| 90 |
} |
| 91 |
} |