32use Wikimedia\Parsoid\Config\Api\PageConfig as ApiPageConfig;
43 private $revisionStore;
46 private $slotRoleRegistry;
56 $this->revisionStore = $revisionStore;
57 $this->slotRoleRegistry = $slotRoleRegistry;
81 ?
string $unused =
null,
82 ?
string $pagelanguageOverride =
null,
83 ?array $parsoidSettings =
null
86 '@phan-var Title $title';
88 if ( !empty( $parsoidSettings[
'debugApi'] ) ) {
89 if ( $revision ===
null ) {
90 throw new \InvalidArgumentException(
91 "Revision not provided. Cannot lookup revision via debug API." );
94 $content = $revision->getContent( SlotRecord::MAIN );
97 return ApiPageConfig::fromSettings( $parsoidSettings, [
98 "title" =>
$title->getPrefixedText(),
99 "pageContent" => $wtContent,
100 "pageLanguage" => $pagelanguageOverride,
101 "revid" => $revision->getId(),
105 throw new \UnexpectedValueException(
106 "Non-wikitext content models not supported by debug API" );
110 if ( $revision ===
null ) {
118 $revisionRecord = $this->revisionStore->getKnownCurrentRevision(
123 } elseif ( !is_int( $revision ) ) {
124 $revisionRecord = $revision;
129 $revisionRecord = $this->revisionStore->getRevisionById( $revision );
130 if ( $revisionRecord ===
null ) {
135 $revisionRecord = $this->revisionStore->getRevisionById(
136 $revision, RevisionStore::READ_LATEST
138 $success = ( $revisionRecord !== null ) ?
'success' :
'failure';
139 LoggerFactory::getInstance(
'Parsoid' )->error(
140 "Retried revision fetch after failure: {$success}", [
142 'title' =>
$title->getPrefixedText(),
146 if ( $revisionRecord ===
null ) {
147 throw new RevisionAccessException(
"Can't find revision {$revision}" );
154 $revisionRecord !==
null &&
155 !$revisionRecord->audienceCan(
156 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_PUBLIC
159 throw new RevisionAccessException(
'Not an available content version.' );
170 $parserOptions->
setOption(
'enableLimitReport',
false );
172 $slotRoleHandler = $this->slotRoleRegistry->getRoleHandler( SlotRecord::MAIN );
173 return new PageConfig(
178 $pagelanguageOverride
Helper class used by MediaWiki to create Parsoid PageConfig objects.
create(PageIdentity $pageId, ?UserIdentity $user=null, $revision=null, ?string $unused=null, ?string $pagelanguageOverride=null, ?array $parsoidSettings=null)
Create a new PageConfig.
__construct(RevisionStore $revisionStore, SlotRoleRegistry $slotRoleRegistry)
Page-level configuration interface for Parsoid.
Set options of the Parser.
setOption( $name, $value)
Set an option, generically.
static newFromUser( $user)
Get a ParserOptions object from a given user.
Represents a title within MediaWiki.
Content object for wiki text pages.
Interface for configuration instances.
Interface for objects (potentially) representing an editable wiki page.