Remove usages and hard deprecate Revision::newFromRow
Also updates CategoryMembershipChange to accept a RevisionRecord instead of a Revision. Bug: T246284 Change-Id: I30024b7278e108b0f4e20ef1eb44647916fad47c
This commit is contained in:
parent
a102fb3379
commit
a2cf98ef70
6 changed files with 63 additions and 29 deletions
|
|
@ -633,6 +633,7 @@ because of Phabricator reports.
|
|||
- ::getTimestampFromId - use RevisionStore::getTimestampFromId instead
|
||||
- ::countByPageId - use RevisionStore::countRevisionsByPageId instead
|
||||
- ::countByTitle - use RevisionStore::countRevisionsByTitle instead
|
||||
- ::newFromRow - use RevisionStore::newRevisionFromRow instead
|
||||
- ::newKnownCurrent - use RevisionStore::getKnownCurrentRevision instead
|
||||
- ::getParentLengths - use RevisionStore::getRevisionSizes instead
|
||||
* RecentChange::markPatrolled was deprecated. Use ::doMarkPatrolled instead.
|
||||
|
|
@ -646,6 +647,8 @@ because of Phabricator reports.
|
|||
* RevisionStore::loadRevisionFromTitle was deprecated.
|
||||
* RevisionStore::listRevisionSizes was deprecated.
|
||||
* SkinTemplate::makeArticleUrlDetails has been deprecated, no longer used.
|
||||
* Passing a Revision object into CategoryMembershipChange constructor is
|
||||
deprecated. Pass a RevisionRecord instead.
|
||||
* The "mediawiki.legacy.oldshared" module has been deprecated.
|
||||
Skins and extensions that are using this should copy its necessary CSS rules
|
||||
to their own styles module. CologneBlue and Nostalgia skins serve as examples.
|
||||
|
|
|
|||
|
|
@ -220,10 +220,12 @@ class Revision implements IDBAccessObject {
|
|||
* RevisionStore::newMutableRevisionFromArray() can be used as a temporary replacement,
|
||||
* but should be avoided.
|
||||
*
|
||||
* @deprecated since 1.31 together with the Revision class. Hard deprecated since 1.35
|
||||
* @param object|array $row
|
||||
* @return Revision
|
||||
*/
|
||||
public static function newFromRow( $row ) {
|
||||
wfDeprecated( __METHOD__, '1.31' );
|
||||
if ( is_array( $row ) ) {
|
||||
$rec = self::getRevisionFactory()->newMutableRevisionFromArray( $row );
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
|
||||
/**
|
||||
* Helper class for category membership changes
|
||||
|
|
@ -43,7 +44,7 @@ class CategoryMembershipChange {
|
|||
private $pageTitle;
|
||||
|
||||
/**
|
||||
* @var Revision|null Latest Revision instance of the categorized page
|
||||
* @var RevisionRecord|null Latest Revision instance of the categorized page
|
||||
*/
|
||||
private $revision;
|
||||
|
||||
|
|
@ -61,18 +62,27 @@ class CategoryMembershipChange {
|
|||
|
||||
/**
|
||||
* @param Title $pageTitle Title instance of the categorized page
|
||||
* @param Revision|null $revision Latest Revision instance of the categorized page
|
||||
* @param RevisionRecord|Revision|null $revision Latest Revision instance of the categorized page.
|
||||
* Since 1.35 passing a Revision object is deprecated in favor of RevisionRecord.
|
||||
*
|
||||
* @throws MWException
|
||||
*/
|
||||
public function __construct( Title $pageTitle, Revision $revision = null ) {
|
||||
public function __construct( Title $pageTitle, $revision = null ) {
|
||||
$this->pageTitle = $pageTitle;
|
||||
if ( $revision === null ) {
|
||||
$this->timestamp = wfTimestampNow();
|
||||
} else {
|
||||
$this->timestamp = $revision->getTimestamp();
|
||||
}
|
||||
$this->revision = $revision;
|
||||
if ( $revision instanceof Revision ) {
|
||||
wfDeprecated(
|
||||
'Revision for ' . __METHOD__,
|
||||
'1.35'
|
||||
);
|
||||
$this->revision = $revision->getRevisionRecord();
|
||||
} else {
|
||||
$this->revision = $revision;
|
||||
}
|
||||
$this->newForCategorizationCallback = [ RecentChange::class, 'newForCategorization' ];
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +157,7 @@ class CategoryMembershipChange {
|
|||
* @param string $comment Change summary
|
||||
* @param Title $pageTitle Title of the page that is being added or removed
|
||||
* @param string $lastTimestamp Parent revision timestamp of this change in TS_MW format
|
||||
* @param Revision|null $revision
|
||||
* @param RevisionRecord|null $revision
|
||||
* @param bool $added true, if the category was added, false for removed
|
||||
*
|
||||
* @throws MWException
|
||||
|
|
@ -176,9 +186,14 @@ class CategoryMembershipChange {
|
|||
|
||||
# If no revision is given, the change was probably triggered by parser functions
|
||||
if ( $revision !== null ) {
|
||||
$correspondingRc = $this->revision->getRecentChange();
|
||||
$revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
|
||||
|
||||
$correspondingRc = $revisionStore->getRecentChange( $this->revision );
|
||||
if ( $correspondingRc === null ) {
|
||||
$correspondingRc = $this->revision->getRecentChange( Revision::READ_LATEST );
|
||||
$correspondingRc = $revisionStore->getRecentChange(
|
||||
$this->revision,
|
||||
RevisionStore::READ_LATEST
|
||||
);
|
||||
}
|
||||
if ( $correspondingRc !== null ) {
|
||||
$bot = $correspondingRc->getAttribute( 'rc_bot' ) ?: 0;
|
||||
|
|
@ -218,11 +233,9 @@ class CategoryMembershipChange {
|
|||
*/
|
||||
private function getUser() {
|
||||
if ( $this->revision ) {
|
||||
$userId = $this->revision->getUser( RevisionRecord::RAW );
|
||||
if ( $userId === 0 ) {
|
||||
return User::newFromName( $this->revision->getUserText( RevisionRecord::RAW ), false );
|
||||
} else {
|
||||
return User::newFromId( $userId );
|
||||
$userIdentity = $this->revision->getUser( RevisionRecord::RAW );
|
||||
if ( $userIdentity ) {
|
||||
return User::newFromIdentity( $userIdentity );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
* @file
|
||||
*/
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionLookup;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\RevisionStoreRecord;
|
||||
use Wikimedia\Rdbms\LBFactory;
|
||||
|
||||
/**
|
||||
|
|
@ -153,7 +156,8 @@ class CategoryMembershipChangeJob extends Job {
|
|||
// Find revisions to this page made around and after this revision which lack category
|
||||
// notifications in recent changes. This lets jobs pick up were the last one left off.
|
||||
$encCutoff = $dbr->addQuotes( $dbr->timestamp( $cutoffUnix ) );
|
||||
$revQuery = Revision::getQueryInfo();
|
||||
$revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
|
||||
$revQuery = $revisionStore->getQueryInfo();
|
||||
$res = $dbr->select(
|
||||
$revQuery['tables'],
|
||||
$revQuery['fields'],
|
||||
|
|
@ -169,7 +173,7 @@ class CategoryMembershipChangeJob extends Job {
|
|||
|
||||
// Apply all category updates in revision timestamp order
|
||||
foreach ( $res as $row ) {
|
||||
$this->notifyUpdatesForRevision( $lbFactory, $page, Revision::newFromRow( $row ) );
|
||||
$this->notifyUpdatesForRevision( $lbFactory, $page, $revisionStore->newRevisionFromRow( $row ) );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
@ -178,25 +182,27 @@ class CategoryMembershipChangeJob extends Job {
|
|||
/**
|
||||
* @param LBFactory $lbFactory
|
||||
* @param WikiPage $page
|
||||
* @param Revision $newRev
|
||||
* @param RevisionRecord $newRev
|
||||
* @throws MWException
|
||||
*/
|
||||
protected function notifyUpdatesForRevision(
|
||||
LBFactory $lbFactory, WikiPage $page, Revision $newRev
|
||||
LBFactory $lbFactory, WikiPage $page, RevisionRecord $newRev
|
||||
) {
|
||||
$config = RequestContext::getMain()->getConfig();
|
||||
$title = $page->getTitle();
|
||||
|
||||
// Get the new revision
|
||||
if ( !$newRev->getContent() ) {
|
||||
return; // deleted?
|
||||
if ( $newRev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the prior revision (the same for null edits)
|
||||
if ( $newRev->getParentId() ) {
|
||||
$oldRev = Revision::newFromId( $newRev->getParentId(), Revision::READ_LATEST );
|
||||
if ( !$oldRev || !$oldRev->getContent() ) {
|
||||
return; // deleted?
|
||||
$oldRev = MediaWikiServices::getInstance()
|
||||
->getRevisionLookup()
|
||||
->getRevisionById( $newRev->getParentId(), RevisionLookup::READ_LATEST );
|
||||
if ( !$oldRev || $oldRev->isDeleted( RevisionRecord::DELETED_TEXT ) ) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$oldRev = null;
|
||||
|
|
@ -233,7 +239,7 @@ class CategoryMembershipChangeJob extends Job {
|
|||
}
|
||||
|
||||
private function getExplicitCategoriesChanges(
|
||||
WikiPage $page, Revision $newRev, Revision $oldRev = null
|
||||
WikiPage $page, RevisionRecord $newRev, RevisionRecord $oldRev = null
|
||||
) {
|
||||
// Inject the same timestamp for both revision parses to avoid seeing category changes
|
||||
// due to time-based parser functions. Inject the same page title for the parses too.
|
||||
|
|
@ -256,20 +262,22 @@ class CategoryMembershipChangeJob extends Job {
|
|||
|
||||
/**
|
||||
* @param WikiPage $page
|
||||
* @param Revision $rev
|
||||
* @param RevisionRecord $rev
|
||||
* @param string $parseTimestamp TS_MW
|
||||
*
|
||||
* @return string[] category names
|
||||
*/
|
||||
private function getCategoriesAtRev( WikiPage $page, Revision $rev, $parseTimestamp ) {
|
||||
private function getCategoriesAtRev( WikiPage $page, RevisionRecord $rev, $parseTimestamp ) {
|
||||
$renderer = MediaWikiServices::getInstance()->getRevisionRenderer();
|
||||
$options = $page->makeParserOptions( 'canonical' );
|
||||
$options->setTimestamp( $parseTimestamp );
|
||||
|
||||
$output = $rev->isCurrent() ? $this->parserCache->get( $page, $options ) : null;
|
||||
$output = $rev instanceof RevisionStoreRecord && $rev->isCurrent()
|
||||
? $this->parserCache->get( $page, $options )
|
||||
: null;
|
||||
|
||||
if ( !$output || $output->getCacheRevisionId() !== $rev->getId() ) {
|
||||
$output = $renderer->getRenderedRevision( $rev->getRevisionRecord(), $options )
|
||||
$output = $renderer->getRenderedRevision( $rev, $options )
|
||||
->getRevisionParserOutput();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -382,6 +382,7 @@ class RevisionDbTest extends MediaWikiIntegrationTestCase {
|
|||
$row = $res->fetchObject();
|
||||
$res->free();
|
||||
|
||||
$this->hideDeprecated( Revision::class . '::newFromRow' );
|
||||
$rev = Revision::newFromRow( $row );
|
||||
|
||||
$this->assertRevEquals( $orig, $rev );
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
|
||||
/**
|
||||
* @covers CategoryMembershipChange
|
||||
*
|
||||
|
|
@ -62,7 +65,7 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase {
|
|||
self::$revUser = User::newFromId( self::$pageRev->getUser( Revision::RAW ) );
|
||||
}
|
||||
|
||||
private function newChange( Revision $revision = null ) {
|
||||
private function newChange( RevisionRecord $revision = null ) {
|
||||
$change = new CategoryMembershipChange( Title::newFromText( self::$pageName ), $revision );
|
||||
$change->overrideNewForCategorizationCallback(
|
||||
'CategoryMembershipChangeTest::newForCategorizationCallback'
|
||||
|
|
@ -112,7 +115,9 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase {
|
|||
}
|
||||
|
||||
public function testChangeAddedWithRev() {
|
||||
$revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() );
|
||||
$revision = MediaWikiServices::getInstance()
|
||||
->getRevisionLookup()
|
||||
->getRevisionByTitle( Title::newFromText( self::$pageName ) );
|
||||
$change = $this->newChange( $revision );
|
||||
$change->triggerCategoryAddedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
|
||||
|
||||
|
|
@ -133,7 +138,9 @@ class CategoryMembershipChangeTest extends MediaWikiLangTestCase {
|
|||
}
|
||||
|
||||
public function testChangeRemovedWithRev() {
|
||||
$revision = Revision::newFromId( Title::newFromText( self::$pageName )->getLatestRevID() );
|
||||
$revision = MediaWikiServices::getInstance()
|
||||
->getRevisionLookup()
|
||||
->getRevisionByTitle( Title::newFromText( self::$pageName ) );
|
||||
$change = $this->newChange( $revision );
|
||||
$change->triggerCategoryRemovedNotification( Title::newFromText( 'CategoryName', NS_CATEGORY ) );
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue