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 );
$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.
* @return SlotRecord
*/
private function getMainSlotRaw() {
- return $this->mRecord->getSlot( 'main', RevisionRecord::RAW );
+ return $this->mRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW );
}
/**
}
try {
- return $this->mRecord->getContent( 'main', $audience, $user );
+ return $this->mRecord->getContent( SlotRecord::MAIN, $audience, $user );
}
catch ( RevisionAccessException $e ) {
return null;
use Html;
use InvalidArgumentException;
use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
use ParserOptions;
use ParserOutput;
use Psr\Log\LoggerInterface;
$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 );
}
// TODO: MCR: ask all slots if they have links [SlotHandler/PageTypeHandler]
- $mainContent = $this->getRawContent( 'main' );
+ $mainContent = $this->getRawContent( SlotRecord::MAIN );
return $mainContent->isCountable( $hasLinks );
}
*/
public function isRedirect() {
// NOTE: main slot determines redirect status
- $mainContent = $this->getRawContent( 'main' );
+ $mainContent = $this->getRawContent( SlotRecord::MAIN );
return $mainContent->isRedirect();
}
*/
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();
}
$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 );
}
// 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 {
$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();
// 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']
) {
) );
// 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() ) );
}
}
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 );
}
* @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!' );
}
// 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() ),
*/
$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( [] );
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!' );
}
$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 );
$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!'
);
// 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 );
$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();
$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
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();
*/
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;
$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 );
};
}
$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!'
);
) {
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?)
$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';
*/
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
use MediaWiki\Storage\MutableRevisionRecord;
use MediaWiki\Storage\RevisionRecord;
use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
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();
}
return $params["tocontentmodel-$role"];
}
- if ( $role === 'main' ) {
+ if ( $role === SlotRecord::MAIN ) {
if ( isset( $params['fromcontentmodel'] ) ) {
return $params['fromcontentmodel'];
}
$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"];
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;
"nosuch{$prefix}section"
);
}
- $newRev->setContent( 'main', $content );
+ $newRev->setContent( SlotRecord::MAIN, $content );
}
return [ $newRev, $rev, $rev ];
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 ] );
}
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();
}
}
// 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 ) {
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 );
use MediaWiki\Storage\RevisionAccessException;
use MediaWiki\Storage\RevisionRecord;
use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
/**
* @ingroup API
if ( $revision ) {
$msg = wfMessage( 'colon-separator' )->inContentLanguage()->text();
try {
- $content = $revision->getContent( 'main' );
+ $content = $revision->getContent( SlotRecord::MAIN );
} catch ( RevisionAccessException $e ) {
$content = null;
}
}
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.
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 );
*/
use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
/**
* DifferenceEngine is responsible for rendering the difference between two revisions as HTML.
protected function getSlotContents() {
if ( $this->isContentOverridden ) {
return [
- 'main' => [
+ SlotRecord::MAIN => [
'old' => $this->mOldContent,
'new' => $this->mNewContent,
]
];
}
// 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;
}
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 );
return false;
}
- if ( $role !== 'main' ) {
+ if ( $role !== SlotRecord::MAIN ) {
// TODO use human-readable role name at least
$slotTitle = $role;
$slotDiff = $this->getSlotHeader( $slotTitle ) . $slotDiff;
$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;
$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;
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\MutableRevisionRecord;
use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
/**
* Class for viewing MediaWiki article and history.
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 );
// 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;
}
$bSlots = $b->getRevisionRecord()->getSlots();
$changedRoles = $aSlots->getRolesWithDifferentContent( $bSlots );
- return ( $changedRoles !== [ 'main' ] && $changedRoles !== [] );
+ return ( $changedRoles !== [ SlotRecord::MAIN ] && $changedRoles !== [] );
}
/**
}
$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 );
$revision = $revision->getRevisionRecord();
}
- $slots = RevisionSlotsUpdate::newFromContent( [ 'main' => $content ] );
+ $slots = RevisionSlotsUpdate::newFromContent( [ SlotRecord::MAIN => $content ] );
$updater = $this->getDerivedDataUpdater( $user, $revision, $slots );
if ( !$updater->isUpdatePrepared() ) {
}
// 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() ) ) {
) {
// 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]
} 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 );
use MediaWiki\Storage\MutableRevisionRecord;
use MediaWiki\Storage\RevisionRecord;
use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
class PoolWorkArticleView extends PoolCounterWork {
/** @var WikiPage */
$revision = new MutableRevisionRecord( $page->getTitle() );
$revision->setId( $revid );
$revision->setPageId( $page->getId() );
- $revision->setContent( 'main', $content );
+ $revision->setContent( SlotRecord::MAIN, $content );
}
if ( $revision ) {
* @ingroup Maintenance
*/
+use MediaWiki\Storage\SlotRecord;
+
require_once __DIR__ . '/Maintenance.php';
/**
$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 ] );
$page = WikiPage::factory( $title );
if ( $remove ) {
- if ( $slot === 'main' ) {
+ if ( $slot === SlotRecord::MAIN ) {
$this->fatalError( "Cannot remove main slot! Use --slot to specify." );
}
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\NameTableStore;
+use MediaWiki\Storage\SlotRecord;
use MediaWiki\Storage\SqlBlobStore;
use Wikimedia\Assert\Assert;
use Wikimedia\Rdbms\IDatabase;
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() {
*/
use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\SlotRecord;
require_once __DIR__ . '/../Maintenance.php';
$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" );
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;
$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() {
$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() {
$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() {
$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() {
$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() {
$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();
$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 );
$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,
$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 ] );
$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 ) );
$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();
use MediaWiki\Revision\RevisionRenderer;
use MediaWiki\Storage\MutableRevisionRecord;
use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
use MediaWiki\User\UserIdentityValue;
use MediaWikiTestCase;
use ParserOptions;
$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 );
$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() {
$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 );
$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() {
$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 ] );
$this->assertContains( 'rev:21', $html );
- $this->assertSame( $html, $rr->getSlotParserOutput( 'main' )->getText() );
+ $this->assertSame( $html, $rr->getSlotParserOutput( SlotRecord::MAIN )->getText() );
}
public function testGetRenderedRevision_old() {
$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 );
$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 );
$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!
$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->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();
$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 ] );
// 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()
'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' ) );
'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' ) );
'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' ) );
$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() );
}
$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 );
);
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent );
$update->modifySlot( SlotRecord::newInherited( $auxSlot ) );
// TODO: MCR: test removing slots!
$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() );
$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 );
// 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}}' );
// 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() );
$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 );
$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() );
}
$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
$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();
$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 );
$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 );
}
$mainContent = new WikitextContent( 'first [[main]] ~~~' );
$update = new MutableRevisionSlots();
- $update->setContent( 'main', $mainContent );
+ $update->setContent( SlotRecord::MAIN, $mainContent );
$rev = $this->createRevision( $page, __METHOD__ );
$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 );
}
$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 );
);
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent2 );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent2 );
$update->removeSlot( 'aux' );
$page = $this->getPage( __METHOD__ );
$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 );
$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' );
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() {
$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' ) );
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 ];
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 ];
}
$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() );
}
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() );
}
$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() {
'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' => [],
'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' =>
use Content;
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
use MediaWikiTestCase;
use ParserOptions;
use RecentChange;
// TODO: MCR: test additional slots
$content = new TextContent( 'Lorem Ipsum' );
- $updater->setContent( 'main', $content );
+ $updater->setContent( SlotRecord::MAIN, $content );
$parent = $updater->grabParentRevision();
$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?
// 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 );
$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' );
// 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?
// 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 );
}
$updater = $page->newPageUpdater( $user );
- $updater->setContent( 'main', $content );
+ $updater->setContent( SlotRecord::MAIN, $content );
$rev = $updater->saveRevision( $comment );
return $rev;
}
// 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();
// 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();
// 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();
// 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();
$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 );
$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() );
$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( '' );
// 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 );
$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 );
// 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 );
$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();
$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 );
$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' );
$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 ] );
$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 ] );
$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 ] );
namespace MediaWiki\Tests\Storage;
use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\SlotRecord;
use MediaWikiTestCase;
use Revision;
'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' => [],
'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( [
'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( [
'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' => [],
'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' =>
$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;
);
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;
$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'
);
}
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()' );
}
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()' );
}
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' ) );
* @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' );
* @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' ) );
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' );
* @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 ] );
* @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 );
* @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',
* @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',
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() {
$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() );
}
}
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 ) );
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',
];
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(),
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',
$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 );
];
yield 'no timestamp' => [
[
- 'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
+ 'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
'comment' => $this->getRandomCommentStoreComment(),
'user' => true,
],
];
yield 'no comment' => [
[
- 'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
+ 'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
'timestamp' => '20171117010101',
'user' => true,
],
];
yield 'no user' => [
[
- 'slot' => SlotRecord::newUnsaved( 'main', new WikitextContent( 'Chicken' ) ),
+ 'slot' => SlotRecord::newUnsaved( SlotRecord::MAIN, new WikitextContent( 'Chicken' ) ),
'comment' => $this->getRandomCommentStoreComment(),
'timestamp' => '20171117010101',
],
$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 );
}
$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 );
}
$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 );
}
);
$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 );
}
$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' );
$record = $store->newRevisionFromArchiveRow( $row );
$this->assertRevisionRecordMatchesRevision( $orig, $record );
- $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
+ $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
}
/**
$record = $store->newRevisionFromArchiveRow( $row );
$this->assertRevisionRecordMatchesRevision( $orig, $record );
- $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
+ $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
}
/**
$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() );
);
}
} 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() );
}
}
$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 ] );
$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 ] );
$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 ] );
);
// 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();
}
}
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\RevisionAccessException;
use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
use MediaWiki\Storage\SqlBlobStore;
use MediaWikiTestCase;
use MWException;
Title::newFromText( __METHOD__ . '-UTPage' )
);
- $this->assertSame( $text, $record->getContent( 'main' )->serialize() );
+ $this->assertSame( $text, $record->getContent( SlotRecord::MAIN )->serialize() );
}
/**
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 ) {
}
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' ) );
* @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();
* @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();
$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() );
}
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.
}
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 ];
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\SlotRecord;
/**
* @group medium
$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 );
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\SlotRenderingProvider;
+use MediaWiki\Storage\SlotRecord;
/**
* @group ContentHandler
$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 );
}
$srp = $this->getMock( SlotRenderingProvider::class );
$handler = new WikitextContentHandler();
- $updates = $handler->getDeletionUpdates( $title, 'main' );
+ $updates = $handler->getDeletionUpdates( $title, SlotRecord::MAIN );
$this->assertEquals( [], $updates );
}
}
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 );
}
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 ) );
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\MutableRevisionRecord;
use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
use PHPUnit\Framework\MockObject\MockObject;
/**
}
$u = $page->newPageUpdater( $user );
- $u->setContent( 'main', $cont );
+ $u->setContent( SlotRecord::MAIN, $cont );
$rev = $u->saveRevision( CommentStoreComment::newUnsavedComment( 'Rev ' . $key ) );
$revisions[ $key ] = $rev;
$rev->setComment( $dummyRev->getComment() );
$rev->setTimestamp( $dummyRev->getTimestamp() );
- $rev->setContent( 'main', $content );
+ $rev->setContent( SlotRecord::MAIN, $content );
$rev = new Revision( $rev );
$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' );
<?php
use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\SlotRecord;
use MediaWiki\Storage\SqlBlobStore;
use MediaWiki\Tests\Storage\PreMcrSchemaOverride;
$blobStore = MediaWikiServices::getInstance()->getBlobStore();
$textId = $blobStore->getTextIdFromAddress(
- $this->firstRev->getSlot( 'main' )->getAddress()
+ $this->firstRev->getSlot( SlotRecord::MAIN )->getAddress()
);
$row = (object)[ 'ar_text_id' => $textId ];
'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() ),
],
'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',
],
use MediaWiki\Edit\PreparedEdit;
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\RevisionSlotsUpdate;
+use MediaWiki\Storage\SlotRecord;
use PHPUnit\Framework\MockObject\MockObject;
use Wikimedia\TestingAccessWrapper;
);
// 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' );
}
// 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
$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 );
$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 ) );
<?php
use MediaWiki\Storage\MutableRevisionRecord;
use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Storage\SlotRecord;
use MediaWiki\User\UserIdentityValue;
/**
$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 ) {
$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 );
$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 );
$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()
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\MutableRevisionRecord;
use MediaWiki\Storage\RevisionRecord;
+use MediaWiki\Storage\SlotRecord;
/**
* @covers PoolWorkArticleView
$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' ) );
}
$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();
$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 );