2declare( strict_types = 1 );
11use MediaWiki\Languages\LanguageFactory;
23use Wikimedia\Bcp47Code\Bcp47Code;
36 private readonly LanguageFactory $languageFactory,
65 ?
string $unused =
null,
66 ?Bcp47Code $pageLanguageOverride =
null,
67 bool $ensureAccessibleContent =
false
70 if ( $unused !==
null ) {
71 wfDeprecated( __METHOD__ .
' with non-null 4th arg',
'1.40' );
80 $parserOptions, $pageId, $revision,
81 $pageLanguageOverride, $ensureAccessibleContent
109 ?Bcp47Code $pageLanguageOverride =
null,
110 bool $ensureAccessibleContent =
false
112 $title =
Title::newFromPageIdentity( $pageId );
114 if ( $revision ===
null ) {
122 $revisionRecord = $this->revisionStore->getKnownCurrentRevision(
127 } elseif ( !is_int( $revision ) ) {
128 $revisionRecord = $revision;
130 if ( $revision === 0 ) {
136 throw new \UnexpectedValueException(
137 "Got revision ID 0 indicating unsaved content. " .
138 "Unsaved content must be provided as a RevisionRecord object."
145 $revisionRecord = $this->revisionStore->getRevisionById( $revision );
146 if ( $revisionRecord ===
null ) {
151 $revisionRecord = $this->revisionStore->getRevisionById(
152 $revision, IDBAccessObject::READ_LATEST
154 $success = ( $revisionRecord !== null ) ?
'success' :
'failure';
155 LoggerFactory::getInstance(
'Parsoid' )->error(
156 "Retried revision fetch after failure: {$success}", [
158 'title' => $title->getPrefixedText(),
162 if ( $revisionRecord ===
null ) {
163 throw new RevisionAccessException(
"Can't find revision {$revision}" );
170 $revisionRecord !==
null &&
171 !$revisionRecord->audienceCan(
172 RevisionRecord::DELETED_TEXT, RevisionRecord::FOR_PUBLIC
175 throw new SuppressedDataException(
'Not an available content version.' );
181 $slotRoleHandler = $this->slotRoleRegistry->getRoleHandler( SlotRecord::MAIN );
183 if ( $pageLanguageOverride ) {
184 $pageLanguage = $this->languageFactory->getLanguage( $pageLanguageOverride );
187 $pageLanguage = $title->getPageLanguage();
190 $pageConfig =
new PageConfig(
196 $pageLanguage->getDir()
199 if ( $ensureAccessibleContent ) {
200 if ( $revisionRecord ===
null ) {
202 throw new RevisionAccessException(
'The specified revision does not exist.' );
207 $pageConfig->getRevisionContent()->getContent( SlotRecord::MAIN );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Helper class used by MediaWiki to create Parsoid PageConfig objects.
create(PageIdentity $pageId, ?UserIdentity $user=null, $revision=null, ?string $unused=null, ?Bcp47Code $pageLanguageOverride=null, bool $ensureAccessibleContent=false)
Create a new PageConfig.
createFromParserOptions(ParserOptions $parserOptions, PageIdentity $pageId, $revision=null, ?Bcp47Code $pageLanguageOverride=null, bool $ensureAccessibleContent=false)
Create a new PageConfig.
__construct(private readonly RevisionStore $revisionStore, private readonly SlotRoleRegistry $slotRoleRegistry, private readonly LanguageFactory $languageFactory,)
Page-level configuration interface for Parsoid.
Interface for objects (potentially) representing an editable wiki page.