Inject dependencies into ApiSetNotificationTimestamp
Bug: T259960 Change-Id: I8123dea3269a26c1fda8d1f301903aeb4534db0a
This commit is contained in:
parent
eff825dcd6
commit
627104459f
2 changed files with 56 additions and 12 deletions
|
|
@ -94,7 +94,14 @@ class ApiMain extends ApiBase {
|
|||
|
||||
// Write modules
|
||||
'purge' => ApiPurge::class,
|
||||
'setnotificationtimestamp' => ApiSetNotificationTimestamp::class,
|
||||
'setnotificationtimestamp' => [
|
||||
'class' => ApiSetNotificationTimestamp::class,
|
||||
'services' => [
|
||||
'DBLoadBalancer',
|
||||
'RevisionStore',
|
||||
'WatchedItemStore',
|
||||
]
|
||||
],
|
||||
'rollback' => ApiRollback::class,
|
||||
'delete' => ApiDelete::class,
|
||||
'undelete' => ApiUndelete::class,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
use Wikimedia\Rdbms\ILoadBalancer;
|
||||
|
||||
/**
|
||||
* API interface for setting the wl_notificationtimestamp field
|
||||
|
|
@ -33,6 +34,36 @@ class ApiSetNotificationTimestamp extends ApiBase {
|
|||
|
||||
private $mPageSet = null;
|
||||
|
||||
/** @var RevisionStore */
|
||||
private $revisionStore;
|
||||
|
||||
/** @var ILoadBalancer */
|
||||
private $loadBalancer;
|
||||
|
||||
/** @var WatchedItemStoreInterface */
|
||||
private $watchedItemStore;
|
||||
|
||||
/**
|
||||
* @param ApiMain $main
|
||||
* @param string $action
|
||||
* @param ILoadBalancer $loadBalancer
|
||||
* @param RevisionStore $revisionStore
|
||||
* @param WatchedItemStoreInterface $watchedItemStore
|
||||
*/
|
||||
public function __construct(
|
||||
ApiMain $main,
|
||||
$action,
|
||||
ILoadBalancer $loadBalancer,
|
||||
RevisionStore $revisionStore,
|
||||
WatchedItemStoreInterface $watchedItemStore
|
||||
) {
|
||||
parent::__construct( $main, $action );
|
||||
|
||||
$this->loadBalancer = $loadBalancer;
|
||||
$this->revisionStore = $revisionStore;
|
||||
$this->watchedItemStore = $watchedItemStore;
|
||||
}
|
||||
|
||||
public function execute() {
|
||||
$user = $this->getUser();
|
||||
|
||||
|
|
@ -59,7 +90,7 @@ class ApiSetNotificationTimestamp extends ApiBase {
|
|||
);
|
||||
}
|
||||
|
||||
$dbw = wfGetDB( DB_MASTER, 'api' );
|
||||
$dbw = $this->loadBalancer->getConnectionRef( DB_MASTER, 'api' );
|
||||
|
||||
$timestamp = null;
|
||||
if ( isset( $params['timestamp'] ) ) {
|
||||
|
|
@ -78,8 +109,10 @@ class ApiSetNotificationTimestamp extends ApiBase {
|
|||
$title = reset( $titles );
|
||||
if ( $title ) {
|
||||
// XXX $title isn't actually used, can we just get rid of the previous six lines?
|
||||
$timestamp = MediaWikiServices::getInstance()->getRevisionStore()
|
||||
->getTimestampFromId( $params['torevid'], IDBAccessObject::READ_LATEST );
|
||||
$timestamp = $this->revisionStore->getTimestampFromId(
|
||||
$params['torevid'],
|
||||
IDBAccessObject::READ_LATEST
|
||||
);
|
||||
if ( $timestamp ) {
|
||||
$timestamp = $dbw->timestamp( $timestamp );
|
||||
} else {
|
||||
|
|
@ -94,10 +127,15 @@ class ApiSetNotificationTimestamp extends ApiBase {
|
|||
$title = reset( $titles );
|
||||
if ( $title ) {
|
||||
$timestamp = null;
|
||||
$rl = MediaWikiServices::getInstance()->getRevisionLookup();
|
||||
$currRev = $rl->getRevisionById( $params['newerthanrevid'], Title::READ_LATEST );
|
||||
$currRev = $this->revisionStore->getRevisionById(
|
||||
$params['newerthanrevid'],
|
||||
Title::READ_LATEST
|
||||
);
|
||||
if ( $currRev ) {
|
||||
$nextRev = $rl->getNextRevision( $currRev, Title::READ_LATEST );
|
||||
$nextRev = $this->revisionStore->getNextRevision(
|
||||
$currRev,
|
||||
Title::READ_LATEST
|
||||
);
|
||||
if ( $nextRev ) {
|
||||
$timestamp = $dbw->timestamp( $nextRev->getTimestamp() );
|
||||
}
|
||||
|
|
@ -105,12 +143,11 @@ class ApiSetNotificationTimestamp extends ApiBase {
|
|||
}
|
||||
}
|
||||
|
||||
$watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
|
||||
$apiResult = $this->getResult();
|
||||
$result = [];
|
||||
if ( $params['entirewatchlist'] ) {
|
||||
// Entire watchlist mode: Just update the thing and return a success indicator
|
||||
$watchedItemStore->resetAllNotificationTimestampsForUser( $user, $timestamp );
|
||||
$this->watchedItemStore->resetAllNotificationTimestampsForUser( $user, $timestamp );
|
||||
|
||||
$result['notificationtimestamp'] = $timestamp === null
|
||||
? ''
|
||||
|
|
@ -138,14 +175,14 @@ class ApiSetNotificationTimestamp extends ApiBase {
|
|||
|
||||
if ( $pageSet->getTitles() ) {
|
||||
// Now process the valid titles
|
||||
$watchedItemStore->setNotificationTimestampsForUser(
|
||||
$this->watchedItemStore->setNotificationTimestampsForUser(
|
||||
$user,
|
||||
$timestamp,
|
||||
$pageSet->getTitles()
|
||||
);
|
||||
|
||||
// Query the results of our update
|
||||
$timestamps = $watchedItemStore->getNotificationTimestampsBatch(
|
||||
$timestamps = $this->watchedItemStore->getNotificationTimestampsBatch(
|
||||
$user,
|
||||
$pageSet->getTitles()
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue