Remove use of Revision objects in RevisionItem classes

Bug: T249393
Bug: T249021
Change-Id: I1e240adb2799978b7f4302f90e43f7d337a0fdd9
This commit is contained in:
DannyS712 2020-05-01 18:03:43 +00:00
parent 40214bd908
commit ec7584d4fa
6 changed files with 34 additions and 27 deletions

View file

@ -39,8 +39,8 @@ class ChangeTagsRevisionItem extends RevisionItem {
$difflink = $this->list->msg( 'parentheses' )
->rawParams( $this->getDiffLink() )->escaped();
$revlink = $this->getRevisionLink();
$userlink = Linker::revUserLink( $this->revision->getRevisionRecord() );
$comment = Linker::revComment( $this->revision->getRevisionRecord() );
$userlink = Linker::revUserLink( $this->getRevisionRecord() );
$comment = Linker::revComment( $this->getRevisionRecord() );
if ( $this->isDeleted() ) {
$revlink = "<span class=\"history-deleted\">$revlink</span>";
}

View file

@ -26,7 +26,7 @@ use MediaWiki\Revision\RevisionFactory;
* Item class for a archive table row
*/
class RevDelArchiveItem extends RevDelRevisionItem {
protected static function initRevision( $list, $row ) {
protected static function initRevisionRecord( $list, $row ) {
$revRecord = MediaWikiServices::getInstance()
->getRevisionFactory()
->newRevisionFromArchiveRow(
@ -36,8 +36,7 @@ class RevDelArchiveItem extends RevDelRevisionItem {
[ 'page_id' => $list->title->getArticleID() ]
);
// TODO return a RevisionRecord instead
return new Revision( $revRecord );
return $revRecord;
}
public function getIdField() {
@ -62,7 +61,7 @@ class RevDelArchiveItem extends RevDelRevisionItem {
public function getId() {
# Convert DB timestamp to MW timestamp
return $this->revision->getTimestamp();
return $this->revisionRecord->getTimestamp();
}
public function setBits( $bits ) {
@ -84,7 +83,7 @@ class RevDelArchiveItem extends RevDelRevisionItem {
protected function getRevisionLink() {
$date = $this->list->getLanguage()->userTimeAndDate(
$this->revision->getTimestamp(), $this->list->getUser() );
$this->revisionRecord->getTimestamp(), $this->list->getUser() );
if ( $this->isDeleted() && !$this->canViewContent() ) {
return htmlspecialchars( $date );
@ -96,7 +95,7 @@ class RevDelArchiveItem extends RevDelRevisionItem {
[],
[
'target' => $this->list->title->getPrefixedText(),
'timestamp' => $this->revision->getTimestamp()
'timestamp' => $this->revisionRecord->getTimestamp()
]
);
}
@ -113,7 +112,7 @@ class RevDelArchiveItem extends RevDelRevisionItem {
[
'target' => $this->list->title->getPrefixedText(),
'diff' => 'prev',
'timestamp' => $this->revision->getTimestamp()
'timestamp' => $this->revisionRecord->getTimestamp()
]
);
}

View file

@ -29,7 +29,7 @@ class RevDelArchivedRevisionItem extends RevDelArchiveItem {
}
public function getId() {
return $this->revision->getId();
return $this->getRevisionRecord()->getId();
}
public function setBits( $bits ) {

View file

@ -19,6 +19,7 @@
* @ingroup RevisionDelete
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
/**
@ -27,12 +28,12 @@ use MediaWiki\Revision\RevisionRecord;
* @property RevDelRevisionList $list
*/
class RevDelRevisionItem extends RevDelItem {
/** @var Revision */
public $revision;
/** @var RevisionRecord */
public $revisionRecord;
public function __construct( RevisionListBase $list, $row ) {
parent::__construct( $list, $row );
$this->revision = static::initRevision( $list, $row );
$this->revisionRecord = static::initRevisionRecord( $list, $row );
}
/**
@ -40,21 +41,21 @@ class RevDelRevisionItem extends RevDelItem {
*
* @param RevisionListBase $list
* @param mixed $row
* @return Revision
* @return RevisionRecord
*/
protected static function initRevision( $list, $row ) {
return new Revision( $row );
protected static function initRevisionRecord( $list, $row ) {
return MediaWikiServices::getInstance()
->getRevisionFactory()
->newRevisionFromRow( $row );
}
/**
* Get the RevisionRecord for the item
*
* @todo remove use of Revision entirely
*
* @return RevisionRecord
*/
protected function getRevisionRecord() : RevisionRecord {
return $this->revision->getRevisionRecord();
return $this->revisionRecord;
}
public function getIdField() {

View file

@ -54,8 +54,14 @@ class RevDelRevisionList extends RevDelList {
}
public static function suggestTarget( $target, array $ids ) {
$rev = Revision::newFromId( $ids[0] );
return $rev ? $rev->getTitle() : $target;
$revisionRecord = MediaWikiServices::getInstance()
->getRevisionLookup()
->getRevisionById( $ids[0] );
if ( $revisionRecord ) {
return Title::newFromLinkTarget( $revisionRecord->getPageAsLinkTarget() );
}
return $target;
}
/**

View file

@ -20,33 +20,34 @@
* @file
*/
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord;
/**
* Item class for a live revision table row
*/
class RevisionItem extends RevisionItemBase {
/** @var Revision */
protected $revision;
/** @var RevisionRecord */
protected $revisionRecord;
/** @var RequestContext */
protected $context;
public function __construct( RevisionListBase $list, $row ) {
parent::__construct( $list, $row );
$this->revision = new Revision( $row );
$this->revisionRecord = MediaWikiServices::getInstance()
->getRevisionFactory()
->newRevisionFromRow( $row );
$this->context = $list->getContext();
}
/**
* Get the RevisionRecord for the item
*
* @todo remove use of Revision entirely
*
* @return RevisionRecord
*/
protected function getRevisionRecord() : RevisionRecord {
return $this->revision->getRevisionRecord();
return $this->revisionRecord;
}
public function getIdField() {