From 24de2ebf71e3984237eb41a17e6d0607ff114097 Mon Sep 17 00:00:00 2001 From: DannyS712 Date: Mon, 27 Apr 2020 18:20:58 +0000 Subject: [PATCH] FeedUtils: Remove use of Revision objects Bug: T250981 Bug: T249021 Change-Id: I0251865f6f1f5ab0627d5eac92d0e210284bc291 --- includes/FeedUtils.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/includes/FeedUtils.php b/includes/FeedUtils.php index 8d772281708..ad9b6417b01 100644 --- a/includes/FeedUtils.php +++ b/includes/FeedUtils.php @@ -23,6 +23,7 @@ use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RevisionRecord; +use MediaWiki\Revision\SlotRecord; /** * Helper functions for feeds @@ -105,7 +106,8 @@ class FeedUtils { // No "privileged" version should end up in the cache. // Most feed readers will not log in anyway. $anon = new User(); - $permManager = MediaWikiServices::getInstance()->getPermissionManager(); + $services = MediaWikiServices::getInstance(); + $permManager = $services->getPermissionManager(); $accErrors = $permManager->getPermissionErrors( 'read', $anon, @@ -118,19 +120,25 @@ class FeedUtils { return $completeText; } + $revLookup = $services->getRevisionLookup(); + $contentHandlerFactory = $services->getContentHandlerFactory(); if ( $oldid ) { $diffText = ''; // Don't bother generating the diff if we won't be able to show it if ( $wgFeedDiffCutoff > 0 ) { - $rev = Revision::newFromId( $oldid ); + $revRecord = $revLookup->getRevisionById( $oldid ); - if ( !$rev ) { + if ( !$revRecord ) { $diffText = false; } else { $context = clone RequestContext::getMain(); $context->setTitle( $title ); - $contentHandler = $rev->getContentHandler(); + $model = $revRecord->getSlot( + SlotRecord::MAIN, + RevisionRecord::RAW + )->getModel(); + $contentHandler = $contentHandlerFactory->getContentHandler( $model ); $de = $contentHandler->createDifferenceEngine( $context, $oldid, $newid ); $diffText = $de->getDiff( wfMessage( 'previousrevision' )->text(), // hack @@ -153,14 +161,13 @@ class FeedUtils { $diffText = self::applyDiffStyle( $diffText ); } } else { - $rev = Revision::newFromId( $newid ); - if ( $wgFeedDiffCutoff <= 0 || $rev === null ) { - $newContent = MediaWikiServices::getInstance() - ->getContentHandlerFactory() + $revRecord = $revLookup->getRevisionById( $newid ); + if ( $wgFeedDiffCutoff <= 0 || $revRecord === null ) { + $newContent = $contentHandlerFactory ->getContentHandler( $title->getContentModel() ) ->makeEmptyContent(); } else { - $newContent = $rev->getContent(); + $newContent = $revRecord->getContent( SlotRecord::MAIN ); } if ( $newContent instanceof TextContent ) {