+ if ( $this->fld_roles ) {
+ $vals['roles'] = $revision->getSlotRoles();
+ }
+
+ if ( $this->needSlots ) {
+ $revDel = $this->checkRevDel( $revision, RevisionRecord::DELETED_TEXT );
+ if ( ( $this->fld_slotsha1 || $this->fetchContent ) && ( $revDel & self::IS_DELETED ) ) {
+ $anyHidden = true;
+ }
+ if ( $this->slotRoles === null ) {
+ try {
+ $slot = $revision->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
+ } catch ( RevisionAccessException $e ) {
+ // Back compat: If there's no slot, there's no content, so set 'textmissing'
+ // @todo: Gergő says to mention T198099 as a "todo" here.
+ $vals['textmissing'] = true;
+ $slot = null;
+ }
+
+ if ( $slot ) {
+ $content = null;
+ $vals += $this->extractSlotInfo( $slot, $revDel, $content );
+ if ( !empty( $vals['nosuchsection'] ) ) {
+ $this->dieWithError(
+ [
+ 'apierror-nosuchsection-what',
+ wfEscapeWikiText( $this->section ),
+ $this->msg( 'revid', $revision->getId() )
+ ],
+ 'nosuchsection'
+ );
+ }
+ if ( $content ) {
+ $vals += $this->extractDeprecatedContent( $content, $revision );
+ }
+ }
+ } else {
+ $roles = array_intersect( $this->slotRoles, $revision->getSlotRoles() );
+ $vals['slots'] = [
+ ApiResult::META_KVP_MERGE => true,
+ ];
+ foreach ( $roles as $role ) {
+ try {
+ $slot = $revision->getSlot( $role, RevisionRecord::RAW );
+ } catch ( RevisionAccessException $e ) {
+ // Don't error out here so the client can still process other slots/revisions.
+ // @todo: Gergő says to mention T198099 as a "todo" here.
+ $vals['slots'][$role]['missing'] = true;
+ continue;
+ }
+ $content = null;
+ $vals['slots'][$role] = $this->extractSlotInfo( $slot, $revDel, $content );
+ // @todo Move this into extractSlotInfo() (and remove its $content parameter)
+ // when extractDeprecatedContent() is no more.
+ if ( $content ) {
+ $vals['slots'][$role]['contentmodel'] = $content->getModel();
+ $vals['slots'][$role]['contentformat'] = $content->getDefaultFormat();
+ ApiResult::setContentValue( $vals['slots'][$role], 'content', $content->serialize() );
+ }
+ }
+ ApiResult::setArrayType( $vals['slots'], 'kvp', 'role' );
+ ApiResult::setIndexedTagName( $vals['slots'], 'slot' );
+ }