*/
use MediaWiki\MediaWikiServices;
-use MediaWiki\Storage\MutableRevisionRecord;
-use MediaWiki\Storage\RevisionRecord;
-use MediaWiki\Storage\RevisionStore;
+use MediaWiki\Revision\MutableRevisionRecord;
+use MediaWiki\Revision\RevisionRecord;
+use MediaWiki\Revision\RevisionArchiveRecord;
+use MediaWiki\Revision\RevisionStore;
+use MediaWiki\Revision\SlotRecord;
class ApiComparePages extends ApiBase {
/** @var RevisionStore */
private $revisionStore;
+ /** @var \MediaWiki\Revision\SlotRoleRegistry */
+ private $slotRoleRegistry;
+
private $guessedTitle = false, $props;
public function __construct( ApiMain $mainModule, $moduleName, $modulePrefix = '' ) {
parent::__construct( $mainModule, $moduleName, $modulePrefix );
$this->revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
+ $this->slotRoleRegistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
}
public function execute() {
if ( !$fromRelRev ) {
$this->dieWithError( 'apierror-compare-relative-to-nothing' );
}
+ if ( $params['torelative'] !== 'cur' && $fromRelRev instanceof RevisionArchiveRecord ) {
+ // RevisionStore's getPreviousRevision/getNextRevision blow up
+ // when passed an RevisionArchiveRecord for a deleted page
+ $this->dieWithError( [ 'apierror-compare-relative-to-deleted', $params['torelative'] ] );
+ }
switch ( $params['torelative'] ) {
case 'prev':
// Swap 'from' and 'to'
}
$guessedTitle = $this->guessTitle();
- if ( $guessedTitle && $role === 'main' ) {
- // @todo: Use SlotRoleRegistry and do this for all slots
- return $guessedTitle->getContentModel();
+ if ( $guessedTitle ) {
+ return $this->slotRoleRegistry->getRoleHandler( $role )->getDefaultModel( $guessedTitle );
}
if ( isset( $params["fromcontentmodel-$role"] ) ) {
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';
- }
+ $slotRoles = $this->slotRoleRegistry->getKnownRoles();
sort( $slotRoles, SORT_STRING );
// Parameters for the 'from' and 'to' content