From d3cc06cc6aca04de03d9037684546cbb83cefd46 Mon Sep 17 00:00:00 2001 From: Reedy Date: Tue, 1 Nov 2022 21:51:15 -0600 Subject: [PATCH] Namespace Controller Change-Id: Ice356e774c153c353eb6ed71b8a02afd1ad1e654 --- extension.json | 2 -- includes/Api/ApiEchoMarkRead.php | 6 ++--- includes/Api/ApiEchoNotifications.php | 10 ++++----- .../ModerationController.php | 10 ++++++++- .../NotificationController.php | 22 ++++++++++++++++++- includes/DeferredMarkAsDeletedUpdate.php | 3 ++- .../Formatters/EchoEventPresentationModel.php | 4 ++-- .../EchoPageLinkedPresentationModel.php | 4 ++-- includes/Hooks.php | 12 +++++----- includes/jobs/NotificationJob.php | 4 +++- includes/model/Event.php | 3 ++- .../NotificationControllerTest.php | 20 ++++++++--------- 12 files changed, 65 insertions(+), 35 deletions(-) rename includes/{controller => Controller}/ModerationController.php (86%) rename includes/{controller => Controller}/NotificationController.php (97%) rename tests/phpunit/{controller => Controller}/NotificationControllerTest.php (93%) diff --git a/extension.json b/extension.json index 3ad5ec13a..c21bcab38 100644 --- a/extension.json +++ b/extension.json @@ -1101,11 +1101,9 @@ "MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionPresentationModel": "includes/Formatters/EchoMentionPresentationModel.php", "EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php", "MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php", - "EchoModerationController": "includes/controller/ModerationController.php", "EchoMultipleIterator": "includes/iterator/MultipleIterator.php", "EchoNotRecursiveIterator": "includes/iterator/NotRecursiveIterator.php", "EchoNotification": "includes/model/Notification.php", - "EchoNotificationController": "includes/controller/NotificationController.php", "EchoNotificationDeleteJob": "includes/jobs/NotificationDeleteJob.php", "EchoNotificationJob": "includes/jobs/NotificationJob.php", "EchoNotificationMapper": "includes/mapper/NotificationMapper.php", diff --git a/includes/Api/ApiEchoMarkRead.php b/includes/Api/ApiEchoMarkRead.php index f192fd50b..210969fa5 100644 --- a/includes/Api/ApiEchoMarkRead.php +++ b/includes/Api/ApiEchoMarkRead.php @@ -4,7 +4,7 @@ namespace MediaWiki\Extension\Notifications\Api; use ApiBase; use EchoAttributeManager; -use EchoNotificationController; +use MediaWiki\Extension\Notifications\Controller\NotificationController; use MWEchoDbFactory; use MWEchoNotifUser; use WikiMap; @@ -67,13 +67,13 @@ class ApiEchoMarkRead extends ApiBase { foreach ( EchoAttributeManager::$sections as $section ) { $rawSectionCount = $notifUser->getNotificationCount( $section ); $result[$section]['rawcount'] = $rawSectionCount; - $result[$section]['count'] = EchoNotificationController::formatNotificationCount( $rawSectionCount ); + $result[$section]['count'] = NotificationController::formatNotificationCount( $rawSectionCount ); $rawCount += $rawSectionCount; } $result += [ 'rawcount' => $rawCount, - 'count' => EchoNotificationController::formatNotificationCount( $rawCount ), + 'count' => NotificationController::formatNotificationCount( $rawCount ), ]; $this->getResult()->addValue( 'query', $this->getModuleName(), $result ); diff --git a/includes/Api/ApiEchoNotifications.php b/includes/Api/ApiEchoNotifications.php index ad7093e54..49782c486 100644 --- a/includes/Api/ApiEchoNotifications.php +++ b/includes/Api/ApiEchoNotifications.php @@ -11,10 +11,10 @@ use EchoAttributeManager; use EchoDataOutputFormatter; use EchoForeignNotifications; use EchoNotification; -use EchoNotificationController; use EchoNotificationMapper; use EchoSeenTime; use EchoServices; +use MediaWiki\Extension\Notifications\Controller\NotificationController; use MWEchoNotifUser; use Title; use User; @@ -357,12 +357,12 @@ class ApiEchoNotifications extends ApiQueryBase { $rawCount = $notifUser->getNotificationCount( $section, $global ); if ( $groupBySection ) { $result[$section]['rawcount'] = $rawCount; - $result[$section]['count'] = EchoNotificationController::formatNotificationCount( $rawCount ); + $result[$section]['count'] = NotificationController::formatNotificationCount( $rawCount ); } $totalRawCount += $rawCount; } $result['rawcount'] = $totalRawCount; - $result['count'] = EchoNotificationController::formatNotificationCount( $totalRawCount ); + $result['count'] = NotificationController::formatNotificationCount( $totalRawCount ); return $result; } @@ -541,7 +541,7 @@ class ApiEchoNotifications extends ApiQueryBase { foreach ( $results as $result ) { $primary[$section]['rawcount'] += $result[$section]['rawcount']; } - $primary[$section]['count'] = EchoNotificationController::formatNotificationCount( + $primary[$section]['count'] = NotificationController::formatNotificationCount( $primary[$section]['rawcount'] ); } } @@ -553,7 +553,7 @@ class ApiEchoNotifications extends ApiQueryBase { // regardless of groupbysection, totals are always included $primary['rawcount'] += $result['rawcount']; } - $primary['count'] = EchoNotificationController::formatNotificationCount( $primary['rawcount'] ); + $primary['count'] = NotificationController::formatNotificationCount( $primary['rawcount'] ); return $primary; } diff --git a/includes/controller/ModerationController.php b/includes/Controller/ModerationController.php similarity index 86% rename from includes/controller/ModerationController.php rename to includes/Controller/ModerationController.php index 5f7902032..0047ceb26 100644 --- a/includes/controller/ModerationController.php +++ b/includes/Controller/ModerationController.php @@ -1,11 +1,19 @@ events = []; } } diff --git a/includes/Formatters/EchoEventPresentationModel.php b/includes/Formatters/EchoEventPresentationModel.php index 0a74f1d4e..be33c2c55 100644 --- a/includes/Formatters/EchoEventPresentationModel.php +++ b/includes/Formatters/EchoEventPresentationModel.php @@ -3,10 +3,10 @@ namespace MediaWiki\Extension\Notifications\Formatters; use EchoEvent; -use EchoNotificationController; use InvalidArgumentException; use JsonSerializable; use Language; +use MediaWiki\Extension\Notifications\Controller\NotificationController; use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RevisionRecord; use Message; @@ -264,7 +264,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo */ final protected function getNotificationCountForOutput( $includeCurrent = true, $groupCallback = null ) { $count = $this->getBundleCount( $includeCurrent, $groupCallback ); - return EchoNotificationController::getCappedNotificationCount( $count ); + return NotificationController::getCappedNotificationCount( $count ); } /** diff --git a/includes/Formatters/EchoPageLinkedPresentationModel.php b/includes/Formatters/EchoPageLinkedPresentationModel.php index a012ce92a..cc759148e 100644 --- a/includes/Formatters/EchoPageLinkedPresentationModel.php +++ b/includes/Formatters/EchoPageLinkedPresentationModel.php @@ -3,7 +3,7 @@ namespace MediaWiki\Extension\Notifications\Formatters; use EchoEvent; -use EchoNotificationController; +use MediaWiki\Extension\Notifications\Controller\NotificationController; use MediaWiki\MediaWikiServices; use SpecialPage; use Title; @@ -72,7 +72,7 @@ class EchoPageLinkedPresentationModel extends EchoEventPresentationModel { return null; } $title = $this->event->getTitle(); - $isPageMuted = EchoNotificationController::isPageLinkedTitleMutedByUser( $title, $this->getUser() ); + $isPageMuted = NotificationController::isPageLinkedTitleMutedByUser( $title, $this->getUser() ); $action = $isPageMuted ? 'unmute' : 'mute'; $prefTitle = SpecialPage::getTitleFor( 'Preferences', false, 'mw-prefsection-echo-mutedpageslist' ); $data = [ diff --git a/includes/Hooks.php b/includes/Hooks.php index 2b19b29c2..1c1b34ddf 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -13,9 +13,7 @@ use EchoEmailFormat; use EchoEmailFrequency; use EchoEvent; use EchoEventMapper; -use EchoModerationController; use EchoNotification; -use EchoNotificationController; use EchoNotificationMapper; use EchoSeenTime; use EchoServices; @@ -29,6 +27,8 @@ use MailAddress; use MediaWiki\Api\Hook\ApiMain__moduleManagerHook; use MediaWiki\Auth\Hook\LocalUserCreatedHook; use MediaWiki\DAO\WikiAwareEntity; +use MediaWiki\Extension\Notifications\Controller\ModerationController; +use MediaWiki\Extension\Notifications\Controller\NotificationController; use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel; use MediaWiki\Extension\Notifications\Push\Api\ApiEchoPushSubscriptions; use MediaWiki\Hook\AbortTalkPageEmailNotificationHook; @@ -1084,8 +1084,8 @@ class Hooks implements 'notice' => $seenMsgTime, ] ); - $msgFormattedCount = EchoNotificationController::formatNotificationCount( $msgCount ); - $alertFormattedCount = EchoNotificationController::formatNotificationCount( $alertCount ); + $msgFormattedCount = NotificationController::formatNotificationCount( $msgCount ); + $alertFormattedCount = NotificationController::formatNotificationCount( $alertCount ); $url = SpecialPage::getTitleFor( 'Notifications' )->getLocalURL(); @@ -1637,7 +1637,7 @@ class Hooks implements DeferredUpdates::addCallableUpdate( static function () use ( $articleId ) { $eventMapper = new EchoEventMapper(); $eventIds = $eventMapper->fetchIdsByPage( $articleId ); - EchoModerationController::moderate( $eventIds, true ); + ModerationController::moderate( $eventIds, true ); } ); } @@ -1653,7 +1653,7 @@ class Hooks implements DeferredUpdates::addCallableUpdate( static function () use ( $oldPageId ) { $eventMapper = new EchoEventMapper(); $eventIds = $eventMapper->fetchIdsByPage( $oldPageId ); - EchoModerationController::moderate( $eventIds, false ); + ModerationController::moderate( $eventIds, false ); } ); } } diff --git a/includes/jobs/NotificationJob.php b/includes/jobs/NotificationJob.php index d323e29a7..fec322e64 100644 --- a/includes/jobs/NotificationJob.php +++ b/includes/jobs/NotificationJob.php @@ -1,5 +1,7 @@ fetchById( $this->params['eventId'], true ); - EchoNotificationController::notify( $event, false ); + NotificationController::notify( $event, false ); return true; } diff --git a/includes/model/Event.php b/includes/model/Event.php index 42a007f6c..106bb6dc2 100644 --- a/includes/model/Event.php +++ b/includes/model/Event.php @@ -1,5 +1,6 @@ getStatsdDataFactory(); $type = $info['type']; diff --git a/tests/phpunit/controller/NotificationControllerTest.php b/tests/phpunit/Controller/NotificationControllerTest.php similarity index 93% rename from tests/phpunit/controller/NotificationControllerTest.php rename to tests/phpunit/Controller/NotificationControllerTest.php index 954570e6b..f307ad413 100644 --- a/tests/phpunit/controller/NotificationControllerTest.php +++ b/tests/phpunit/Controller/NotificationControllerTest.php @@ -1,10 +1,11 @@ assertEquals( $expect, array_map( 'array_keys', $result ), $message ); } @@ -160,7 +161,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { $event->method( 'getType' ) ->willReturn( 'unit-test' ); - $result = EchoNotificationController::getUsersToNotifyForEvent( $event ); + $result = NotificationController::getUsersToNotifyForEvent( $event ); $ids = []; foreach ( $result as $user ) { $ids[] = $user->getId(); @@ -177,7 +178,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { $event->expects( $this->never() ) ->method( 'getType' ); - EchoNotificationController::notify( $event, false ); + NotificationController::notify( $event, false ); } public static function getEventNotifyTypesProvider() { @@ -251,7 +252,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { [ 'priority' => 4 ] ), ] ); - $result = EchoNotificationController::getEventNotifyTypes( $type ); + $result = NotificationController::getEventNotifyTypes( $type ); $this->assertEquals( $expect, $result, $message ); } @@ -265,7 +266,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { $event->expects( $this->once() ) ->method( 'getId' ) ->willReturn( 42 ); - EchoNotificationController::enqueueEvent( $event ); + NotificationController::enqueueEvent( $event ); $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup(); $queues = $jobQueueGroup->getQueuesWithJobs(); $this->assertCount( 1, $queues ); @@ -293,7 +294,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { ->willReturn( Title::newFromText( 'test-title' ) ); $event->method( 'getId' ) ->willReturn( 42 ); - EchoNotificationController::enqueueEvent( $event ); + NotificationController::enqueueEvent( $event ); $this->assertCount( 0, $queueGroup->getQueuesWithJobs() ); } @@ -315,7 +316,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { ->method( 'getId' ) ->willReturn( 42 ); - $params = EchoNotificationController::getEventParams( $event ); + $params = NotificationController::getEventParams( $event ); $expectedParams = [ 'eventId' => 42, 'rootJobSignature' => 'test-signature', @@ -327,7 +328,6 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { /** * @dataProvider PageLinkedTitleMutedByUserDataProvider - * @covers EchoNotificationController::isPageLinkedTitleMutedByUser * @param Title $title * @param User $user * @param UserOptionsLookup $userOptionsLookup @@ -335,7 +335,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase { */ public function testIsPageLinkedTitleMutedByUser( Title $title, User $user, UserOptionsLookup $userOptionsLookup, $expected ): void { - $wrapper = TestingAccessWrapper::newFromClass( EchoNotificationController::class ); + $wrapper = TestingAccessWrapper::newFromClass( NotificationController::class ); $wrapper->mutedPageLinkedTitlesCache = $this->createMock( MapCacheLRU::class ); $this->setService( 'UserOptionsLookup', $userOptionsLookup ); $this->assertSame(