Add constant for the name of the 'main' slot for MCR
authorGergő Tisza <tgr.huwiki@gmail.com>
Mon, 24 Sep 2018 21:10:08 +0000 (14:10 -0700)
committerGergő Tisza <tgr.huwiki@gmail.com>
Mon, 24 Sep 2018 23:52:12 +0000 (16:52 -0700)
Bug: T202142
Change-Id: I97a74e5a029b014f3c2195188936d5c8233c1b7f

45 files changed:
docs/pageupdater.txt
includes/Revision.php
includes/Revision/RevisionRenderer.php
includes/Storage/DerivedPageDataUpdater.php
includes/Storage/PageUpdater.php
includes/Storage/RevisionStore.php
includes/Storage/SlotRecord.php
includes/api/ApiComparePages.php
includes/api/ApiFeedContributions.php
includes/api/ApiQueryRevisionsBase.php
includes/diff/DifferenceEngine.php
includes/page/Article.php
includes/page/WikiPage.php
includes/poolcounter/PoolWorkArticleView.php
maintenance/edit.php
maintenance/populateContentTables.php
maintenance/storage/dumpRev.php
tests/phpunit/includes/Revision/RenderedRevisionTest.php
tests/phpunit/includes/Revision/RevisionRendererTest.php
tests/phpunit/includes/RevisionDbTestBase.php
tests/phpunit/includes/RevisionMcrDbTest.php
tests/phpunit/includes/RevisionMcrReadNewDbTest.php
tests/phpunit/includes/RevisionTest.php
tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php
tests/phpunit/includes/Storage/MutableRevisionRecordTest.php
tests/phpunit/includes/Storage/MutableRevisionSlotsTest.php
tests/phpunit/includes/Storage/NoContentModelRevisionStoreDbTest.php
tests/phpunit/includes/Storage/PageUpdaterTest.php
tests/phpunit/includes/Storage/RevisionArchiveRecordTest.php
tests/phpunit/includes/Storage/RevisionQueryInfoTest.php
tests/phpunit/includes/Storage/RevisionRecordTests.php
tests/phpunit/includes/Storage/RevisionSlotsTest.php
tests/phpunit/includes/Storage/RevisionSlotsUpdateTest.php
tests/phpunit/includes/Storage/RevisionStoreDbTestBase.php
tests/phpunit/includes/Storage/RevisionStoreRecordTest.php
tests/phpunit/includes/Storage/RevisionStoreTest.php
tests/phpunit/includes/Storage/SlotRecordTest.php
tests/phpunit/includes/api/ApiQueryWatchlistIntegrationTest.php
tests/phpunit/includes/content/WikitextContentHandlerTest.php
tests/phpunit/includes/diff/DifferenceEngineTest.php
tests/phpunit/includes/page/ArticleViewTest.php
tests/phpunit/includes/page/PageArchivePreMcrTest.php
tests/phpunit/includes/page/WikiPageDbTestBase.php
tests/phpunit/includes/parser/ParserMethodsTest.php
tests/phpunit/includes/poolcounter/PoolWorkArticleViewTest.php

index 4980c92..54eb91a 100644 (file)
@@ -61,7 +61,7 @@ Typical usage for programmatic revision creation (with $page being a WikiPage as
 replaced by a repository service later):
 
   $updater = $page->newPageUpdater( $user );
-  $updater->setContent( 'main', $content );
+  $updater->setContent( SlotRecord::MAIN, $content );
   $updater->setRcPatrolStatus( RecentChange::PRC_PATROLLED );
   $newRev = $updater->saveRevision( $comment );
 
@@ -69,8 +69,8 @@ Usage with content depending on the parent revision
 
   $updater = $page->newPageUpdater( $user );
   $parent = $updater->grabParentRevision();
-  $content = $parent->getContent( 'main' )->replaceSection( $section, $sectionContent );
-  $updater->setContent( 'main', $content );
+  $content = $parent->getContent( SlotRecord::MAIN )->replaceSection( $section, $sectionContent );
+  $updater->setContent( SlotRecord::MAIN, $content );
   $newRev = $updater->saveRevision( $comment, EDIT_UPDATE );
 
 In both cases, all secondary updates will be triggered automatically.
index 1e35dda..a55b1c4 100644 (file)
@@ -691,7 +691,7 @@ class Revision implements IDBAccessObject {
         * @return SlotRecord
         */
        private function getMainSlotRaw() {
-               return $this->mRecord->getSlot( 'main', RevisionRecord::RAW );
+               return $this->mRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
        }
 
        /**
@@ -926,7 +926,7 @@ class Revision implements IDBAccessObject {
                }
 
                try {
-                       return $this->mRecord->getContent( 'main', $audience, $user );
+                       return $this->mRecord->getContent( SlotRecord::MAIN, $audience, $user );
                }
                catch ( RevisionAccessException $e ) {
                        return null;
index f71f9e7..c937376 100644 (file)
@@ -25,6 +25,7 @@ namespace MediaWiki\Revision;
 use Html;
 use InvalidArgumentException;
 use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
 use ParserOptions;
 use ParserOutput;
 use Psr\Log\LoggerInterface;
@@ -165,15 +166,15 @@ class RevisionRenderer {
                $withHtml = $hints['generate-html'] ?? true;
 
                // short circuit if there is only the main slot
-               if ( array_keys( $slots ) === [ 'main' ] ) {
-                       return $rrev->getSlotParserOutput( 'main' );
+               if ( array_keys( $slots ) === [ SlotRecord::MAIN ] ) {
+                       return $rrev->getSlotParserOutput( SlotRecord::MAIN );
                }
 
                // TODO: put fancy layout logic here, see T200915.
 
                // move main slot to front
-               if ( isset( $slots['main'] ) ) {
-                       $slots = [ 'main' => $slots['main'] ] + $slots;
+               if ( isset( $slots[SlotRecord::MAIN] ) ) {
+                       $slots = [ SlotRecord::MAIN => $slots[SlotRecord::MAIN] ] + $slots;
                }
 
                $combinedOutput = new ParserOutput( null );
index e34e406..3f3b0cf 100644 (file)
@@ -659,7 +659,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                }
 
                // TODO: MCR: ask all slots if they have links [SlotHandler/PageTypeHandler]
-               $mainContent = $this->getRawContent( 'main' );
+               $mainContent = $this->getRawContent( SlotRecord::MAIN );
                return $mainContent->isCountable( $hasLinks );
        }
 
@@ -668,7 +668,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
         */
        public function isRedirect() {
                // NOTE: main slot determines redirect status
-               $mainContent = $this->getRawContent( 'main' );
+               $mainContent = $this->getRawContent( SlotRecord::MAIN );
 
                return $mainContent->isRedirect();
        }
@@ -680,7 +680,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
         */
        private function revisionIsRedirect( RevisionRecord $rev ) {
                // NOTE: main slot determines redirect status
-               $mainContent = $rev->getContent( 'main', RevisionRecord::RAW );
+               $mainContent = $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW );
 
                return $mainContent->isRedirect();
        }
@@ -751,8 +751,8 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                $stashedEdit = false;
 
                // TODO: MCR: allow output for all slots to be stashed.
-               if ( $useStash && $slotsUpdate->isModifiedSlot( 'main' ) ) {
-                       $mainContent = $slotsUpdate->getModifiedSlot( 'main' )->getContent();
+               if ( $useStash && $slotsUpdate->isModifiedSlot( SlotRecord::MAIN ) ) {
+                       $mainContent = $slotsUpdate->getModifiedSlot( SlotRecord::MAIN )->getContent();
                        $legacyUser = User::newFromIdentity( $user );
                        $stashedEdit = ApiStashEdit::checkCache( $title, $mainContent, $legacyUser );
                }
@@ -807,7 +807,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                                // No PST for inherited slots! Note that "modified" slots may still be inherited
                                // from an earlier version, e.g. for rollbacks.
                                $pstSlot = $slot;
-                       } elseif ( $role === 'main' && $stashedEdit ) {
+                       } elseif ( $role === SlotRecord::MAIN && $stashedEdit ) {
                                // TODO: MCR: allow PST content for all slots to be stashed.
                                $pstSlot = SlotRecord::newUnsaved( $role, $stashedEdit->pstContent );
                        } else {
@@ -1223,11 +1223,11 @@ class DerivedPageDataUpdater implements IDBAccessObject {
 
                $preparedEdit->popts = $this->getCanonicalParserOptions();
                $preparedEdit->output = $this->getCanonicalParserOutput();
-               $preparedEdit->pstContent = $this->revision->getContent( 'main' );
+               $preparedEdit->pstContent = $this->revision->getContent( SlotRecord::MAIN );
                $preparedEdit->newContent =
-                       $slotsUpdate->isModifiedSlot( 'main' )
-                       ? $slotsUpdate->getModifiedSlot( 'main' )->getContent()
-                       : $this->revision->getContent( 'main' ); // XXX: can we just remove this?
+                       $slotsUpdate->isModifiedSlot( SlotRecord::MAIN )
+                       ? $slotsUpdate->getModifiedSlot( SlotRecord::MAIN )->getContent()
+                       : $this->revision->getContent( SlotRecord::MAIN ); // XXX: can we just remove this?
                $preparedEdit->oldContent = null; // unused. // XXX: could get this from the parent revision
                $preparedEdit->revid = $this->revision ? $this->revision->getId() : null;
                $preparedEdit->timestamp = $preparedEdit->output->getCacheTime();
@@ -1394,7 +1394,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
 
                // TODO: MCR: check if *any* changed slot supports categories!
                if ( $this->rcWatchCategoryMembership
-                       && $this->getContentHandler( 'main' )->supportsCategories() === true
+                       && $this->getContentHandler( SlotRecord::MAIN )->supportsCategories() === true
                        && ( $this->options['changed'] || $this->options['created'] )
                        && !$this->options['restored']
                ) {
@@ -1459,7 +1459,7 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                ) );
 
                // TODO: make search infrastructure aware of slots!
-               $mainSlot = $this->revision->getSlot( 'main' );
+               $mainSlot = $this->revision->getSlot( SlotRecord::MAIN );
                if ( !$mainSlot->isInherited() && !$this->isContentDeleted() ) {
                        DeferredUpdates::addUpdate( new SearchUpdate( $id, $dbKey, $mainSlot->getContent() ) );
                }
@@ -1493,9 +1493,9 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                }
 
                if ( $title->getNamespace() == NS_MEDIAWIKI
-                       && $this->getRevisionSlotsUpdate()->isModifiedSlot( 'main' )
+                       && $this->getRevisionSlotsUpdate()->isModifiedSlot( SlotRecord::MAIN )
                ) {
-                       $mainContent = $this->isContentDeleted() ? null : $this->getRawContent( 'main' );
+                       $mainContent = $this->isContentDeleted() ? null : $this->getRawContent( SlotRecord::MAIN );
 
                        $this->messageCache->updateMessageOverride( $title, $mainContent );
                }
index 1621213..29ce710 100644 (file)
@@ -388,7 +388,7 @@ class PageUpdater {
         * @param string $role A slot role name (but not "main")
         */
        public function removeSlot( $role ) {
-               if ( $role === 'main' ) {
+               if ( $role === SlotRecord::MAIN ) {
                        throw new InvalidArgumentException( 'Cannot remove the main slot!' );
                }
 
@@ -635,7 +635,7 @@ class PageUpdater {
 
                // Make sure the given content type is allowed for this page
                // TODO: decide: Extend check to other slots? Consider the role in check? [PageType]
-               $mainContentHandler = $this->getContentHandler( 'main' );
+               $mainContentHandler = $this->getContentHandler( SlotRecord::MAIN );
                if ( !$mainContentHandler->canBeUsedOn( $this->getTitle() ) ) {
                        $this->status = Status::newFatal( 'content-not-allowed-here',
                                ContentHandler::getLocalizedName( $mainContentHandler->getModelID() ),
@@ -701,7 +701,7 @@ class PageUpdater {
                 */
                $this->derivedDataUpdater->getCanonicalParserOutput();
 
-               $mainContent = $this->derivedDataUpdater->getSlots()->getContent( 'main' );
+               $mainContent = $this->derivedDataUpdater->getSlots()->getContent( SlotRecord::MAIN );
 
                // Trigger pre-save hook (using provided edit summary)
                $hookStatus = Status::newGood( [] );
@@ -1049,7 +1049,7 @@ class PageUpdater {
        private function doCreate( CommentStoreComment $summary, User $user, $flags ) {
                $wikiPage = $this->getWikiPage(); // TODO: use for legacy hooks only!
 
-               if ( !$this->derivedDataUpdater->getSlots()->hasSlot( 'main' ) ) {
+               if ( !$this->derivedDataUpdater->getSlots()->hasSlot( SlotRecord::MAIN ) ) {
                        throw new PageUpdateException( 'Must provide a main slot when creating a page!' );
                }
 
@@ -1186,7 +1186,7 @@ class PageUpdater {
                                $hints['causeAgent'] = $user->getName();
 
                                $newLegacyRevision = new Revision( $newRevisionRecord );
-                               $mainContent = $newRevisionRecord->getContent( 'main', RevisionRecord::RAW );
+                               $mainContent = $newRevisionRecord->getContent( SlotRecord::MAIN, RevisionRecord::RAW );
 
                                // Update links tables, site stats, etc.
                                $this->derivedDataUpdater->prepareUpdate( $newRevisionRecord, $hints );
index 61b428f..bab1b5e 100644 (file)
@@ -437,21 +437,25 @@ class RevisionStore
                $slotRoles = $rev->getSlotRoles();
 
                // Make sure the main slot is always provided throughout migration
-               if ( !in_array( 'main', $slotRoles ) ) {
+               if ( !in_array( SlotRecord::MAIN, $slotRoles ) ) {
                        throw new InvalidArgumentException(
                                'main slot must be provided'
                        );
                }
 
                // If we are not writing into the new schema, we can't support extra slots.
-               if ( !$this->hasMcrSchemaFlags( SCHEMA_COMPAT_WRITE_NEW ) && $slotRoles !== [ 'main' ] ) {
+               if ( !$this->hasMcrSchemaFlags( SCHEMA_COMPAT_WRITE_NEW )
+                       && $slotRoles !== [ SlotRecord::MAIN ]
+               ) {
                        throw new InvalidArgumentException(
                                'Only the main slot is supported when not writing to the MCR enabled schema!'
                        );
                }
 
                // As long as we are not reading from the new schema, we don't want to write extra slots.
-               if ( !$this->hasMcrSchemaFlags( SCHEMA_COMPAT_READ_NEW ) && $slotRoles !== [ 'main' ] ) {
+               if ( !$this->hasMcrSchemaFlags( SCHEMA_COMPAT_READ_NEW )
+                       && $slotRoles !== [ SlotRecord::MAIN ]
+               ) {
                        throw new InvalidArgumentException(
                                'Only the main slot is supported when not reading from the MCR enabled schema!'
                        );
@@ -519,7 +523,7 @@ class RevisionStore
                // Technically, this could go away after MCR migration: while
                // calling code may require a main slot to exist, RevisionStore
                // really should not know or care about that requirement.
-               $rev->getSlot( 'main', RevisionRecord::RAW );
+               $rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
 
                foreach ( $slotRoles as $role ) {
                        $slot = $rev->getSlot( $role, RevisionRecord::RAW );
@@ -594,7 +598,7 @@ class RevisionStore
                                $newSlots[$role] = $slot;
 
                                // Write the main slot's text ID to the revision table for backwards compatibility
-                               if ( $slot->getRole() === 'main'
+                               if ( $slot->getRole() === SlotRecord::MAIN
                                        && $this->hasMcrSchemaFlags( SCHEMA_COMPAT_WRITE_OLD )
                                ) {
                                        $blobAddress = $slot->getAddress();
@@ -672,7 +676,7 @@ class RevisionStore
                $contentId = null;
 
                // Write the main slot's text ID to the revision table for backwards compatibility
-               if ( $protoSlot->getRole() === 'main'
+               if ( $protoSlot->getRole() === SlotRecord::MAIN
                        && $this->hasMcrSchemaFlags( SCHEMA_COMPAT_WRITE_OLD )
                ) {
                        // If SCHEMA_COMPAT_WRITE_NEW is also set, the fake content ID is overwritten
@@ -876,7 +880,7 @@ class RevisionStore
 
                if ( $this->hasMcrSchemaFlags( SCHEMA_COMPAT_WRITE_OLD ) ) {
                        // In non MCR mode this IF section will relate to the main slot
-                       $mainSlot = $rev->getSlot( 'main' );
+                       $mainSlot = $rev->getSlot( SlotRecord::MAIN );
                        $model = $mainSlot->getModel();
                        $format = $mainSlot->getFormat();
 
@@ -1209,7 +1213,7 @@ class RevisionStore
         */
        private function emulateMainSlot_1_29( $row, $queryFlags, Title $title ) {
                $mainSlotRow = new stdClass();
-               $mainSlotRow->role_name = 'main';
+               $mainSlotRow->role_name = SlotRecord::MAIN;
                $mainSlotRow->model_name = null;
                $mainSlotRow->slot_revision_id = null;
                $mainSlotRow->slot_content_id = null;
@@ -1358,7 +1362,7 @@ class RevisionStore
                        $mainSlotRow->slot_content_id =
                                function ( SlotRecord $slot ) use ( $queryFlags, $mainSlotRow ) {
                                        $db = $this->getDBConnectionRefForQueryFlags( $queryFlags );
-                                       return $this->findSlotContentId( $db, $mainSlotRow->slot_revision_id, 'main' );
+                                       return $this->findSlotContentId( $db, $mainSlotRow->slot_revision_id, SlotRecord::MAIN );
                                };
                }
 
@@ -1609,7 +1613,7 @@ class RevisionStore
                        $slots[$row->role_name] = new SlotRecord( $row, $contentCallback );
                }
 
-               if ( !isset( $slots['main'] ) ) {
+               if ( !isset( $slots[SlotRecord::MAIN] ) ) {
                        throw new RevisionAccessException(
                                'Main slot of revision ' . $revId . ' not found in database!'
                        );
@@ -1640,7 +1644,7 @@ class RevisionStore
        ) {
                if ( !$this->hasMcrSchemaFlags( SCHEMA_COMPAT_READ_NEW ) ) {
                        $mainSlot = $this->emulateMainSlot_1_29( $revisionRow, $queryFlags, $title );
-                       $slots = new RevisionSlots( [ 'main' => $mainSlot ] );
+                       $slots = new RevisionSlots( [ SlotRecord::MAIN => $mainSlot ] );
                } else {
                        // XXX: do we need the same kind of caching here
                        // that getKnownCurrentRevision uses (if $revId == page_latest?)
@@ -2346,7 +2350,7 @@ class RevisionStore
                        $ret['fields']['slot_revision_id'] = 'slots.rev_id';
                        $ret['fields']['slot_content_id'] = 'NULL';
                        $ret['fields']['slot_origin'] = 'slots.rev_id';
-                       $ret['fields']['role_name'] = $db->addQuotes( 'main' );
+                       $ret['fields']['role_name'] = $db->addQuotes( SlotRecord::MAIN );
 
                        if ( in_array( 'content', $options, true ) ) {
                                $ret['fields']['content_size'] = 'slots.rev_len';
index c7eb735..ee36d44 100644 (file)
@@ -37,6 +37,8 @@ use Wikimedia\Assert\Assert;
  */
 class SlotRecord {
 
+       const MAIN = 'main';
+
        /**
         * @var object database result row, as a raw object. Callbacks are supported for field values,
         *      to enable on-demand emulation of these values. This is primarily intended for use
index 02cadbd..c5a2234 100644 (file)
@@ -23,6 +23,7 @@ use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\MutableRevisionRecord;
 use MediaWiki\Storage\RevisionRecord;
 use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
 
 class ApiComparePages extends ApiBase {
 
@@ -271,7 +272,7 @@ class ApiComparePages extends ApiBase {
                }
 
                $guessedTitle = $this->guessTitle();
-               if ( $guessedTitle && $role === 'main' ) {
+               if ( $guessedTitle && $role === SlotRecord::MAIN ) {
                        // @todo: Use SlotRoleRegistry and do this for all slots
                        return $guessedTitle->getContentModel();
                }
@@ -283,7 +284,7 @@ class ApiComparePages extends ApiBase {
                        return $params["tocontentmodel-$role"];
                }
 
-               if ( $role === 'main' ) {
+               if ( $role === SlotRecord::MAIN ) {
                        if ( isset( $params['fromcontentmodel'] ) ) {
                                return $params['fromcontentmodel'];
                        }
@@ -315,7 +316,7 @@ class ApiComparePages extends ApiBase {
                $this->requireMaxOneParameter( $params, "{$prefix}text", "{$prefix}slots" );
                $this->requireMaxOneParameter( $params, "{$prefix}section", "{$prefix}slots" );
                if ( $params["{$prefix}text"] !== null ) {
-                       $params["{$prefix}slots"] = [ 'main' ];
+                       $params["{$prefix}slots"] = [ SlotRecord::MAIN ];
                        $params["{$prefix}text-main"] = $params["{$prefix}text"];
                        $params["{$prefix}section-main"] = null;
                        $params["{$prefix}contentmodel-main"] = $params["{$prefix}contentmodel"];
@@ -378,10 +379,11 @@ class ApiComparePages extends ApiBase {
                                if ( isset( $params["{$prefix}section"] ) ) {
                                        $section = $params["{$prefix}section"];
                                        $newRev = MutableRevisionRecord::newFromParentRevision( $rev );
-                                       $content = $rev->getContent( 'main', RevisionRecord::FOR_THIS_USER, $this->getUser() );
+                                       $content = $rev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER,
+                                               $this->getUser() );
                                        if ( !$content ) {
                                                $this->dieWithError(
-                                                       [ 'apierror-missingcontent-revid-role', $rev->getId(), 'main' ], 'missingcontent'
+                                                       [ 'apierror-missingcontent-revid-role', $rev->getId(), SlotRecord::MAIN ], 'missingcontent'
                                                );
                                        }
                                        $content = $content ? $content->getSection( $section ) : null;
@@ -391,7 +393,7 @@ class ApiComparePages extends ApiBase {
                                                        "nosuch{$prefix}section"
                                                );
                                        }
-                                       $newRev->setContent( 'main', $content );
+                                       $newRev->setContent( SlotRecord::MAIN, $content );
                                }
 
                                return [ $newRev, $rev, $rev ];
@@ -412,8 +414,8 @@ class ApiComparePages extends ApiBase {
                foreach ( $params["{$prefix}slots"] as $role ) {
                        $text = $params["{$prefix}text-{$role}"];
                        if ( $text === null ) {
-                               // The 'main' role can't be deleted
-                               if ( $role === 'main' ) {
+                               // The SlotRecord::MAIN role can't be deleted
+                               if ( $role === SlotRecord::MAIN ) {
                                        $this->dieWithError( [ 'apierror-compare-maintextrequired', $prefix ] );
                                }
 
@@ -439,7 +441,7 @@ class ApiComparePages extends ApiBase {
                        if ( !$model && $rev && $rev->hasSlot( $role ) ) {
                                $model = $rev->getSlot( $role, RevisionRecord::RAW )->getModel();
                        }
-                       if ( !$model && $title && $role === 'main' ) {
+                       if ( !$model && $title && $role === SlotRecord::MAIN ) {
                                // @todo: Use SlotRoleRegistry and do this for all slots
                                $model = $title->getContentModel();
                        }
@@ -494,7 +496,7 @@ class ApiComparePages extends ApiBase {
                        }
 
                        // Deprecated 'fromsection'/'tosection'
-                       if ( $role === 'main' && isset( $params["{$prefix}section"] ) ) {
+                       if ( $role === SlotRecord::MAIN && isset( $params["{$prefix}section"] ) ) {
                                $section = $params["{$prefix}section"];
                                $content = $content->getSection( $section );
                                if ( !$content ) {
@@ -581,8 +583,8 @@ class ApiComparePages extends ApiBase {
 
        public function getAllowedParams() {
                $slotRoles = MediaWikiServices::getInstance()->getSlotRoleStore()->getMap();
-               if ( !in_array( 'main', $slotRoles, true ) ) {
-                       $slotRoles[] = 'main';
+               if ( !in_array( SlotRecord::MAIN, $slotRoles, true ) ) {
+                       $slotRoles[] = SlotRecord::MAIN;
                }
                sort( $slotRoles, SORT_STRING );
 
index 92d504e..2b2b32c 100644 (file)
@@ -24,6 +24,7 @@ use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\RevisionAccessException;
 use MediaWiki\Storage\RevisionRecord;
 use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
 
 /**
  * @ingroup API
@@ -174,7 +175,7 @@ class ApiFeedContributions extends ApiBase {
                if ( $revision ) {
                        $msg = wfMessage( 'colon-separator' )->inContentLanguage()->text();
                        try {
-                               $content = $revision->getContent( 'main' );
+                               $content = $revision->getContent( SlotRecord::MAIN );
                        } catch ( RevisionAccessException $e ) {
                                $content = null;
                        }
index 600c89e..e5d7748 100644 (file)
@@ -307,7 +307,7 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
                        }
                        if ( $this->slotRoles === null ) {
                                try {
-                                       $slot = $revision->getSlot( 'main', RevisionRecord::RAW );
+                                       $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.
@@ -621,8 +621,8 @@ abstract class ApiQueryRevisionsBase extends ApiQueryGeneratorBase {
 
        public function getAllowedParams() {
                $slotRoles = MediaWikiServices::getInstance()->getSlotRoleStore()->getMap();
-               if ( !in_array( 'main', $slotRoles, true ) ) {
-                       $slotRoles[] = 'main';
+               if ( !in_array( SlotRecord::MAIN, $slotRoles, true ) ) {
+                       $slotRoles[] = SlotRecord::MAIN;
                }
                sort( $slotRoles, SORT_STRING );
 
index 9602bd2..936f6bf 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
 
 /**
  * DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
@@ -273,7 +274,7 @@ class DifferenceEngine extends ContextSource {
        protected function getSlotContents() {
                if ( $this->isContentOverridden ) {
                        return [
-                               'main' => [
+                               SlotRecord::MAIN => [
                                        'old' => $this->mOldContent,
                                        'new' => $this->mNewContent,
                                ]
@@ -302,8 +303,8 @@ class DifferenceEngine extends ContextSource {
                        ];
                }
                // move main slot to front
-               if ( isset( $slots['main'] ) ) {
-                       $slots = [ 'main' => $slots['main'] ] + $slots;
+               if ( isset( $slots[SlotRecord::MAIN] ) ) {
+                       $slots = [ SlotRecord::MAIN => $slots[SlotRecord::MAIN] ] + $slots;
                }
                return $slots;
        }
@@ -1053,7 +1054,7 @@ class DifferenceEngine extends ContextSource {
                foreach ( $this->getSlotDiffRenderers() as $role => $slotDiffRenderer ) {
                        $slotDiff = $slotDiffRenderer->getDiff( $slotContents[$role]['old'],
                                $slotContents[$role]['new'] );
-                       if ( $slotDiff && $role !== 'main' ) {
+                       if ( $slotDiff && $role !== SlotRecord::MAIN ) {
                                // TODO use human-readable role name at least
                                $slotTitle = $role;
                                $difftext .= $this->getSlotHeader( $slotTitle );
@@ -1100,7 +1101,7 @@ class DifferenceEngine extends ContextSource {
                        return false;
                }
 
-               if ( $role !== 'main' ) {
+               if ( $role !== SlotRecord::MAIN ) {
                        // TODO use human-readable role name at least
                        $slotTitle = $role;
                        $slotDiff = $this->getSlotHeader( $slotTitle ) . $slotDiff;
@@ -1640,7 +1641,7 @@ class DifferenceEngine extends ContextSource {
                        $this->mOldPage = Title::newFromLinkTarget( $oldRevision->getPageAsLinkTarget() );
                        // This method is meant for edit diffs and such so there is no reason to provide a
                        // revision that's not readable to the user, but check it just in case.
-                       $this->mOldContent = $oldRevision ? $oldRevision->getContent( 'main',
+                       $this->mOldContent = $oldRevision ? $oldRevision->getContent( SlotRecord::MAIN,
                                RevisionRecord::FOR_THIS_USER, $this->getUser() ) : null;
                } else {
                        $this->mOldPage = null;
@@ -1649,7 +1650,7 @@ class DifferenceEngine extends ContextSource {
                $this->mNewRev = new Revision( $newRevision );
                $this->mNewid = $newRevision->getId();
                $this->mNewPage = Title::newFromLinkTarget( $newRevision->getPageAsLinkTarget() );
-               $this->mNewContent = $newRevision->getContent( 'main',
+               $this->mNewContent = $newRevision->getContent( SlotRecord::MAIN,
                        RevisionRecord::FOR_THIS_USER, $this->getUser() );
 
                $this->mRevisionsIdsLoaded = $this->mRevisionsLoaded = true;
index 6a42d58..b6f5dce 100644 (file)
@@ -22,6 +22,7 @@
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\MutableRevisionRecord;
 use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
 
 /**
  * Class for viewing MediaWiki article and history.
@@ -524,7 +525,7 @@ class Article implements Page {
        private function applyContentOverride( Content $override ) {
                // Construct a fake revision
                $rev = new MutableRevisionRecord( $this->getTitle() );
-               $rev->setContent( 'main', $override );
+               $rev->setContent( SlotRecord::MAIN, $override );
 
                $this->mRevision = new Revision( $rev );
 
@@ -870,7 +871,7 @@ class Article implements Page {
                // TODO: find a *good* place for the code that determines the redirect target for
                // a given revision!
                // NOTE: Use main slot content. Compare code in DerivedPageDataUpdater::revisionIsRedirect.
-               $content = $revision->getContent( 'main' );
+               $content = $revision->getContent( SlotRecord::MAIN );
                return $content ? $content->getRedirectTarget() : null;
        }
 
index 74e3179..7c97465 100644 (file)
@@ -1494,7 +1494,7 @@ class WikiPage implements Page, IDBAccessObject {
                $bSlots = $b->getRevisionRecord()->getSlots();
                $changedRoles = $aSlots->getRolesWithDifferentContent( $bSlots );
 
-               return ( $changedRoles !== [ 'main' ] && $changedRoles !== [] );
+               return ( $changedRoles !== [ SlotRecord::MAIN ] && $changedRoles !== [] );
        }
 
        /**
@@ -1853,13 +1853,13 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                $slotsUpdate = new RevisionSlotsUpdate();
-               $slotsUpdate->modifyContent( 'main', $content );
+               $slotsUpdate->modifyContent( SlotRecord::MAIN, $content );
 
                // NOTE: while doEditContent() executes, callbacks to getDerivedDataUpdater and
                // prepareContentForEdit will generally use the DerivedPageDataUpdater that is also
                // used by this PageUpdater. However, there is no guarantee for this.
                $updater = $this->newPageUpdater( $user, $slotsUpdate );
-               $updater->setContent( 'main', $content );
+               $updater->setContent( SlotRecord::MAIN, $content );
                $updater->setOriginalRevisionId( $originalRevId );
                $updater->setUndidRevisionId( $undidRevId );
 
@@ -1966,7 +1966,7 @@ class WikiPage implements Page, IDBAccessObject {
                        $revision = $revision->getRevisionRecord();
                }
 
-               $slots = RevisionSlotsUpdate::newFromContent( [ 'main' => $content ] );
+               $slots = RevisionSlotsUpdate::newFromContent( [ SlotRecord::MAIN => $content ] );
                $updater = $this->getDerivedDataUpdater( $user, $revision, $slots );
 
                if ( !$updater->isUpdatePrepared() ) {
@@ -3069,8 +3069,8 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                // TODO: MCR: also log model changes in other slots, in case that becomes possible!
-               $currentContent = $current->getContent( 'main' );
-               $targetContent = $target->getContent( 'main' );
+               $currentContent = $current->getContent( SlotRecord::MAIN );
+               $targetContent = $target->getContent( SlotRecord::MAIN );
                $changingContentModel = $targetContent->getModel() !== $currentContent->getModel();
 
                if ( in_array( 'mw-rollback', ChangeTags::getSoftwareTags() ) ) {
@@ -3290,7 +3290,7 @@ class WikiPage implements Page, IDBAccessObject {
        ) {
                // TODO: move this into a PageEventEmitter service
 
-               if ( $slotsChanged === null || in_array( 'main',  $slotsChanged ) ) {
+               if ( $slotsChanged === null || in_array( SlotRecord::MAIN,  $slotsChanged ) ) {
                        // Invalidate caches of articles which include this page.
                        // Only for the main slot, because only the main slot is transcluded.
                        // TODO: MCR: not true for TemplateStyles! [SlotHandler]
@@ -3578,7 +3578,7 @@ class WikiPage implements Page, IDBAccessObject {
                } elseif ( $rev instanceof Content ) {
                        wfDeprecated( __METHOD__ . ' with a Content object instead of a RevisionRecord', '1.32' );
 
-                       $slotContent = [ 'main' => $rev ];
+                       $slotContent = [ SlotRecord::MAIN => $rev ];
                } else {
                        $slotContent = array_map( function ( SlotRecord $slot ) {
                                return $slot->getContent( Revision::RAW );
index 286494e..157b508 100644 (file)
@@ -23,6 +23,7 @@ use MediaWiki\Revision\RevisionRenderer;
 use MediaWiki\Storage\MutableRevisionRecord;
 use MediaWiki\Storage\RevisionRecord;
 use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
 
 class PoolWorkArticleView extends PoolCounterWork {
        /** @var WikiPage */
@@ -81,7 +82,7 @@ class PoolWorkArticleView extends PoolCounterWork {
                        $revision = new MutableRevisionRecord( $page->getTitle() );
                        $revision->setId( $revid );
                        $revision->setPageId( $page->getId() );
-                       $revision->setContent( 'main', $content );
+                       $revision->setContent( SlotRecord::MAIN, $content );
                }
 
                if ( $revision ) {
index a279cda..eb03b38 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup Maintenance
  */
 
+use MediaWiki\Storage\SlotRecord;
+
 require_once __DIR__ . '/Maintenance.php';
 
 /**
@@ -55,7 +57,7 @@ class EditCLI extends Maintenance {
                $bot = $this->hasOption( 'bot' );
                $autoSummary = $this->hasOption( 'autosummary' );
                $noRC = $this->hasOption( 'no-rc' );
-               $slot = $this->getOption( 'slot', 'main' );
+               $slot = $this->getOption( 'slot', SlotRecord::MAIN );
 
                if ( $userName === false ) {
                        $wgUser = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] );
@@ -83,7 +85,7 @@ class EditCLI extends Maintenance {
                $page = WikiPage::factory( $title );
 
                if ( $remove ) {
-                       if ( $slot === 'main' ) {
+                       if ( $slot === SlotRecord::MAIN ) {
                                $this->fatalError( "Cannot remove main slot! Use --slot to specify." );
                        }
 
index 49db4fb..93d5baf 100644 (file)
@@ -21,6 +21,7 @@
 
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\NameTableStore;
+use MediaWiki\Storage\SlotRecord;
 use MediaWiki\Storage\SqlBlobStore;
 use Wikimedia\Assert\Assert;
 use Wikimedia\Rdbms\IDatabase;
@@ -66,7 +67,8 @@ class PopulateContentTables extends Maintenance {
        private function initServices() {
                $this->dbw = $this->getDB( DB_MASTER );
                $this->contentModelStore = MediaWikiServices::getInstance()->getContentModelStore();
-               $this->mainRoleId = MediaWikiServices::getInstance()->getSlotRoleStore()->acquireId( 'main' );
+               $this->mainRoleId = MediaWikiServices::getInstance()->getSlotRoleStore()
+                       ->acquireId( SlotRecord::MAIN );
        }
 
        public function execute() {
index 91a5f3b..0f0073c 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\SlotRecord;
 
 require_once __DIR__ . '/../Maintenance.php';
 
@@ -46,13 +47,13 @@ class DumpRev extends Maintenance {
                        $this->fatalError( "Row not found" );
                }
 
-               $content = $rev->getContent( 'main' );
+               $content = $rev->getContent( SlotRecord::MAIN );
                if ( !$content ) {
                        $this->fatalError( "Text not found" );
                }
 
                $blobStore = MediaWikiServices::getInstance()->getBlobStore();
-               $slot = $rev->getSlot( 'main' );
+               $slot = $rev->getSlot( SlotRecord::MAIN );
                $text = $blobStore->getBlob( $slot->getAddress() );
 
                $this->output( "Text length: " . strlen( $text ) . "\n" );
index bea0b49..2ee1ab4 100644 (file)
@@ -11,6 +11,7 @@ use MediaWiki\Storage\RevisionArchiveRecord;
 use MediaWiki\Storage\RevisionRecord;
 use MediaWiki\Storage\RevisionStore;
 use MediaWiki\Storage\RevisionStoreRecord;
+use MediaWiki\Storage\SlotRecord;
 use MediaWiki\Storage\SuppressedDataException;
 use MediaWiki\User\UserIdentityValue;
 use MediaWikiTestCase;
@@ -241,7 +242,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $this->assertContains( 'user:Frank!', $html );
                $this->assertContains( 'time:20180101000003!', $html );
 
-               $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+               $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
        }
 
        public function testGetRevisionParserOutput_old() {
@@ -263,7 +264,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $this->assertContains( 'user:Frank!', $html );
                $this->assertContains( 'time:20180101000003!', $html );
 
-               $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+               $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
        }
 
        public function testGetRevisionParserOutput_archive() {
@@ -285,7 +286,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $this->assertContains( 'user:Frank!', $html );
                $this->assertContains( 'time:20180101000003!', $html );
 
-               $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+               $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
        }
 
        public function testGetRevisionParserOutput_suppressed() {
@@ -337,7 +338,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $this->assertContains( 'user:Frank!', $html );
                $this->assertContains( 'time:20180101000003!', $html );
 
-               $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+               $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
        }
 
        public function testGetRevisionParserOutput_raw() {
@@ -371,7 +372,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $this->assertContains( 'user:Frank!', $html );
                $this->assertContains( 'time:20180101000003!', $html );
 
-               $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+               $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
        }
 
        public function testGetRevisionParserOutput_multi() {
@@ -387,7 +388,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
 
                $combinedOutput = $rr->getRevisionParserOutput();
-               $mainOutput = $rr->getSlotParserOutput( 'main' );
+               $mainOutput = $rr->getSlotParserOutput( SlotRecord::MAIN );
                $auxOutput = $rr->getSlotParserOutput( 'aux' );
 
                $combinedHtml = $combinedOutput->getText();
@@ -422,7 +423,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $text .= "* user:{{REVISIONUSER}}!\n";
                $text .= "* time:{{REVISIONTIMESTAMP}}!\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
@@ -449,7 +450,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $text .= "* user:{{REVISIONUSER}}!\n";
                $text .= "* time:{{REVISIONTIMESTAMP}}!\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $actualRevision = $this->getMockRevision(
                        RevisionStoreRecord::class,
@@ -503,13 +504,13 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $title = $this->getMockTitle( 7, 21 );
 
                $rev = new MutableRevisionRecord( $title );
-               $rev->setContent( 'main', $mockContent );
+               $rev->setContent( SlotRecord::MAIN, $mockContent );
                $rev->setContent( 'aux', $mockContent );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
 
-               $output = $rr->getSlotParserOutput( 'main', [ 'generate-html' => false ] );
+               $output = $rr->getSlotParserOutput( SlotRecord::MAIN, [ 'generate-html' => false ] );
                $this->assertFalse( $output->hasText(), 'hasText' );
 
                $output = $rr->getRevisionParserOutput( [ 'generate-html' => false ] );
@@ -527,19 +528,19 @@ class RenderedRevisionTest extends MediaWikiTestCase {
                $text .= "* user:{{REVISIONUSER}}!\n";
                $text .= "* time:{{REVISIONTIMESTAMP}}!\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
                $rev->setContent( 'aux', new WikitextContent( '[[Goats]]' ) );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = new RenderedRevision( $title, $rev, $options, $this->combinerCallback );
 
                $firstOutput = $rr->getRevisionParserOutput();
-               $mainOutput = $rr->getSlotParserOutput( 'main' );
+               $mainOutput = $rr->getSlotParserOutput( SlotRecord::MAIN );
                $auxOutput = $rr->getSlotParserOutput( 'aux' );
 
                // emulate a saved revision
                $savedRev = new MutableRevisionRecord( $title );
-               $savedRev->setContent( 'main', new WikitextContent( $text ) );
+               $savedRev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
                $savedRev->setContent( 'aux', new WikitextContent( '[[Goats]]' ) );
                $savedRev->setId( 23 ); // saved, new
                $savedRev->setUser( new UserIdentityValue( 9, 'Frank', 0 ) );
@@ -547,7 +548,7 @@ class RenderedRevisionTest extends MediaWikiTestCase {
 
                $rr->updateRevision( $savedRev );
 
-               $this->assertNotSame( $mainOutput, $rr->getSlotParserOutput( 'main' ), 'Reset main' );
+               $this->assertNotSame( $mainOutput, $rr->getSlotParserOutput( SlotRecord::MAIN ), 'Reset main' );
                $this->assertSame( $auxOutput, $rr->getSlotParserOutput( 'aux' ), 'Keep aux' );
 
                $updatedOutput = $rr->getRevisionParserOutput();
index 28052ff..ca13899 100644 (file)
@@ -9,6 +9,7 @@ use LogicException;
 use MediaWiki\Revision\RevisionRenderer;
 use MediaWiki\Storage\MutableRevisionRecord;
 use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
 use MediaWiki\User\UserIdentityValue;
 use MediaWikiTestCase;
 use ParserOptions;
@@ -153,7 +154,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $text .= "* time:{{REVISIONTIMESTAMP}}\n";
                $text .= "* [[Link It]]\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = $renderer->getRenderedRevision( $rev, $options );
@@ -170,7 +171,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $this->assertContains( 'user:Frank', $html );
                $this->assertContains( 'time:20180101000003', $html );
 
-               $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+               $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
        }
 
        public function testGetRenderedRevision_current() {
@@ -189,7 +190,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $text .= "* user:{{REVISIONUSER}}\n";
                $text .= "* time:{{REVISIONTIMESTAMP}}\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = $renderer->getRenderedRevision( $rev, $options );
@@ -206,7 +207,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $this->assertContains( 'user:Frank', $html );
                $this->assertContains( 'time:20180101000003', $html );
 
-               $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+               $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
        }
 
        public function testGetRenderedRevision_master() {
@@ -225,7 +226,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $text .= "* user:{{REVISIONUSER}}\n";
                $text .= "* time:{{REVISIONTIMESTAMP}}\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = $renderer->getRenderedRevision( $rev, $options, null, [ 'use-master' => true ] );
@@ -236,7 +237,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
 
                $this->assertContains( 'rev:21', $html );
 
-               $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+               $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
        }
 
        public function testGetRenderedRevision_old() {
@@ -255,7 +256,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $text .= "* user:{{REVISIONUSER}}\n";
                $text .= "* time:{{REVISIONTIMESTAMP}}\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = $renderer->getRenderedRevision( $rev, $options );
@@ -292,7 +293,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $text .= "* user:{{REVISIONUSER}}\n";
                $text .= "* time:{{REVISIONTIMESTAMP}}\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = $renderer->getRenderedRevision( $rev, $options );
@@ -317,7 +318,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $text .= "* user:{{REVISIONUSER}}\n";
                $text .= "* time:{{REVISIONTIMESTAMP}}\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $sysop = $this->getTestUser( [ 'sysop' ] )->getUser(); // privileged!
@@ -356,7 +357,7 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $text .= "* user:{{REVISIONUSER}}\n";
                $text .= "* time:{{REVISIONTIMESTAMP}}\n";
 
-               $rev->setContent( 'main', new WikitextContent( $text ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $options = ParserOptions::newCanonical( 'canonical' );
                $rr = $renderer->getRenderedRevision(
@@ -391,13 +392,13 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $rev->setTimestamp( '20180101000003' );
                $rev->setComment( CommentStoreComment::newUnsavedComment( '' ) );
 
-               $rev->setContent( 'main', new WikitextContent( '[[Kittens]]' ) );
+               $rev->setContent( SlotRecord::MAIN, new WikitextContent( '[[Kittens]]' ) );
                $rev->setContent( 'aux', new WikitextContent( '[[Goats]]' ) );
 
                $rr = $renderer->getRenderedRevision( $rev );
 
                $combinedOutput = $rr->getRevisionParserOutput();
-               $mainOutput = $rr->getSlotParserOutput( 'main' );
+               $mainOutput = $rr->getSlotParserOutput( SlotRecord::MAIN );
                $auxOutput = $rr->getSlotParserOutput( 'aux' );
 
                $combinedHtml = $combinedOutput->getText();
@@ -453,13 +454,13 @@ class RevisionRendererTest extends MediaWikiTestCase {
                $title = $this->getMockTitle( 7, 21 );
 
                $rev = new MutableRevisionRecord( $title );
-               $rev->setContent( 'main', $mockContent );
+               $rev->setContent( SlotRecord::MAIN, $mockContent );
                $rev->setContent( 'aux', $mockContent );
 
                // NOTE: we are testing the private combineSlotOutput() callback here.
                $rr = $renderer->getRenderedRevision( $rev );
 
-               $output = $rr->getSlotParserOutput( 'main', [ 'generate-html' => false ] );
+               $output = $rr->getSlotParserOutput( SlotRecord::MAIN, [ 'generate-html' => false ] );
                $this->assertFalse( $output->hasText(), 'hasText' );
 
                $output = $rr->getRevisionParserOutput( [ 'generate-html' => false ] );
index 8bf87a2..28e6e12 100644 (file)
@@ -259,7 +259,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                // getTextId() must be an int!
                $this->assertInternalType( 'integer', $rev->getTextId() );
 
-               $mainSlot = $rev->getRevisionRecord()->getSlot( 'main', RevisionRecord::RAW );
+               $mainSlot = $rev->getRevisionRecord()->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
 
                // we currently only support storage in the text table
                $textId = MediaWikiServices::getInstance()
@@ -1581,7 +1581,7 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase {
                        'slot_content_id' => 1,
                        'content_address' => 'tt:789',
                        'model_name' => CONTENT_MODEL_WIKITEXT,
-                       'role_name' => 'main',
+                       'role_name' => SlotRecord::MAIN,
                        'slot_origin' => 1,
                ], new WikitextContent( 'Test' ) );
 
index 3e4746a..f5bc4fa 100644 (file)
@@ -35,7 +35,7 @@ class RevisionMcrDbTest extends RevisionDbTestBase {
                        'slot_content_id' => 1,
                        'content_address' => 'tt:789',
                        'model_name' => CONTENT_MODEL_WIKITEXT,
-                       'role_name' => 'main',
+                       'role_name' => SlotRecord::MAIN,
                        'slot_origin' => 1,
                ], new WikitextContent( 'Test' ) );
 
index b446a8c..7218466 100644 (file)
@@ -31,7 +31,7 @@ class RevisionMcrReadNewDbTest extends RevisionDbTestBase {
                        'slot_content_id' => 1,
                        'content_address' => 'tt:789',
                        'model_name' => CONTENT_MODEL_WIKITEXT,
-                       'role_name' => 'main',
+                       'role_name' => SlotRecord::MAIN,
                        'slot_origin' => 1,
                ], new WikitextContent( 'Test' ) );
 
index 6359995..c470787 100644 (file)
@@ -931,7 +931,7 @@ class RevisionTest extends MediaWikiTestCase {
                $this->assertNull( $rev->getContent(), 'Content of no slots is null' );
 
                $content = new TextContent( 'Hello Kittens!' );
-               $rec->setContent( 'main', $content );
+               $rec->setContent( SlotRecord::MAIN, $content );
                $this->assertSame( $content, $rev->getContent() );
        }
 
index 8b472d4..7931236 100644 (file)
@@ -115,7 +115,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $mainContent = new WikitextContent( 'Lorem ipsum' );
 
                $update = new RevisionSlotsUpdate();
-               $update->modifyContent( 'main', $mainContent );
+               $update->modifyContent( SlotRecord::MAIN, $mainContent );
                $updater = $this->getDerivedPageDataUpdater( $page );
                $updater->prepareContent( $user, $update, false );
 
@@ -194,7 +194,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                );
 
                $update = new RevisionSlotsUpdate();
-               $update->modifyContent( 'main', $mainContent );
+               $update->modifyContent( SlotRecord::MAIN, $mainContent );
                $update->modifySlot( SlotRecord::newInherited( $auxSlot ) );
                // TODO: MCR: test removing slots!
 
@@ -220,7 +220,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $this->assertEquals( [ 'main', 'aux' ], $updater->getModifiedSlotRoles() );
                $this->assertEquals( [ 'main', 'aux' ], $updater->getTouchedSlotRoles() );
 
-               $mainSlot = $updater->getRawSlot( 'main' );
+               $mainSlot = $updater->getRawSlot( SlotRecord::MAIN );
                $this->assertInstanceOf( SlotRecord::class, $mainSlot );
                $this->assertNotContains( '~~~', $mainSlot->getContent()->serialize(), 'PST should apply.' );
                $this->assertContains( $sysop->getName(), $mainSlot->getContent()->serialize() );
@@ -255,12 +255,12 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $mainContent2 = new WikitextContent( 'second ({{subst:REVISIONUSER}}) #~~~#' );
 
                $rev = $this->createRevision( $page, 'first', $mainContent1 );
-               $mainContent1 = $rev->getContent( 'main' ); // get post-pst content
+               $mainContent1 = $rev->getContent( SlotRecord::MAIN ); // get post-pst content
                $userName = $rev->getUser()->getName();
                $sysopName = $sysop->getName();
 
                $update = new RevisionSlotsUpdate();
-               $update->modifyContent( 'main', $mainContent1 );
+               $update->modifyContent( SlotRecord::MAIN, $mainContent1 );
                $updater1 = $this->getDerivedPageDataUpdater( $page );
                $updater1->prepareContent( $sysop, $update, false );
 
@@ -283,12 +283,12 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
 
                // TODO: MCR: test inheritance from parent
                $update = new RevisionSlotsUpdate();
-               $update->modifyContent( 'main', $mainContent2 );
+               $update->modifyContent( SlotRecord::MAIN, $mainContent2 );
                $updater2 = $this->getDerivedPageDataUpdater( $page );
                $updater2->prepareContent( $sysop, $update, false );
 
                // non-null edit use the new user name in PST
-               $pstText = $updater2->getSlots()->getContent( 'main' )->serialize();
+               $pstText = $updater2->getSlots()->getContent( SlotRecord::MAIN )->serialize();
                $this->assertNotContains( '{{subst:REVISIONUSER}}', $pstText, '{{subst:REVISIONUSER}}' );
                $this->assertNotContains( '~~~', $pstText, 'signature ~~~' );
                $this->assertContains( '(' . $sysopName . ')', $pstText, '{{subst:REVISIONUSER}}' );
@@ -342,8 +342,8 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
 
                // TODO: MCR: test multiple slots, test slot removal!
 
-               $this->assertInstanceOf( SlotRecord::class, $updater1->getRawSlot( 'main' ) );
-               $this->assertNotContains( '~~~~', $updater1->getRawContent( 'main' )->serialize() );
+               $this->assertInstanceOf( SlotRecord::class, $updater1->getRawSlot( SlotRecord::MAIN ) );
+               $this->assertNotContains( '~~~~', $updater1->getRawContent( SlotRecord::MAIN )->serialize() );
 
                $mainOutput = $updater1->getCanonicalParserOutput();
                $this->assertContains( 'first', $mainOutput->getText() );
@@ -379,11 +379,11 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $mainContent1 = new WikitextContent( 'first [[main]] ~~~' );
 
                $update = new RevisionSlotsUpdate();
-               $update->modifyContent( 'main', $mainContent1 );
+               $update->modifyContent( SlotRecord::MAIN, $mainContent1 );
                $updater = $this->getDerivedPageDataUpdater( $page );
                $updater->prepareContent( $user, $update, false );
 
-               $mainOutput = $updater->getSlotParserOutput( 'main' );
+               $mainOutput = $updater->getSlotParserOutput( SlotRecord::MAIN );
                $canonicalOutput = $updater->getCanonicalParserOutput();
 
                $rev = $this->createRevision( $page, 'first', $mainContent1 );
@@ -394,7 +394,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $this->assertTrue( $updater->isUpdatePrepared() );
                $this->assertTrue( $updater->isContentPrepared() );
 
-               $this->assertSame( $mainOutput, $updater->getSlotParserOutput( 'main' ) );
+               $this->assertSame( $mainOutput, $updater->getSlotParserOutput( SlotRecord::MAIN ) );
                $this->assertSame( $canonicalOutput, $updater->getCanonicalParserOutput() );
        }
 
@@ -409,11 +409,11 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $mainContent1 = new WikitextContent( 'first --{{REVISIONID}}--' );
 
                $update = new RevisionSlotsUpdate();
-               $update->modifyContent( 'main', $mainContent1 );
+               $update->modifyContent( SlotRecord::MAIN, $mainContent1 );
                $updater = $this->getDerivedPageDataUpdater( $page );
                $updater->prepareContent( $user, $update, false );
 
-               $mainOutput = $updater->getSlotParserOutput( 'main' );
+               $mainOutput = $updater->getSlotParserOutput( SlotRecord::MAIN );
                $canonicalOutput = $updater->getCanonicalParserOutput();
 
                // prevent optimization on matching speculative ID
@@ -429,7 +429,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $this->assertTrue( $updater->isContentPrepared() );
 
                // ParserOutput objects should have been flushed.
-               $this->assertNotSame( $mainOutput, $updater->getSlotParserOutput( 'main' ) );
+               $this->assertNotSame( $mainOutput, $updater->getSlotParserOutput( SlotRecord::MAIN ) );
                $this->assertNotSame( $canonicalOutput, $updater->getCanonicalParserOutput() );
 
                $html = $updater->getCanonicalParserOutput()->getText();
@@ -450,7 +450,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
 
                $mainContent = new WikitextContent( 'first [[main]] ~~~' );
                $update = new RevisionSlotsUpdate();
-               $update->modifyContent( 'main', $mainContent );
+               $update->modifyContent( SlotRecord::MAIN, $mainContent );
 
                $updater = $this->getDerivedPageDataUpdater( __METHOD__ );
                $updater->prepareContent( $user, $update, false );
@@ -461,7 +461,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $this->assertSame( $canonicalOutput->getCacheTime(), $preparedEdit->timestamp );
                $this->assertSame( $canonicalOutput, $preparedEdit->output );
                $this->assertSame( $mainContent, $preparedEdit->newContent );
-               $this->assertSame( $updater->getRawContent( 'main' ), $preparedEdit->pstContent );
+               $this->assertSame( $updater->getRawContent( SlotRecord::MAIN ), $preparedEdit->pstContent );
                $this->assertSame( $updater->getCanonicalParserOptions(), $preparedEdit->popts );
                $this->assertSame( null, $preparedEdit->revid );
        }
@@ -474,7 +474,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
 
                $mainContent = new WikitextContent( 'first [[main]] ~~~' );
                $update = new MutableRevisionSlots();
-               $update->setContent( 'main', $mainContent );
+               $update->setContent( SlotRecord::MAIN, $mainContent );
 
                $rev = $this->createRevision( $page, __METHOD__ );
 
@@ -486,7 +486,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $preparedEdit = $updater->getPreparedEdit();
                $this->assertSame( $canonicalOutput->getCacheTime(), $preparedEdit->timestamp );
                $this->assertSame( $canonicalOutput, $preparedEdit->output );
-               $this->assertSame( $updater->getRawContent( 'main' ), $preparedEdit->pstContent );
+               $this->assertSame( $updater->getRawContent( SlotRecord::MAIN ), $preparedEdit->pstContent );
                $this->assertSame( $updater->getCanonicalParserOptions(), $preparedEdit->popts );
                $this->assertSame( $rev->getId(), $preparedEdit->revid );
        }
@@ -499,7 +499,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $mainContent1 = new WikitextContent( 'first' );
 
                $update = new RevisionSlotsUpdate();
-               $update->modifyContent( 'main', $mainContent1 );
+               $update->modifyContent( SlotRecord::MAIN, $mainContent1 );
                $updater = $this->getDerivedPageDataUpdater( $page );
                $updater->prepareContent( $user, $update, false );
 
@@ -595,7 +595,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                );
 
                $update = new RevisionSlotsUpdate();
-               $update->modifyContent( 'main', $mainContent2 );
+               $update->modifyContent( SlotRecord::MAIN, $mainContent2 );
                $update->removeSlot( 'aux' );
 
                $page = $this->getPage( __METHOD__ );
@@ -676,13 +676,13 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $content2 = new WikitextContent( 'two' );
 
                $update1 = new RevisionSlotsUpdate();
-               $update1->modifyContent( 'main', $content1 );
+               $update1->modifyContent( SlotRecord::MAIN, $content1 );
 
                $update1b = new RevisionSlotsUpdate();
                $update1b->modifyContent( 'xyz', $content1 );
 
                $update2 = new RevisionSlotsUpdate();
-               $update2->modifyContent( 'main', $content2 );
+               $update2->modifyContent( SlotRecord::MAIN, $content2 );
 
                $rev1 = $this->makeRevision( $title, $update1, $user1, 'rev1', 11 );
                $rev1b = $this->makeRevision( $title, $update1b, $user1, 'rev1', 11 );
index 48bf4aa..3e91df4 100644 (file)
@@ -51,7 +51,7 @@ class MutableRevisionRecordTest extends MediaWikiTestCase {
                        $record->setPageId( $rowOverrides['rev_page'] );
                }
 
-               $record->setContent( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $record->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
                $record->setComment( $comment );
                $record->setUser( $user );
                $record->setTimestamp( '20101010000000' );
@@ -141,33 +141,33 @@ class MutableRevisionRecordTest extends MediaWikiTestCase {
        public function testGetMainContentWhenEmpty() {
                $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
                $this->setExpectedException( RevisionAccessException::class );
-               $this->assertNull( $record->getContent( 'main' ) );
+               $this->assertNull( $record->getContent( SlotRecord::MAIN ) );
        }
 
        public function testSetGetMainContent() {
                $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
                $content = new WikitextContent( 'Badger' );
-               $record->setContent( 'main', $content );
-               $this->assertSame( $content, $record->getContent( 'main' ) );
+               $record->setContent( SlotRecord::MAIN, $content );
+               $this->assertSame( $content, $record->getContent( SlotRecord::MAIN ) );
        }
 
        public function testGetSlotWhenEmpty() {
                $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
-               $this->assertFalse( $record->hasSlot( 'main' ) );
+               $this->assertFalse( $record->hasSlot( SlotRecord::MAIN ) );
 
                $this->setExpectedException( RevisionAccessException::class );
-               $record->getSlot( 'main' );
+               $record->getSlot( SlotRecord::MAIN );
        }
 
        public function testSetGetSlot() {
                $record = new MutableRevisionRecord( Title::newFromText( 'Foo' ) );
                $slot = SlotRecord::newUnsaved(
-                       'main',
+                       SlotRecord::MAIN,
                        new WikitextContent( 'x' )
                );
                $record->setSlot( $slot );
-               $this->assertTrue( $record->hasSlot( 'main' ) );
-               $this->assertSame( $slot, $record->getSlot( 'main' ) );
+               $this->assertTrue( $record->hasSlot( SlotRecord::MAIN ) );
+               $this->assertSame( $slot, $record->getSlot( SlotRecord::MAIN ) );
        }
 
        public function testSetGetMinor() {
@@ -249,7 +249,7 @@ class MutableRevisionRecordTest extends MediaWikiTestCase {
                $record->setSlot( $auxSlot );
 
                $this->assertSame( [ 'main' ], $record->getOriginalSlots()->getSlotRoles() );
-               $this->assertSame( $mainSlot, $record->getOriginalSlots()->getSlot( 'main' ) );
+               $this->assertSame( $mainSlot, $record->getOriginalSlots()->getSlot( SlotRecord::MAIN ) );
 
                $this->assertSame( [ 'aux' ], $record->getInheritedSlots()->getSlotRoles() );
                $this->assertSame( $auxSlot, $record->getInheritedSlots()->getSlot( 'aux' ) );
@@ -314,7 +314,7 @@ class MutableRevisionRecordTest extends MediaWikiTestCase {
                yield 'empty' => [ $rev ];
 
                $rev = new MutableRevisionRecord( $title );
-               $rev->setContent( 'main', $content );
+               $rev->setContent( SlotRecord::MAIN, $content );
                $rev->setUser( $user );
                $rev->setComment( $comment );
                yield 'no timestamp' => [ $rev ];
@@ -326,14 +326,14 @@ class MutableRevisionRecordTest extends MediaWikiTestCase {
                yield 'no content' => [ $rev ];
 
                $rev = new MutableRevisionRecord( $title );
-               $rev->setContent( 'main', $content );
+               $rev->setContent( SlotRecord::MAIN, $content );
                $rev->setComment( $comment );
                $rev->setTimestamp( '20101010000000' );
                yield 'no user' => [ $rev ];
 
                $rev = new MutableRevisionRecord( $title );
                $rev->setUser( $user );
-               $rev->setContent( 'main', $content );
+               $rev->setContent( SlotRecord::MAIN, $content );
                $rev->setTimestamp( '20101010000000' );
                yield 'no comment' => [ $rev ];
        }
index 5a83143..1ef0121 100644 (file)
@@ -65,14 +65,14 @@ class MutableRevisionSlotsTest extends RevisionSlotsTest {
 
                $this->assertSame( [], $slots->getSlots() );
 
-               $slotA = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $slots->setSlot( $slotA );
-               $this->assertSame( $slotA, $slots->getSlot( 'main' ) );
+               $this->assertSame( $slotA, $slots->getSlot( SlotRecord::MAIN ) );
                $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
 
-               $slotB = SlotRecord::newUnsaved( 'main', new WikitextContent( 'B' ) );
+               $slotB = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'B' ) );
                $slots->setSlot( $slotB );
-               $this->assertSame( $slotB, $slots->getSlot( 'main' ) );
+               $this->assertSame( $slotB, $slots->getSlot( SlotRecord::MAIN ) );
                $this->assertSame( [ 'main' => $slotB ], $slots->getSlots() );
        }
 
@@ -87,18 +87,18 @@ class MutableRevisionSlotsTest extends RevisionSlotsTest {
 
        public function testInheritSlotOverwritesSlot() {
                $slots = new MutableRevisionSlots();
-               $slotA = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $slots->setSlot( $slotA );
-               $slotB = $this->newSavedSlot( 'main', new WikitextContent( 'B' ) );
+               $slotB = $this->newSavedSlot( SlotRecord::MAIN, new WikitextContent( 'B' ) );
                $slotC = $this->newSavedSlot( 'foo', new WikitextContent( 'C' ) );
                $slots->inheritSlot( $slotB );
                $slots->inheritSlot( $slotC );
                $this->assertSame( [ 'main', 'foo' ], $slots->getSlotRoles() );
-               $this->assertNotSame( $slotB, $slots->getSlot( 'main' ) );
+               $this->assertNotSame( $slotB, $slots->getSlot( SlotRecord::MAIN ) );
                $this->assertNotSame( $slotC, $slots->getSlot( 'foo' ) );
-               $this->assertTrue( $slots->getSlot( 'main' )->isInherited() );
+               $this->assertTrue( $slots->getSlot( SlotRecord::MAIN )->isInherited() );
                $this->assertTrue( $slots->getSlot( 'foo' )->isInherited() );
-               $this->assertSame( $slotB->getContent(), $slots->getSlot( 'main' )->getContent() );
+               $this->assertSame( $slotB->getContent(), $slots->getSlot( SlotRecord::MAIN )->getContent() );
                $this->assertSame( $slotC->getContent(), $slots->getSlot( 'foo' )->getContent() );
        }
 
@@ -107,26 +107,26 @@ class MutableRevisionSlotsTest extends RevisionSlotsTest {
 
                $this->assertSame( [], $slots->getSlots() );
 
-               $slotA = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $slots->setSlot( $slotA );
-               $this->assertSame( $slotA, $slots->getSlot( 'main' ) );
+               $this->assertSame( $slotA, $slots->getSlot( SlotRecord::MAIN ) );
                $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
 
                $newContent = new WikitextContent( 'B' );
-               $slots->setContent( 'main', $newContent );
-               $this->assertSame( $newContent, $slots->getContent( 'main' ) );
+               $slots->setContent( SlotRecord::MAIN, $newContent );
+               $this->assertSame( $newContent, $slots->getContent( SlotRecord::MAIN ) );
        }
 
        public function testRemoveExistingSlot() {
-               $slotA = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $slots = new MutableRevisionSlots( [ $slotA ] );
 
                $this->assertSame( [ 'main' => $slotA ], $slots->getSlots() );
 
-               $slots->removeSlot( 'main' );
+               $slots->removeSlot( SlotRecord::MAIN );
                $this->assertSame( [], $slots->getSlots() );
                $this->setExpectedException( RevisionAccessException::class );
-               $slots->getSlot( 'main' );
+               $slots->getSlot( SlotRecord::MAIN );
        }
 
        public function testNewFromParentRevisionSlots() {
index 1d504de..7e1e1ee 100644 (file)
@@ -135,7 +135,7 @@ class NoContentModelRevisionStoreDbTest extends RevisionStoreDbTestBase {
                                                'slot_revision_id' => 'slots.rev_id',
                                                'slot_content_id' => 'NULL',
                                                'slot_origin' => 'slots.rev_id',
-                                               'role_name' => $db->addQuotes( 'main' ),
+                                               'role_name' => $db->addQuotes( SlotRecord::MAIN ),
                                        ]
                                ),
                                'joins' => [],
@@ -152,7 +152,7 @@ class NoContentModelRevisionStoreDbTest extends RevisionStoreDbTestBase {
                                                'slot_revision_id' => 'slots.rev_id',
                                                'slot_content_id' => 'NULL',
                                                'slot_origin' => 'slots.rev_id',
-                                               'role_name' => $db->addQuotes( 'main' ),
+                                               'role_name' => $db->addQuotes( SlotRecord::MAIN ),
                                                'content_size' => 'slots.rev_len',
                                                'content_sha1' => 'slots.rev_sha1',
                                                'content_address' =>
index 81f726c..3933986 100644 (file)
@@ -6,6 +6,7 @@ use CommentStoreComment;
 use Content;
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
 use MediaWikiTestCase;
 use ParserOptions;
 use RecentChange;
@@ -72,7 +73,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                // TODO: MCR: test additional slots
                $content = new TextContent( 'Lorem Ipsum' );
-               $updater->setContent( 'main', $content );
+               $updater->setContent( SlotRecord::MAIN, $content );
 
                $parent = $updater->grabParentRevision();
 
@@ -102,7 +103,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                $this->assertInstanceOf( Revision::class, $updater->getStatus()->value['revision'] );
 
                $rev = $updater->getNewRevision();
-               $revContent = $rev->getContent( 'main' );
+               $revContent = $rev->getContent( SlotRecord::MAIN );
                $this->assertSame( 'Lorem Ipsum', $revContent->serialize(), 'revision content' );
 
                // were the WikiPage and Title objects updated?
@@ -128,7 +129,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                // re-edit with same content - should be a "null-edit"
                $updater = $page->newPageUpdater( $user );
-               $updater->setContent( 'main', $content );
+               $updater->setContent( SlotRecord::MAIN, $content );
 
                $summary = CommentStoreComment::newUnsavedComment( 'to to re-edit' );
                $rev = $updater->saveRevision( $summary );
@@ -167,7 +168,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                $this->assertTrue( $updater->hasEditConflict( 0 ), 'hasEditConflict' );
 
                // TODO: MCR: test additional slots
-               $updater->setContent( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
 
                // TODO: test all flags for saveRevision()!
                $summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
@@ -189,7 +190,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                // TODO: Test null revision (with different user): new revision!
 
                $rev = $updater->getNewRevision();
-               $revContent = $rev->getContent( 'main' );
+               $revContent = $rev->getContent( SlotRecord::MAIN );
                $this->assertSame( 'Lorem Ipsum', $revContent->serialize(), 'revision content' );
 
                // were the WikiPage and Title objects updated?
@@ -210,7 +211,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                // re-edit
                $updater = $page->newPageUpdater( $user );
-               $updater->setContent( 'main', new TextContent( 'dolor sit amet' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'dolor sit amet' ) );
 
                $summary = CommentStoreComment::newUnsavedComment( 're-edit' );
                $updater->saveRevision( $summary );
@@ -242,7 +243,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                }
 
                $updater = $page->newPageUpdater( $user );
-               $updater->setContent( 'main', $content );
+               $updater->setContent( SlotRecord::MAIN, $content );
                $rev = $updater->saveRevision( $comment );
                return $rev;
        }
@@ -267,7 +268,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                // try creating the page - should trigger CAS failure.
                $summary = CommentStoreComment::newUnsavedComment( 'create?!' );
-               $updater->setContent( 'main', new TextContent( 'Lorem ipsum' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum' ) );
                $updater->saveRevision( $summary );
                $status = $updater->getStatus();
 
@@ -287,7 +288,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                // try creating the page - should trigger CAS failure.
                $summary = CommentStoreComment::newUnsavedComment( 'edit?!' );
-               $updater->setContent( 'main', new TextContent( 'dolor sit amet' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'dolor sit amet' ) );
                $updater->saveRevision( $summary );
                $status = $updater->getStatus();
 
@@ -311,7 +312,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                // update with EDIT_UPDATE flag should fail
                $summary = CommentStoreComment::newUnsavedComment( 'udpate?!' );
-               $updater->setContent( 'main', new TextContent( 'Lorem ipsum' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum' ) );
                $updater->saveRevision( $summary, EDIT_UPDATE );
                $status = $updater->getStatus();
 
@@ -326,7 +327,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                // update with EDIT_NEW flag should fail
                $summary = CommentStoreComment::newUnsavedComment( 'create?!' );
                $updater = $page->newPageUpdater( $user );
-               $updater->setContent( 'main', new TextContent( 'dolor sit amet' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'dolor sit amet' ) );
                $updater->saveRevision( $summary, EDIT_NEW );
                $status = $updater->getStatus();
 
@@ -356,7 +357,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                $updater = $page->newPageUpdater( $user );
 
                $summary = CommentStoreComment::newUnsavedComment( 'Lorem ipsum ' . $patrolled );
-               $updater->setContent( 'main', new TextContent( 'Lorem ipsum ' . $patrolled ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum ' . $patrolled ) );
                $updater->setRcPatrolStatus( $patrolled );
                $rev = $updater->saveRevision( $summary );
 
@@ -375,24 +376,24 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                $updater = $page->newPageUpdater( $user );
                $summary = CommentStoreComment::newUnsavedComment( 'one' );
-               $updater->setContent( 'main', new TextContent( 'Lorem ipsum' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum' ) );
                $rev1 = $updater->saveRevision( $summary, EDIT_NEW );
 
                $updater = $page->newPageUpdater( $user );
                $summary = CommentStoreComment::newUnsavedComment( 'two' );
-               $updater->setContent( 'main', new TextContent( 'Foo Bar' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'Foo Bar' ) );
                $rev2 = $updater->saveRevision( $summary, EDIT_UPDATE );
 
                $updater = $page->newPageUpdater( $user );
                $summary = CommentStoreComment::newUnsavedComment( 'three' );
-               $updater->inheritSlot( $rev1->getSlot( 'main' ) );
+               $updater->inheritSlot( $rev1->getSlot( SlotRecord::MAIN ) );
                $rev3 = $updater->saveRevision( $summary, EDIT_UPDATE );
 
                $this->assertNotSame( $rev1->getId(), $rev3->getId() );
                $this->assertNotSame( $rev2->getId(), $rev3->getId() );
 
-               $main1 = $rev1->getSlot( 'main' );
-               $main3 = $rev3->getSlot( 'main' );
+               $main1 = $rev1->getSlot( SlotRecord::MAIN );
+               $main3 = $rev3->getSlot( SlotRecord::MAIN );
 
                $this->assertNotSame( $main1->getRevision(), $main3->getRevision() );
                $this->assertSame( $main1->getAddress(), $main3->getAddress() );
@@ -410,7 +411,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                $updater = $page->newPageUpdater( $user );
                $updater->setUseAutomaticEditSummaries( true );
-               $updater->setContent( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
 
                // empty comment triggers auto-summary
                $summary = CommentStoreComment::newUnsavedComment( '' );
@@ -423,7 +424,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                // check that this also works when blanking the page
                $updater = $page->newPageUpdater( $user );
                $updater->setUseAutomaticEditSummaries( true );
-               $updater->setContent( 'main', new TextContent( '' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( '' ) );
 
                $summary = CommentStoreComment::newUnsavedComment( '' );
                $updater->saveRevision( $summary, EDIT_AUTOSUMMARY );
@@ -438,7 +439,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                $updater = $page2->newPageUpdater( $user );
                $updater->setUseAutomaticEditSummaries( false );
-               $updater->setContent( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
 
                $summary = CommentStoreComment::newUnsavedComment( '' );
                $updater->saveRevision( $summary, EDIT_AUTOSUMMARY );
@@ -450,7 +451,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                // check that we don't do auto.summaries without the EDIT_AUTOSUMMARY flag
                $updater = $page2->newPageUpdater( $user );
                $updater->setUseAutomaticEditSummaries( true );
-               $updater->setContent( 'main', new TextContent( '' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( '' ) );
 
                $summary = CommentStoreComment::newUnsavedComment( '' );
                $updater->saveRevision( $summary, 0 );
@@ -477,7 +478,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                $updater = $page->newPageUpdater( $user );
                $updater->setUsePageCreationLog( $use );
                $summary = CommentStoreComment::newUnsavedComment( 'cmt' );
-               $updater->setContent( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
                $updater->saveRevision( $summary, EDIT_NEW );
 
                $rev = $updater->getNewRevision();
@@ -555,7 +556,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
                $page = WikiPage::factory( $title );
                $updater = $page->newPageUpdater( $user );
 
-               $updater->setContent( 'main', new \WikitextContent( $wikitext ) );
+               $updater->setContent( SlotRecord::MAIN, new \WikitextContent( $wikitext ) );
 
                $summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
                $rev = $updater->saveRevision( $summary, EDIT_UPDATE );
@@ -568,7 +569,7 @@ class PageUpdaterTest extends MediaWikiTestCase {
 
                $output = $page->getParserOutput( ParserOptions::newCanonical( 'canonical' ) );
                $html = $output->getText();
-               $text = $rev->getContent( 'main' )->serialize();
+               $text = $rev->getContent( SlotRecord::MAIN )->serialize();
 
                if ( $subst ) {
                        $this->assertContains( $expected, $text, 'In Wikitext' );
index f959d68..fad6228 100644 (file)
@@ -34,7 +34,7 @@ class RevisionArchiveRecordTest extends MediaWikiTestCase {
                $user = new UserIdentityValue( 11, 'Tester', 0 );
                $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
 
-               $main = SlotRecord::newUnsaved( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
                $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
                $slots = new RevisionSlots( [ $main, $aux ] );
 
@@ -65,7 +65,7 @@ class RevisionArchiveRecordTest extends MediaWikiTestCase {
                $user = new UserIdentityValue( 11, 'Tester', 0 );
                $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
 
-               $main = SlotRecord::newUnsaved( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
                $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
                $slots = new RevisionSlots( [ $main, $aux ] );
 
@@ -197,7 +197,7 @@ class RevisionArchiveRecordTest extends MediaWikiTestCase {
 
                $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
 
-               $main = SlotRecord::newUnsaved( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
                $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
                $slots = new RevisionSlots( [ $main, $aux ] );
 
index 7f56c3a..165c27b 100644 (file)
@@ -2,6 +2,7 @@
 namespace MediaWiki\Tests\Storage;
 
 use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\SlotRecord;
 use MediaWikiTestCase;
 use Revision;
 
@@ -737,7 +738,7 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
                                                'slot_revision_id' => 'slots.rev_id',
                                                'slot_content_id' => 'NULL',
                                                'slot_origin' => 'slots.rev_id',
-                                               'role_name' => $db->addQuotes( 'main' ),
+                                               'role_name' => $db->addQuotes( SlotRecord::MAIN ),
                                        ]
                                ),
                                'joins' => [],
@@ -758,7 +759,7 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
                                                'slot_revision_id' => 'slots.rev_id',
                                                'slot_content_id' => 'NULL',
                                                'slot_origin' => 'slots.rev_id',
-                                               'role_name' => $db->addQuotes( 'main' ),
+                                               'role_name' => $db->addQuotes( SlotRecord::MAIN ),
                                                'content_size' => 'slots.rev_len',
                                                'content_sha1' => 'slots.rev_sha1',
                                                'content_address' => $db->buildConcat( [
@@ -784,7 +785,7 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
                                                'slot_revision_id' => 'slots.rev_id',
                                                'slot_content_id' => 'NULL',
                                                'slot_origin' => 'slots.rev_id',
-                                               'role_name' => $db->addQuotes( 'main' ),
+                                               'role_name' => $db->addQuotes( SlotRecord::MAIN ),
                                                'content_size' => 'slots.rev_len',
                                                'content_sha1' => 'slots.rev_sha1',
                                                'content_address' => $db->buildConcat( [
@@ -810,7 +811,7 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
                                                'slot_revision_id' => 'slots.rev_id',
                                                'slot_content_id' => 'NULL',
                                                'slot_origin' => 'slots.rev_id',
-                                               'role_name' => $db->addQuotes( 'main' ),
+                                               'role_name' => $db->addQuotes( SlotRecord::MAIN ),
                                        ]
                                ),
                                'joins' => [],
@@ -831,7 +832,7 @@ class RevisionQueryInfoTest extends MediaWikiTestCase {
                                                'slot_revision_id' => 'slots.rev_id',
                                                'slot_content_id' => 'NULL',
                                                'slot_origin' => 'slots.rev_id',
-                                               'role_name' => $db->addQuotes( 'main' ),
+                                               'role_name' => $db->addQuotes( SlotRecord::MAIN ),
                                                'content_size' => 'slots.rev_len',
                                                'content_sha1' => 'slots.rev_sha1',
                                                'content_address' =>
index 20270d0..901b800 100644 (file)
@@ -189,17 +189,18 @@ trait RevisionRecordTests {
                $rev = $this->newRevision( [ 'rev_deleted' => $visibility ] );
 
                // NOTE: slot meta-data is never suppressed, just the content is!
-               $this->assertTrue( $rev->hasSlot( 'main' ), 'hasSlot is never suppressed' );
-               $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::RAW ), 'raw meta' );
-               $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC ), 'public meta' );
+               $this->assertTrue( $rev->hasSlot( SlotRecord::MAIN ), 'hasSlot is never suppressed' );
+               $this->assertNotNull( $rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW ), 'raw meta' );
+               $this->assertNotNull( $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC ),
+                       'public meta' );
 
                $this->assertNotNull(
-                       $rev->getSlot( 'main', RevisionRecord::FOR_THIS_USER, $user ),
+                       $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $user ),
                        'user can'
                );
 
                try {
-                       $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC )->getContent();
+                       $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC )->getContent();
                        $exception = null;
                } catch ( SuppressedDataException $ex ) {
                        $exception = $ex;
@@ -212,7 +213,7 @@ trait RevisionRecordTests {
                );
 
                try {
-                       $rev->getSlot( 'main', RevisionRecord::FOR_THIS_USER, $user )->getContent();
+                       $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $user )->getContent();
                        $exception = null;
                } catch ( SuppressedDataException $ex ) {
                        $exception = $ex;
@@ -234,16 +235,16 @@ trait RevisionRecordTests {
                $user = $this->getTestUser( $groups )->getUser();
                $rev = $this->newRevision( [ 'rev_deleted' => $visibility ] );
 
-               $this->assertNotNull( $rev->getContent( 'main', RevisionRecord::RAW ), 'raw can' );
+               $this->assertNotNull( $rev->getContent( SlotRecord::MAIN, RevisionRecord::RAW ), 'raw can' );
 
                $this->assertSame(
                        $publicCan,
-                       $rev->getContent( 'main', RevisionRecord::FOR_PUBLIC ) !== null,
+                       $rev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC ) !== null,
                        'public can'
                );
                $this->assertSame(
                        $userCan,
-                       $rev->getContent( 'main', RevisionRecord::FOR_THIS_USER, $user ) !== null,
+                       $rev->getContent( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $user ) !== null,
                        'user can'
                );
        }
@@ -251,7 +252,7 @@ trait RevisionRecordTests {
        public function testGetSlot() {
                $rev = $this->newRevision();
 
-               $slot = $rev->getSlot( 'main' );
+               $slot = $rev->getSlot( SlotRecord::MAIN );
                $this->assertNotNull( $slot, 'getSlot()' );
                $this->assertSame( 'main', $slot->getRole(), 'getRole()' );
        }
@@ -259,14 +260,14 @@ trait RevisionRecordTests {
        public function testHasSlot() {
                $rev = $this->newRevision();
 
-               $this->assertTrue( $rev->hasSlot( 'main' ) );
+               $this->assertTrue( $rev->hasSlot( SlotRecord::MAIN ) );
                $this->assertFalse( $rev->hasSlot( 'xyz' ) );
        }
 
        public function testGetContent() {
                $rev = $this->newRevision();
 
-               $content = $rev->getSlot( 'main' );
+               $content = $rev->getSlot( SlotRecord::MAIN );
                $this->assertNotNull( $content, 'getContent()' );
                $this->assertSame( CONTENT_MODEL_TEXT, $content->getModel(), 'getModel()' );
        }
@@ -379,8 +380,8 @@ trait RevisionRecordTests {
 
        public function provideHasSameContent() {
                // Create some slots with content
-               $mainA = SlotRecord::newUnsaved( 'main', new TextContent( 'A' ) );
-               $mainB = SlotRecord::newUnsaved( 'main', new TextContent( 'B' ) );
+               $mainA = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'A' ) );
+               $mainB = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'B' ) );
                $auxA = SlotRecord::newUnsaved( 'aux', new TextContent( 'A' ) );
                $auxB = SlotRecord::newUnsaved( 'aux', new TextContent( 'A' ) );
 
index 52647c2..409e002 100644 (file)
@@ -46,11 +46,11 @@ class RevisionSlotsTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Storage\RevisionSlots::getSlot
         */
        public function testGetSlot() {
-               $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $mainSlot = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
                $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
 
-               $this->assertSame( $mainSlot, $slots->getSlot( 'main' ) );
+               $this->assertSame( $mainSlot, $slots->getSlot( SlotRecord::MAIN ) );
                $this->assertSame( $auxSlot, $slots->getSlot( 'aux' ) );
                $this->setExpectedException( RevisionAccessException::class );
                $slots->getSlot( 'nothere' );
@@ -60,11 +60,11 @@ class RevisionSlotsTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Storage\RevisionSlots::hasSlot
         */
        public function testHasSlot() {
-               $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $mainSlot = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
                $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
 
-               $this->assertTrue( $slots->hasSlot( 'main' ) );
+               $this->assertTrue( $slots->hasSlot( SlotRecord::MAIN ) );
                $this->assertTrue( $slots->hasSlot( 'aux' ) );
                $this->assertFalse( $slots->hasSlot( 'AUX' ) );
                $this->assertFalse( $slots->hasSlot( 'xyz' ) );
@@ -76,11 +76,11 @@ class RevisionSlotsTest extends MediaWikiTestCase {
        public function testGetContent() {
                $mainContent = new WikitextContent( 'A' );
                $auxContent = new WikitextContent( 'B' );
-               $mainSlot = SlotRecord::newUnsaved( 'main', $mainContent );
+               $mainSlot = SlotRecord::newUnsaved( SlotRecord::MAIN, $mainContent );
                $auxSlot = SlotRecord::newUnsaved( 'aux', $auxContent );
                $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
 
-               $this->assertSame( $mainContent, $slots->getContent( 'main' ) );
+               $this->assertSame( $mainContent, $slots->getContent( SlotRecord::MAIN ) );
                $this->assertSame( $auxContent, $slots->getContent( 'aux' ) );
                $this->setExpectedException( RevisionAccessException::class );
                $slots->getContent( 'nothere' );
@@ -90,7 +90,7 @@ class RevisionSlotsTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Storage\RevisionSlots::getSlotRoles
         */
        public function testGetSlotRoles_someSlots() {
-               $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $mainSlot = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
                $slots = $this->newRevisionSlots( [ $mainSlot, $auxSlot ] );
 
@@ -110,7 +110,7 @@ class RevisionSlotsTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Storage\RevisionSlots::getSlots
         */
        public function testGetSlots() {
-               $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $mainSlot = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $auxSlot = SlotRecord::newUnsaved( 'aux', new WikitextContent( 'B' ) );
                $slotsArray = [ $mainSlot, $auxSlot ];
                $slots = $this->newRevisionSlots( $slotsArray );
@@ -122,7 +122,7 @@ class RevisionSlotsTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Storage\RevisionSlots::getInheritedSlots
         */
        public function testGetInheritedSlots() {
-               $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $mainSlot = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $auxSlot = SlotRecord::newInherited(
                        SlotRecord::newSaved(
                                7, 7, 'foo',
@@ -139,7 +139,7 @@ class RevisionSlotsTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Storage\RevisionSlots::getOriginalSlots
         */
        public function testGetOriginalSlots() {
-               $mainSlot = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $mainSlot = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $auxSlot = SlotRecord::newInherited(
                        SlotRecord::newSaved(
                                7, 7, 'foo',
index 07a6971..75a4718 100644 (file)
@@ -158,25 +158,25 @@ class RevisionSlotsUpdateTest extends MediaWikiTestCase {
        public function testRemoveSlot() {
                $slots = new RevisionSlotsUpdate();
 
-               $slotA = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $slots->modifySlot( $slotA );
 
                $this->assertSame( [ 'main' ], $slots->getModifiedRoles() );
 
-               $slots->removeSlot( 'main' );
+               $slots->removeSlot( SlotRecord::MAIN );
                $slots->removeSlot( 'other' );
                $this->assertSame( [], $slots->getModifiedRoles() );
                $this->assertSame( [ 'main', 'other' ], $slots->getRemovedRoles() );
-               $this->assertTrue( $slots->isRemovedSlot( 'main' ) );
+               $this->assertTrue( $slots->isRemovedSlot( SlotRecord::MAIN ) );
                $this->assertTrue( $slots->isRemovedSlot( 'other' ) );
-               $this->assertFalse( $slots->isModifiedSlot( 'main' ) );
+               $this->assertFalse( $slots->isModifiedSlot( SlotRecord::MAIN ) );
 
                // removing the same slot again should not trigger an error
-               $slots->removeSlot( 'main' );
+               $slots->removeSlot( SlotRecord::MAIN );
 
                // getting a slot after removing it should fail
                $this->setExpectedException( RevisionAccessException::class );
-               $slots->getModifiedSlot( 'main' );
+               $slots->getModifiedSlot( SlotRecord::MAIN );
        }
 
        public function testGetModifiedRoles() {
@@ -184,26 +184,26 @@ class RevisionSlotsUpdateTest extends MediaWikiTestCase {
 
                $this->assertSame( [], $slots->getModifiedRoles() );
 
-               $slots->modifyContent( 'main', new WikitextContent( 'A' ) );
+               $slots->modifyContent( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $slots->modifyContent( 'foo', new WikitextContent( 'Foo' ) );
                $this->assertSame( [ 'main', 'foo' ], $slots->getModifiedRoles() );
 
-               $slots->removeSlot( 'main' );
+               $slots->removeSlot( SlotRecord::MAIN );
                $this->assertSame( [ 'foo' ], $slots->getModifiedRoles() );
        }
 
        public function testGetRemovedRoles() {
-               $slotA = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $slotA = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $slots = new RevisionSlotsUpdate( [ $slotA ] );
 
                $this->assertSame( [], $slots->getRemovedRoles() );
 
-               $slots->removeSlot( 'main', new WikitextContent( 'A' ) );
+               $slots->removeSlot( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $slots->removeSlot( 'foo', new WikitextContent( 'Foo' ) );
 
                $this->assertSame( [ 'main', 'foo' ], $slots->getRemovedRoles() );
 
-               $slots->modifyContent( 'main', new WikitextContent( 'A' ) );
+               $slots->modifyContent( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $this->assertSame( [ 'foo' ], $slots->getRemovedRoles() );
        }
 
index 5497d98..04b6aa8 100644 (file)
@@ -298,9 +298,9 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
        }
 
        protected function assertRevisionCompleteness( RevisionRecord $r ) {
-               $this->assertTrue( $r->hasSlot( 'main' ) );
-               $this->assertInstanceOf( SlotRecord::class, $r->getSlot( 'main' ) );
-               $this->assertInstanceOf( Content::class, $r->getContent( 'main' ) );
+               $this->assertTrue( $r->hasSlot( SlotRecord::MAIN ) );
+               $this->assertInstanceOf( SlotRecord::class, $r->getSlot( SlotRecord::MAIN ) );
+               $this->assertInstanceOf( Content::class, $r->getContent( SlotRecord::MAIN ) );
 
                foreach ( $r->getSlotRoles() as $role ) {
                        $this->assertSlotCompleteness( $r, $r->getSlot( $role ) );
@@ -357,7 +357,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
        public function provideInsertRevisionOn_successes() {
                yield 'Bare minimum revision insertion' => [
                        [
-                               'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
+                               'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
                                'page' => true,
                                'comment' => $this->getRandomCommentStoreComment(),
                                'timestamp' => '20171117010101',
@@ -366,7 +366,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                ];
                yield 'Detailed revision insertion' => [
                        [
-                               'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
+                               'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
                                'parent' => true,
                                'page' => true,
                                'comment' => $this->getRandomCommentStoreComment(),
@@ -454,7 +454,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
        public function testInsertRevisionOn_blobAddressExists() {
                $title = $this->getTestPageTitle();
                $revDetails = [
-                       'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
+                       'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
                        'parent' => true,
                        'comment' => $this->getRandomCommentStoreComment(),
                        'timestamp' => '20171117010101',
@@ -471,14 +471,14 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                $this->assertRevisionRecordsEqual( $revOne, $firstReturn );
 
                // Insert a second revision inheriting the same blob address
-               $revDetails['slot'] = SlotRecord::newInherited( $firstReturn->getSlot( 'main' ) );
+               $revDetails['slot'] = SlotRecord::newInherited( $firstReturn->getSlot( SlotRecord::MAIN ) );
                $revTwo = $this->getRevisionRecordFromDetailsArray( $revDetails );
                $secondReturn = $store->insertRevisionOn( $revTwo, wfGetDB( DB_MASTER ) );
                $this->assertLinkTargetsEqual( $title, $secondReturn->getPageAsLinkTarget() );
                $this->assertRevisionRecordsEqual( $revTwo, $secondReturn );
 
-               $firstMainSlot = $firstReturn->getSlot( 'main' );
-               $secondMainSlot = $secondReturn->getSlot( 'main' );
+               $firstMainSlot = $firstReturn->getSlot( SlotRecord::MAIN );
+               $secondMainSlot = $secondReturn->getSlot( SlotRecord::MAIN );
 
                $this->assertSameSlotContent( $firstMainSlot, $secondMainSlot );
 
@@ -510,7 +510,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                ];
                yield 'no timestamp' => [
                        [
-                               'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
+                               'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
                                'comment' => $this->getRandomCommentStoreComment(),
                                'user' => true,
                        ],
@@ -518,7 +518,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                ];
                yield 'no comment' => [
                        [
-                               'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
+                               'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
                                'timestamp' => '20171117010101',
                                'user' => true,
                        ],
@@ -526,7 +526,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                ];
                yield 'no user' => [
                        [
-                               'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
+                               'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
                                'comment' => $this->getRandomCommentStoreComment(),
                                'timestamp' => '20171117010101',
                        ],
@@ -717,7 +717,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                $revRecord = $store->getRevisionById( $rev->getId() );
 
                $this->assertSame( $rev->getId(), $revRecord->getId() );
-               $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
+               $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals( $content ) );
                $this->assertSame( __METHOD__, $revRecord->getComment()->text );
        }
 
@@ -735,7 +735,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                $revRecord = $store->getRevisionByTitle( $page->getTitle() );
 
                $this->assertSame( $rev->getId(), $revRecord->getId() );
-               $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
+               $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals( $content ) );
                $this->assertSame( __METHOD__, $revRecord->getComment()->text );
        }
 
@@ -753,7 +753,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                $revRecord = $store->getRevisionByPageId( $page->getId() );
 
                $this->assertSame( $rev->getId(), $revRecord->getId() );
-               $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
+               $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals( $content ) );
                $this->assertSame( __METHOD__, $revRecord->getComment()->text );
        }
 
@@ -778,7 +778,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                );
 
                $this->assertSame( $rev->getId(), $revRecord->getId() );
-               $this->assertTrue( $revRecord->getSlot( 'main' )->getContent()->equals( $content ) );
+               $this->assertTrue( $revRecord->getSlot( SlotRecord::MAIN )->getContent()->equals( $content ) );
                $this->assertSame( __METHOD__, $revRecord->getComment()->text );
        }
 
@@ -856,13 +856,14 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                $this->assertSame( $expectedParent, $record->getParentId() );
                $this->assertSame( $rev->getSha1(), $record->getSha1() );
                $this->assertSame( $rev->getComment(), $record->getComment()->text );
-               $this->assertSame( $rev->getContentFormat(), $record->getContent( 'main' )->getDefaultFormat() );
-               $this->assertSame( $rev->getContentModel(), $record->getContent( 'main' )->getModel() );
+               $this->assertSame( $rev->getContentFormat(),
+                       $record->getContent( SlotRecord::MAIN )->getDefaultFormat() );
+               $this->assertSame( $rev->getContentModel(), $record->getContent( SlotRecord::MAIN )->getModel() );
                $this->assertLinkTargetsEqual( $rev->getTitle(), $record->getPageAsLinkTarget() );
 
                $revRec = $rev->getRevisionRecord();
-               $revMain = $revRec->getSlot( 'main' );
-               $recMain = $record->getSlot( 'main' );
+               $revMain = $revRec->getSlot( SlotRecord::MAIN );
+               $recMain = $record->getSlot( SlotRecord::MAIN );
 
                $this->assertSame( $revMain->hasOrigin(), $recMain->hasOrigin(), 'hasOrigin' );
                $this->assertSame( $revMain->hasAddress(), $recMain->hasAddress(), 'hasAddress' );
@@ -1011,7 +1012,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                $record = $store->newRevisionFromArchiveRow( $row );
 
                $this->assertRevisionRecordMatchesRevision( $orig, $record );
-               $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
+               $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
        }
 
        /**
@@ -1042,7 +1043,7 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                $record = $store->newRevisionFromArchiveRow( $row );
 
                $this->assertRevisionRecordMatchesRevision( $orig, $record );
-               $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
+               $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
        }
 
        /**
@@ -1165,8 +1166,8 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                $this->assertRevisionRecordsEqual( $record, $restored );
 
                // does the new revision use the original slot?
-               $recMain = $record->getSlot( 'main' );
-               $restMain = $restored->getSlot( 'main' );
+               $recMain = $record->getSlot( SlotRecord::MAIN );
+               $restMain = $restored->getSlot( SlotRecord::MAIN );
                $this->assertSame( $recMain->getAddress(), $restMain->getAddress() );
                $this->assertSame( $recMain->getContentId(), $restMain->getContentId() );
                $this->assertSame( $recMain->getOrigin(), $restMain->getOrigin() );
@@ -1621,13 +1622,14 @@ abstract class RevisionStoreDbTestBase extends MediaWikiTestCase {
                                );
                        }
                } elseif ( isset( $array['text'] ) ) {
-                       $this->assertSame( $array['text'], $result->getSlot( 'main' )->getContent()->serialize() );
+                       $this->assertSame( $array['text'],
+                               $result->getSlot( SlotRecord::MAIN )->getContent()->serialize() );
                } elseif ( isset( $array['content_format'] ) ) {
                        $this->assertSame(
                                $array['content_format'],
-                               $result->getSlot( 'main' )->getContent()->getDefaultFormat()
+                               $result->getSlot( SlotRecord::MAIN )->getContent()->getDefaultFormat()
                        );
-                       $this->assertSame( $array['content_model'], $result->getSlot( 'main' )->getModel() );
+                       $this->assertSame( $array['content_model'], $result->getSlot( SlotRecord::MAIN )->getModel() );
                }
        }
 
index 1d6a9a0..12d950c 100644 (file)
@@ -34,7 +34,7 @@ class RevisionStoreRecordTest extends MediaWikiTestCase {
                $user = new UserIdentityValue( 11, 'Tester', 0 );
                $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
 
-               $main = SlotRecord::newUnsaved( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
                $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
                $slots = new RevisionSlots( [ $main, $aux ] );
 
@@ -62,7 +62,7 @@ class RevisionStoreRecordTest extends MediaWikiTestCase {
                $user = new UserIdentityValue( 11, 'Tester', 0 );
                $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
 
-               $main = SlotRecord::newUnsaved( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
                $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
                $slots = new RevisionSlots( [ $main, $aux ] );
 
@@ -220,7 +220,7 @@ class RevisionStoreRecordTest extends MediaWikiTestCase {
 
                $comment = CommentStoreComment::newUnsavedComment( 'Hello World' );
 
-               $main = SlotRecord::newUnsaved( 'main', new TextContent( 'Lorem Ipsum' ) );
+               $main = SlotRecord::newUnsaved( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
                $aux = SlotRecord::newUnsaved( 'aux', new TextContent( 'Frumious Bandersnatch' ) );
                $slots = new RevisionSlots( [ $main, $aux ] );
 
@@ -347,19 +347,20 @@ class RevisionStoreRecordTest extends MediaWikiTestCase {
                );
 
                // NOTE: slot meta-data is never suppressed, just the content is!
-               $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::RAW ), 'raw can' );
-               $this->assertNotNull( $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC ), 'public can' );
+               $this->assertNotNull( $rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW ), 'raw can' );
+               $this->assertNotNull( $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC ),
+                       'public can' );
 
                $this->assertNotNull(
-                       $rev->getSlot( 'main', RevisionRecord::FOR_THIS_USER, $user ),
+                       $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $user ),
                        'user can'
                );
 
-               $rev->getSlot( 'main', RevisionRecord::RAW )->getContent();
+               $rev->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )->getContent();
                // NOTE: the content of the current revision is never suppressed!
                // Check that getContent() doesn't throw SuppressedDataException
-               $rev->getSlot( 'main', RevisionRecord::FOR_PUBLIC )->getContent();
-               $rev->getSlot( 'main', RevisionRecord::FOR_THIS_USER, $user )->getContent();
+               $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_PUBLIC )->getContent();
+               $rev->getSlot( SlotRecord::MAIN, RevisionRecord::FOR_THIS_USER, $user )->getContent();
        }
 
 }
index aac94b8..2ed6f28 100644 (file)
@@ -9,6 +9,7 @@ use Language;
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\RevisionAccessException;
 use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
 use MediaWiki\Storage\SqlBlobStore;
 use MediaWikiTestCase;
 use MWException;
@@ -436,7 +437,7 @@ class RevisionStoreTest extends MediaWikiTestCase {
                        Title::newFromText( __METHOD__ . '-UTPage' )
                );
 
-               $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
+               $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
        }
 
        /**
@@ -465,7 +466,7 @@ class RevisionStoreTest extends MediaWikiTestCase {
                        0,
                        Title::newFromText( __METHOD__ . '-UTPage' )
                );
-               $this->assertSame( 'Söme Content', $record->getContent( 'main' )->serialize() );
+               $this->assertSame( 'Söme Content', $record->getContent( SlotRecord::MAIN )->serialize() );
        }
 
        private function makeRow( array $array ) {
index 1aae16d..0db294e 100644 (file)
@@ -118,21 +118,21 @@ class SlotRecordTest extends MediaWikiTestCase {
        }
 
        public function testGetContentId_fails() {
-               $record = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $record = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $this->setExpectedException( IncompleteRevisionException::class );
 
                $record->getContentId();
        }
 
        public function testGetAddress_fails() {
-               $record = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $record = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $this->setExpectedException( IncompleteRevisionException::class );
 
                $record->getAddress();
        }
 
        public function provideIncomplete() {
-               $unsaved = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $unsaved = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                yield 'unsaved' => [ $unsaved ];
 
                $parent = new SlotRecord( $this->makeRow(), new WikitextContent( 'A' ) );
@@ -144,7 +144,7 @@ class SlotRecordTest extends MediaWikiTestCase {
         * @dataProvider provideIncomplete
         */
        public function testGetRevision_fails( SlotRecord $record ) {
-               $record = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $record = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $this->setExpectedException( IncompleteRevisionException::class );
 
                $record->getRevision();
@@ -154,7 +154,7 @@ class SlotRecordTest extends MediaWikiTestCase {
         * @dataProvider provideIncomplete
         */
        public function testGetOrigin_fails( SlotRecord $record ) {
-               $record = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $record = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
                $this->setExpectedException( IncompleteRevisionException::class );
 
                $record->getOrigin();
@@ -173,7 +173,7 @@ class SlotRecordTest extends MediaWikiTestCase {
 
                $this->assertSame( $hash, SlotRecord::base36Sha1( $text ) );
 
-               $record = SlotRecord::newUnsaved( 'main', new WikitextContent( $text ) );
+               $record = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( $text ) );
                $this->assertSame( $hash, $record->getSha1() );
        }
 
@@ -225,7 +225,7 @@ class SlotRecordTest extends MediaWikiTestCase {
 
        public function testNewSaved() {
                // This would happen while doing an edit, before saving revision meta-data.
-               $unsaved = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $unsaved = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
 
                // This would happen while doing an edit, after saving the revision meta-data
                // and content meta-data.
@@ -285,7 +285,7 @@ class SlotRecordTest extends MediaWikiTestCase {
        }
 
        public function provideNewSaved_InvalidArgumentException() {
-               $unsaved = SlotRecord::newUnsaved( 'main', new WikitextContent( 'A' ) );
+               $unsaved = SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'A' ) );
 
                yield 'bad revision id' => [ 'xyzzy', 5, 'address', $unsaved ];
                yield 'bad content id' => [ 7, 'xyzzy', 'address', $unsaved ];
index 6532635..8e2c6d9 100644 (file)
@@ -2,6 +2,7 @@
 
 use MediaWiki\Linker\LinkTarget;
 use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\SlotRecord;
 
 /**
  * @group medium
@@ -93,7 +94,7 @@ class ApiQueryWatchlistIntegrationTest extends ApiTestCase {
                $page = WikiPage::factory( $title );
 
                $updater = $page->newPageUpdater( $user );
-               $updater->setContent( 'main', ContentHandler::makeContent( $content, $title ) );
+               $updater->setContent( SlotRecord::MAIN, ContentHandler::makeContent( $content, $title ) );
                $rev = $updater->saveRevision( $summary );
 
                $rc = MediaWikiServices::getInstance()->getRevisionStore()->getRecentChange( $rev );
index 806038a..e469f12 100644 (file)
@@ -2,6 +2,7 @@
 
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Revision\SlotRenderingProvider;
+use MediaWiki\Storage\SlotRecord;
 
 /**
  * @group ContentHandler
@@ -373,7 +374,7 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
                $srp = $this->getMock( SlotRenderingProvider::class );
 
                $handler = new WikitextContentHandler();
-               $updates = $handler->getSecondaryDataUpdates( $title, $content, 'main', $srp );
+               $updates = $handler->getSecondaryDataUpdates( $title, $content, SlotRecord::MAIN, $srp );
 
                $this->assertEquals( [], $updates );
        }
@@ -385,7 +386,7 @@ class WikitextContentHandlerTest extends MediaWikiLangTestCase {
                $srp = $this->getMock( SlotRenderingProvider::class );
 
                $handler = new WikitextContentHandler();
-               $updates = $handler->getDeletionUpdates( $title, 'main' );
+               $updates = $handler->getDeletionUpdates( $title, SlotRecord::MAIN );
 
                $this->assertEquals( [], $updates );
        }
index 07d02dd..e21ac3b 100644 (file)
@@ -216,9 +216,9 @@ class DifferenceEngineTest extends MediaWikiTestCase {
        }
 
        public function testSetRevisions() {
-               $main1 = SlotRecord::newUnsaved( 'main',
+               $main1 = SlotRecord::newUnsaved( SlotRecord::MAIN,
                        ContentHandler::makeContent( 'xxx', null, CONTENT_MODEL_TEXT ) );
-               $main2 = SlotRecord::newUnsaved( 'main',
+               $main2 = SlotRecord::newUnsaved( SlotRecord::MAIN,
                        ContentHandler::makeContent( 'yyy', null, CONTENT_MODEL_TEXT ) );
                $rev1 = $this->getRevisionRecord( $main1 );
                $rev2 = $this->getRevisionRecord( $main2 );
@@ -260,9 +260,9 @@ class DifferenceEngineTest extends MediaWikiTestCase {
        }
 
        public function provideGetDiffBody() {
-               $main1 = SlotRecord::newUnsaved( 'main',
+               $main1 = SlotRecord::newUnsaved( SlotRecord::MAIN,
                        ContentHandler::makeContent( 'xxx', null, CONTENT_MODEL_TEXT ) );
-               $main2 = SlotRecord::newUnsaved( 'main',
+               $main2 = SlotRecord::newUnsaved( SlotRecord::MAIN,
                        ContentHandler::makeContent( 'yyy', null, CONTENT_MODEL_TEXT ) );
                $slot1 = SlotRecord::newUnsaved( 'slot',
                        ContentHandler::makeContent( 'aaa', null, CONTENT_MODEL_TEXT ) );
index 68cddd6..d07a9e1 100644 (file)
@@ -2,6 +2,7 @@
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\MutableRevisionRecord;
 use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
 use PHPUnit\Framework\MockObject\MockObject;
 
 /**
@@ -43,7 +44,7 @@ class ArticleViewTest extends MediaWikiTestCase {
                        }
 
                        $u = $page->newPageUpdater( $user );
-                       $u->setContent( 'main', $cont );
+                       $u->setContent( SlotRecord::MAIN, $cont );
                        $rev = $u->saveRevision( CommentStoreComment::newUnsavedComment( 'Rev ' . $key ) );
 
                        $revisions[ $key ] = $rev;
@@ -201,7 +202,7 @@ class ArticleViewTest extends MediaWikiTestCase {
                $rev->setComment( $dummyRev->getComment() );
                $rev->setTimestamp( $dummyRev->getTimestamp() );
 
-               $rev->setContent( 'main', $content );
+               $rev->setContent( SlotRecord::MAIN, $content );
 
                $rev = new Revision( $rev );
 
@@ -453,7 +454,7 @@ class ArticleViewTest extends MediaWikiTestCase {
                $this->setTemporaryHook(
                        'ArticleRevisionViewCustom',
                        function ( RevisionRecord $rev, Title $title, $oldid, OutputPage $output ) use ( $page ) {
-                               $content = $rev->getContent( 'main' );
+                               $content = $rev->getContent( SlotRecord::MAIN );
 
                                $this->assertSame( $page->getTitle(), $title, '$title' );
                                $this->assertSame( 'Test A', $content->getNativeData(), '$content' );
index 6757e78..476d5c2 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\SlotRecord;
 use MediaWiki\Storage\SqlBlobStore;
 use MediaWiki\Tests\Storage\PreMcrSchemaOverride;
 
@@ -27,7 +28,7 @@ class PageArchivePreMcrTest extends PageArchiveTestBase {
                $blobStore = MediaWikiServices::getInstance()->getBlobStore();
 
                $textId = $blobStore->getTextIdFromAddress(
-                       $this->firstRev->getSlot( 'main' )->getAddress()
+                       $this->firstRev->getSlot( SlotRecord::MAIN )->getAddress()
                );
 
                $row = (object)[ 'ar_text_id' => $textId ];
@@ -61,7 +62,7 @@ class PageArchivePreMcrTest extends PageArchiveTestBase {
                                'ar_namespace' => '0',
                                'ar_title' => 'PageArchiveTest_thePage',
                                'ar_text_id' => (string)$blobStore->getTextIdFromAddress(
-                                       $this->ipRev->getSlot( 'main' )->getAddress()
+                                       $this->ipRev->getSlot( SlotRecord::MAIN )->getAddress()
                                ),
                                'ar_parent_id' => strval( $this->ipRev->getParentId() ),
                        ],
@@ -86,7 +87,7 @@ class PageArchivePreMcrTest extends PageArchiveTestBase {
                                'ar_namespace' => '0',
                                'ar_title' => 'PageArchiveTest_thePage',
                                'ar_text_id' => (string)$blobStore->getTextIdFromAddress(
-                                       $this->firstRev->getSlot( 'main' )->getAddress()
+                                       $this->firstRev->getSlot( SlotRecord::MAIN )->getAddress()
                                ),
                                'ar_parent_id' => '0',
                        ],
index 4cb2b47..67cbf58 100644 (file)
@@ -3,6 +3,7 @@
 use MediaWiki\Edit\PreparedEdit;
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\RevisionSlotsUpdate;
+use MediaWiki\Storage\SlotRecord;
 use PHPUnit\Framework\MockObject\MockObject;
 use Wikimedia\TestingAccessWrapper;
 
@@ -1232,7 +1233,7 @@ more stuff
                );
 
                // TODO: MCR: assert origin once we write slot data
-               // $mainSlot = $page->getRevision()->getRevisionRecord()->getSlot( 'main' );
+               // $mainSlot = $page->getRevision()->getRevisionRecord()->getSlot( SlotRecord::MAIN );
                // $this->assertTrue( $mainSlot->isInherited(), 'isInherited' );
                // $this->assertSame( $rev2->getId(), $mainSlot->getOrigin(), 'getOrigin' );
        }
@@ -2416,10 +2417,10 @@ more stuff
 
                // provide context, so the cache can be kept in place
                $slotsUpdate = new revisionSlotsUpdate();
-               $slotsUpdate->modifyContent( 'main', $content );
+               $slotsUpdate->modifyContent( SlotRecord::MAIN, $content );
 
                $updater = $page->newPageUpdater( $user, $slotsUpdate );
-               $updater->setContent( 'main', $content );
+               $updater->setContent( SlotRecord::MAIN, $content );
                $revision = $updater->saveRevision(
                        CommentStoreComment::newUnsavedComment( 'test' ),
                        EDIT_NEW
@@ -2448,7 +2449,7 @@ more stuff
                $user = $revision->getUser();
 
                $slotsUpdate = new RevisionSlotsUpdate();
-               $slotsUpdate->modifyContent( 'main', new WikitextContent( 'Hello World' ) );
+               $slotsUpdate->modifyContent( SlotRecord::MAIN, new WikitextContent( 'Hello World' ) );
 
                // get a virgin updater
                $updater1 = $page->getDerivedDataUpdater( $user );
@@ -2460,7 +2461,7 @@ more stuff
                $this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, $revision ) );
 
                $slotsUpdate = RevisionSlotsUpdate::newFromContent(
-                       [ 'main' => $revision->getContent( 'main' ) ]
+                       [ SlotRecord::MAIN => $revision->getContent( SlotRecord::MAIN ) ]
                );
                $this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, null, $slotsUpdate ) );
 
index 1427f01..3e857f0 100644 (file)
@@ -1,6 +1,7 @@
 <?php
 use MediaWiki\Storage\MutableRevisionRecord;
 use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
 use MediaWiki\User\UserIdentityValue;
 
 /**
@@ -235,7 +236,7 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
                $oldRevision->setId( 100 );
                $oldRevision->setUser( new UserIdentityValue( 7, 'FauxAuthor', 0 ) );
                $oldRevision->setTimestamp( '20141111111111' );
-               $oldRevision->setContent( 'main', new WikitextContent( 'FAUX' ) );
+               $oldRevision->setContent( SlotRecord::MAIN, new WikitextContent( 'FAUX' ) );
 
                $po = new ParserOptions( $frank );
                $po->setCurrentRevisionCallback( function () use ( $oldRevision ) {
@@ -263,7 +264,7 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
                $newRevision = new MutableRevisionRecord( $title );
                $newRevision->setUser( new UserIdentityValue( 9, 'NewAuthor', 0 ) );
                $newRevision->setTimestamp( '20180808000000' );
-               $newRevision->setContent( 'main', new WikitextContent( 'NEW' ) );
+               $newRevision->setContent( SlotRecord::MAIN, new WikitextContent( 'NEW' ) );
 
                $po = new ParserOptions( $frank );
                $po->setIsPreview( true );
@@ -298,7 +299,7 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
                $newRevision = new MutableRevisionRecord( $title );
                $newRevision->setUser( new UserIdentityValue( 9, 'NewAuthor', 0 ) );
                $newRevision->setTimestamp( '20180808000000' );
-               $newRevision->setContent( 'main', new WikitextContent( $text ) );
+               $newRevision->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
 
                $po = new ParserOptions( $frank );
                $po->setIsPreview( true );
@@ -329,13 +330,13 @@ class ParserMethodsTest extends MediaWikiLangTestCase {
                $oldRevision->setId( 100 );
                $oldRevision->setUser( new UserIdentityValue( 7, 'OldAuthor', 0 ) );
                $oldRevision->setTimestamp( '20140404000000' );
-               $oldRevision->setContent( 'main', new WikitextContent( 'OLD' ) );
+               $oldRevision->setContent( SlotRecord::MAIN, new WikitextContent( 'OLD' ) );
 
                $currentRevision = new MutableRevisionRecord( $title );
                $currentRevision->setId( 200 );
                $currentRevision->setUser( new UserIdentityValue( 9, 'CurrentAuthor', 0 ) );
                $currentRevision->setTimestamp( '20160606000000' );
-               $currentRevision->setContent( 'main', new WikitextContent( 'CURRENT' ) );
+               $currentRevision->setContent( SlotRecord::MAIN, new WikitextContent( 'CURRENT' ) );
 
                $revisionStore = $this->getMockBuilder( RevisionStore::class )
                        ->disableOriginalConstructor()
index c6b9dee..a0beb45 100644 (file)
@@ -2,6 +2,7 @@
 use MediaWiki\MediaWikiServices;
 use MediaWiki\Storage\MutableRevisionRecord;
 use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
 
 /**
  * @covers PoolWorkArticleView
@@ -13,7 +14,7 @@ class PoolWorkArticleViewTest extends MediaWikiTestCase {
                $user = $this->getTestUser()->getUser();
                $updater = $page->newPageUpdater( $user );
 
-               $updater->setContent( 'main', new WikitextContent( $text ) );
+               $updater->setContent( SlotRecord::MAIN, new WikitextContent( $text ) );
                return $updater->saveRevision( CommentStoreComment::newUnsavedComment( 'testing' ) );
        }
 
@@ -57,7 +58,7 @@ class PoolWorkArticleViewTest extends MediaWikiTestCase {
                $fakeRev = new MutableRevisionRecord( $page->getTitle() );
                $fakeRev->setId( $rev->getId() );
                $fakeRev->setPageId( $page->getId() );
-               $fakeRev->setContent( 'main', new WikitextContent( 'YES!' ) );
+               $fakeRev->setContent( SlotRecord::MAIN, new WikitextContent( 'YES!' ) );
 
                $work = new PoolWorkArticleView( $page, $options, $rev->getId(), false, $fakeRev );
                $work->execute();
@@ -157,7 +158,7 @@ class PoolWorkArticleViewTest extends MediaWikiTestCase {
                $fakeRev = new MutableRevisionRecord( $page->getTitle() );
                $fakeRev->setId( $rev1->getId() );
                $fakeRev->setPageId( $page->getId() );
-               $fakeRev->setContent( 'main', new WikitextContent( 'SECRET' ) );
+               $fakeRev->setContent( SlotRecord::MAIN, new WikitextContent( 'SECRET' ) );
                $fakeRev->setVisibility( RevisionRecord::DELETED_TEXT );
 
                $work = new PoolWorkArticleView( $page, $options, $rev1->getId(), false, $fakeRev );