36use Wikimedia\Parsoid\Core\ClientError;
37use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
77 $this->parsoidParserFactory = $parsoidParserFactory;
78 $this->parserOutputAccess = $parserOutputAccess;
79 $this->pageLookup = $pageLookup;
80 $this->revisionLookup = $revisionLookup;
81 $this->siteConfig = $siteConfig;
82 $this->contentHandlerFactory = $contentHandlerFactory;
100 bool $lenientRevHandling =
false
103 [ $page, $revision, $uncacheable ] = $this->resolveRevision( $page, $revision, $lenientRevHandling );
106 if ( $uncacheable ) {
107 $options |= ParserOutputAccess::OPT_NO_UPDATE_CACHE;
110 $this->adjustParserOptions( $revision, $parserOpts );
111 $status = $this->parserOutputAccess->getParserOutput(
112 $page, $parserOpts, $revision, $options
114 }
catch ( ClientError $e ) {
115 $status = Status::newFatal(
'parsoid-client-error', $e->getMessage() );
116 }
catch ( ResourceLimitExceededException $e ) {
117 $status = Status::newFatal(
'parsoid-resource-limit-exceeded', $e->getMessage() );
135 bool $lenientRevHandling =
false
138 [ $page, $revision, $ignored ] = $this->resolveRevision( $page, $revision, $lenientRevHandling );
140 $this->adjustParserOptions( $revision, $parserOpts );
141 return $this->parserOutputAccess->getCachedParserOutput( $page, $parserOpts, $revision );
160 bool $lenientRevHandling =
false
166 [ $page, $revision, $ignored ] = $this->resolveRevision( $page, $revision, $lenientRevHandling );
170 $revId = $revision->getId();
171 if ( $revId !== 0 && $revId !==
null ) {
172 return Status::newFatal(
'parsoid-revision-access',
173 "parseUncacheable should not be called for a real revision" );
179 $parser = $this->parsoidParserFactory->create();
180 $parserOutput = $this->parsoidParserFactory->create()->parseFakeRevision(
181 $revision, $page, $parserOpts );
182 $parserOutput->updateCacheExpiry( 0 );
184 $globalIdGenerator = MediaWikiServices::getInstance()->getGlobalIdGenerator();
185 $parserOutput->setRenderId( $globalIdGenerator->newUUIDv1() );
186 $parserOutput->setCacheRevisionId( $revision->getId() );
187 $parserOutput->setRevisionTimestamp( $revision->getTimestamp() );
190 $status = Status::newGood( $parserOutput );
191 }
catch ( RevisionAccessException $e ) {
192 return Status::newFatal(
'parsoid-revision-access', $e->getMessage() );
193 }
catch ( ClientError $e ) {
194 $status = Status::newFatal(
'parsoid-client-error', $e->getMessage() );
195 }
catch ( ResourceLimitExceededException $e ) {
196 $status = Status::newFatal(
'parsoid-resource-limit-exceeded', $e->getMessage() );
208 private function resolveRevision( PageIdentity $page, $revision,
bool $lenientRevHandling =
false ): array {
209 $uncacheable = false;
210 if ( !$page instanceof PageRecord ) {
212 $page = $this->pageLookup->getPageByReference( $page );
214 throw new RevisionAccessException(
215 'Page {name} not found',
221 $revision ??= $page->getLatest();
223 if ( is_int( $revision ) ) {
225 $revision = $this->revisionLookup->getRevisionById( $revId );
228 throw new RevisionAccessException(
229 'Revision {revId} not found',
230 [
'revId' => $revId ]
235 if ( $page->getId() !== $revision->getPageId() ) {
236 if ( $lenientRevHandling ) {
237 $page = $this->pageLookup->getPageById( $revision->getPageId() );
240 throw new \RuntimeException(
241 "Unexpected NULL page for pageid " . $revision->getPageId() .
242 " from revision " . $revision->getId()
248 throw new RevisionAccessException(
249 'Revision {revId} does not belong to page {name}',
250 [
'name' => $page->getDBkey(),
'revId' => $revision->getId() ]
255 return [ $page, $revision, $uncacheable ];
258 private function adjustParserOptions( RevisionRecord $revision,
ParserOptions $parserOpts ): void {
259 $mainSlot = $revision->getSlot( SlotRecord::MAIN );
260 $contentModel = $mainSlot->getModel();
261 if ( $this->siteConfig->supportsContentModel( $contentModel ) ) {
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Service for getting rendered output of a given page.
Set options of the Parser.
setUseParsoid()
Request Parsoid-format HTML output.
Interface for objects (potentially) representing an editable wiki page.
Service for looking up information about wiki pages.