Merge "Replace deprecated Title::newFromIDs"

This commit is contained in:
jenkins-bot 2021-10-04 14:36:27 +00:00 committed by Gerrit Code Review
commit 30cd2a226f
3 changed files with 40 additions and 4 deletions

View file

@ -22,7 +22,10 @@
"class": "ApiEchoNotifications",
"services": [ "MainConfig" ]
},
"unreadnotificationpages": "ApiEchoUnreadNotificationPages"
"unreadnotificationpages": {
"class": "ApiEchoUnreadNotificationPages",
"services": [ "PageStore", "TitleFactory" ]
}
},
"APIModules": {
"echomarkread": "ApiEchoMarkRead",

View file

@ -1,6 +1,8 @@
<?php
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\Page\PageRecord;
use MediaWiki\Page\PageStore;
class ApiEchoUnreadNotificationPages extends ApiQueryBase {
use ApiCrossWiki;
@ -10,12 +12,26 @@ class ApiEchoUnreadNotificationPages extends ApiQueryBase {
*/
protected $crossWikiSummary = false;
/**
* @var PageStore
*/
private $pageStore;
/**
* @var TitleFactory
*/
private $titleFactory;
/**
* @param ApiQuery $query
* @param string $moduleName
* @param PageStore $pageStore
* @param TitleFactory $titleFactory
*/
public function __construct( $query, $moduleName ) {
public function __construct( $query, $moduleName, PageStore $pageStore, TitleFactory $titleFactory ) {
parent::__construct( $query, $moduleName, 'unp' );
$this->pageStore = $pageStore;
$this->titleFactory = $titleFactory;
}
/**
@ -96,10 +112,16 @@ class ApiEchoUnreadNotificationPages extends ApiQueryBase {
}
}
$titles = Title::newFromIDs( array_keys( $pageCounts ) );
$titles = $this->pageStore
->newSelectQueryBuilder()
->wherePageIds( array_keys( $pageCounts ) )
->caller( __METHOD__ )
->fetchPageRecords();
$groupCounts = [];
/** @var PageRecord $title */
foreach ( $titles as $title ) {
$title = $this->titleFactory->castFromPageIdentity( $title );
if ( $groupPages ) {
// If $title is a talk page, add its count to its subject page's count
$pageName = $title->getSubjectPage()->getPrefixedText();

View file

@ -1,5 +1,8 @@
<?php
use MediaWiki\MediaWikiServices;
use MediaWiki\Page\PageRecord;
/**
* Cache class that maps article id to Title object
*/
@ -26,8 +29,16 @@ class EchoTitleLocalCache extends EchoLocalCache {
*/
protected function resolve( array $lookups ) {
if ( $lookups ) {
$titles = Title::newFromIDs( $lookups );
$titles = MediaWikiServices::getInstance()
->getPageStore()
->newSelectQueryBuilder()
->wherePageIds( $lookups )
->caller( __METHOD__ )
->fetchPageRecords();
/** @var PageRecord $title */
foreach ( $titles as $title ) {
$title = MediaWikiServices::getInstance()->getTitleFactory()->castFromPageIdentity( $title );
yield $title->getArticleID() => $title;
}
}