Namespace a few more classes

Change-Id: Ie233a4c8291432da3bd25d29337db52a2e97b540
This commit is contained in:
Reedy 2022-11-13 00:48:43 -07:00
parent e576cbdca0
commit b003945c34
30 changed files with 144 additions and 111 deletions

View file

@ -1061,10 +1061,6 @@
"MediaWiki\\Extension\\Notifications\\AttributeManager": "includes/AttributeManager.php",
"EchoCallbackIterator": "includes/Iterator/CallbackIterator.php",
"MediaWiki\\Extension\\Notifications\\Iterator\\CallbackIterator": "includes/Iterator/CallbackIterator.php",
"EchoDataOutputFormatter": "includes/DataOutputFormatter.php",
"EchoDeferredMarkAsDeletedUpdate": "includes/DeferredMarkAsDeletedUpdate.php",
"EchoDiffGroup": "includes/EchoDiffGroup.php",
"EchoDiffParser": "includes/EchoDiffParser.php",
"EchoDiscussionParser": "includes/DiscussionParser.php",
"MediaWiki\\Extension\\Notifications\\DiscussionParser": "includes/DiscussionParser.php",
"EchoEditUserTalkPresentationModel": "includes/Formatters/EchoEditUserTalkPresentationModel.php",
@ -1088,16 +1084,13 @@
"EchoPresentationModelSection": "includes/Formatters/EchoPresentationModelSection.php",
"MediaWiki\\Extension\\Notifications\\Formatters\\EchoPresentationModelSection": "includes/Formatters/EchoPresentationModelSection.php",
"EchoServices": "includes/EchoServices.php",
"EchoSummaryParser": "includes/EchoSummaryParser.php",
"EchoSuppressionRowUpdateGenerator": "includes/schemaUpdate.php",
"EchoUnreadWikis": "includes/UnreadWikis.php",
"EchoUserLocator": "includes/UserLocator.php",
"MediaWiki\\Extension\\Notifications\\UserLocator": "includes/UserLocator.php",
"GenerateSampleNotifications": "maintenance/generateSampleNotifications.php",
"MWEchoDbFactory": "includes/DbFactory.php",
"MediaWiki\\Extension\\Notifications\\DbFactory": "includes/DbFactory.php",
"MWEchoEventLogging": "includes/EventLogging.php",
"MWEchoNotifUser": "includes/NotifUser.php",
"ProcessEchoEmailBatch": "maintenance/processEchoEmailBatch.php",
"RecomputeNotifCounts": "maintenance/recomputeNotifCounts.php",
"RemoveInvalidNotification": "maintenance/removeInvalidNotification.php",

View file

@ -6,8 +6,8 @@ use ApiBase;
use MediaWiki\Extension\Notifications\AttributeManager;
use MediaWiki\Extension\Notifications\Controller\NotificationController;
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\WikiMap\WikiMap;
use MWEchoNotifUser;
use Wikimedia\ParamValidator\ParamValidator;
class ApiEchoMarkRead extends ApiBase {
@ -24,7 +24,7 @@ class ApiEchoMarkRead extends ApiBase {
$this->dieReadOnly();
}
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$params = $this->extractRequestParams();

View file

@ -6,17 +6,17 @@ use ApiBase;
use ApiQuery;
use ApiQueryBase;
use Config;
use EchoDataOutputFormatter;
use EchoForeignNotifications;
use EchoServices;
use MediaWiki\Extension\Notifications\AttributeManager;
use MediaWiki\Extension\Notifications\Bundler;
use MediaWiki\Extension\Notifications\Controller\NotificationController;
use MediaWiki\Extension\Notifications\DataOutputFormatter;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\Model\Notification;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\Extension\Notifications\SeenTime;
use MediaWiki\WikiMap\WikiMap;
use MWEchoNotifUser;
use Title;
use User;
use Wikimedia\ParamValidator\ParamValidator;
@ -320,7 +320,7 @@ class ApiEchoNotifications extends ApiQueryBase {
while ( $notifs !== [] ) {
/** @var Notification $notif */
$notif = array_shift( $notifs );
$output = EchoDataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() );
$output = DataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() );
if ( $output !== false ) {
$result['list'][] = $output;
} elseif ( $bundler && $notif->getBundledNotifications() ) {
@ -350,7 +350,7 @@ class ApiEchoNotifications extends ApiQueryBase {
*/
protected function getPropCount( User $user, array $sections, $groupBySection ) {
$result = [];
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$global = $this->crossWikiSummary ? 'preference' : false;
$totalRawCount = 0;
@ -445,7 +445,7 @@ class ApiEchoNotifications extends ApiQueryBase {
// Format output like any other notification
$notif = Notification::newFromRow( $row );
$output = EchoDataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() );
$output = DataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() );
// Add cross-wiki-specific data
$output['section'] = $section ?: 'all';

View file

@ -7,12 +7,12 @@ use ApiQueryBase;
use ApiUsageException;
use EchoServices;
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\Page\PageRecord;
use MediaWiki\Page\PageStore;
use MediaWiki\Title\TitleFactory;
use MediaWiki\WikiMap\WikiMap;
use MWEchoNotifUser;
use Title;
use Wikimedia\ParamValidator\ParamValidator;
use Wikimedia\ParamValidator\TypeDef\IntegerDef;
@ -198,7 +198,7 @@ class ApiEchoUnreadNotificationPages extends ApiQueryBase {
return [
'pages' => $result,
'totalCount' => MWEchoNotifUser::newFromUser( $this->getUser() )->getLocalNotificationCount(),
'totalCount' => NotifUser::newFromUser( $this->getUser() )->getLocalNotificationCount(),
];
}

View file

@ -5,8 +5,8 @@ namespace MediaWiki\Extension\Notifications\Controller;
use DeferredUpdates;
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\MediaWikiServices;
use MWEchoNotifUser;
use User;
/**
@ -43,7 +43,7 @@ class ModerationController {
// users whose notifications have been moderated.
foreach ( $affectedUserIds as $userId ) {
$user = User::newFromId( $userId );
MWEchoNotifUser::newFromUser( $user )->resetNotificationCount();
NotifUser::newFromUser( $user )->resetNotificationCount();
}
} );
}

View file

@ -16,12 +16,12 @@ use MediaWiki\Extension\Notifications\Iterator\FilteredSequentialIterator;
use MediaWiki\Extension\Notifications\Jobs\NotificationDeleteJob;
use MediaWiki\Extension\Notifications\Jobs\NotificationJob;
use MediaWiki\Extension\Notifications\Model\Event;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\Extension\Notifications\OnWikiList;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionStore;
use MediaWiki\User\UserIdentity;
use MWEchoNotifUser;
use Title;
use User;
@ -80,7 +80,7 @@ class NotificationController {
* @return int Notification count, with ceiling applied
*/
public static function getCappedNotificationCount( int $count ): int {
return min( $count, MWEchoNotifUser::MAX_BADGE_COUNT + 1 );
return min( $count, NotifUser::MAX_BADGE_COUNT + 1 );
}
/**

View file

@ -1,5 +1,9 @@
<?php
namespace MediaWiki\Extension\Notifications;
use EchoServices;
use Language;
use MediaWiki\Extension\Notifications\Formatters\EchoEventFormatter;
use MediaWiki\Extension\Notifications\Formatters\EchoFlyoutFormatter;
use MediaWiki\Extension\Notifications\Formatters\EchoModelFormatter;
@ -8,12 +12,15 @@ use MediaWiki\Extension\Notifications\Model\Event;
use MediaWiki\Extension\Notifications\Model\Notification;
use MediaWiki\Revision\RevisionRecord;
use MediaWiki\WikiMap\WikiMap;
use MWTimestamp;
use RequestContext;
use User;
/**
* Utility class that formats a notification in the format specified
* @todo Make this a service with DI
*/
class EchoDataOutputFormatter {
class DataOutputFormatter {
/**
* @var string[] type => class
@ -157,7 +164,7 @@ class EchoDataOutputFormatter {
$formatted = self::formatNotification( $event, $user, $format, $lang );
if ( $formatted === false ) {
// Can't display it, so mark it as read
EchoDeferredMarkAsDeletedUpdate::add( $event );
DeferredMarkAsDeletedUpdate::add( $event );
return false;
}
$output['*'] = $formatted;

View file

@ -1,5 +1,9 @@
<?php
namespace MediaWiki\Extension\Notifications;
use DeferrableUpdate;
use DeferredUpdates;
use MediaWiki\Extension\Notifications\Controller\ModerationController;
use MediaWiki\Extension\Notifications\Model\Event;
use MediaWiki\Logger\LoggerFactory;
@ -8,7 +12,7 @@ use MediaWiki\Logger\LoggerFactory;
* Mark event notifications as deleted at the end of a request. Used to queue up
* individual events to mark due to formatting failures.
*/
class EchoDeferredMarkAsDeletedUpdate implements DeferrableUpdate {
class DeferredMarkAsDeletedUpdate implements DeferrableUpdate {
/**
* @var Event[]
*/
@ -42,7 +46,7 @@ class EchoDeferredMarkAsDeletedUpdate implements DeferrableUpdate {
// unrenderable because of replica lag.
// Do not moderate it at this time.
LoggerFactory::getInstance( 'Echo' )->debug(
'EchoDeferredMarkAsDeletedUpdate: Event {eventId} was found unrenderable' .
'DeferredMarkAsDeletedUpdate: Event {eventId} was found unrenderable' .
' but its associated title exists on primary database. Skipping.',
[
'eventId' => $event->getId(),

View file

@ -1,4 +1,7 @@
<?php
namespace MediaWiki\Extension\Notifications;
/**
* MediaWiki Extension: Echo
*
@ -24,7 +27,7 @@
/**
* Represents a single set of changes all effecting neighboring lines
*/
class EchoDiffGroup {
class DiffGroup {
/**
* @var int[] The left and right position this change starts at
*/

View file

@ -1,4 +1,7 @@
<?php
namespace MediaWiki\Extension\Notifications;
/**
* MediaWiki Extension: Echo
*
@ -21,6 +24,7 @@
* @author Erik Bernhardson
*/
use UnexpectedValueException;
use Wikimedia\Diff\Diff;
use Wikimedia\Diff\UnifiedDiffFormatter;
@ -31,7 +35,7 @@ use Wikimedia\Diff\UnifiedDiffFormatter;
* to stay consistent with the original diff output and the previous diff
* parsing code.
*/
class EchoDiffParser {
class DiffParser {
/**
* @var int The number of characters the diff prefixes a line with
@ -170,11 +174,11 @@ class EchoDiffParser {
* Parse the next line of the unified diff output
*
* @param string $line The next line of the unified diff
* @param EchoDiffGroup|null $change Changes the immediately previous lines
* @param DiffGroup|null $change Changes the immediately previous lines
*
* @return EchoDiffGroup|null Changes to this line and any changed lines immediately previous
* @return DiffGroup|null Changes to this line and any changed lines immediately previous
*/
protected function parseLine( $line, EchoDiffGroup $change = null ) {
protected function parseLine( $line, DiffGroup $change = null ) {
if ( $line ) {
$op = $line[0];
if ( strlen( $line ) > $this->prefixLength ) {
@ -222,7 +226,7 @@ class EchoDiffParser {
}
if ( $change === null ) {
// @phan-suppress-next-line PhanTypeMismatchArgument
$change = new EchoDiffGroup( $this->leftPos, $this->rightPos );
$change = new DiffGroup( $this->leftPos, $this->rightPos );
}
$change->subtract( $line );
$this->leftPos++;
@ -235,7 +239,7 @@ class EchoDiffParser {
}
if ( $change === null ) {
// @phan-suppress-next-line PhanTypeMismatchArgument
$change = new EchoDiffGroup( $this->leftPos, $this->rightPos );
$change = new DiffGroup( $this->leftPos, $this->rightPos );
}
$change->add( $line );
$this->rightPos++;

View file

@ -3,8 +3,6 @@
namespace MediaWiki\Extension\Notifications;
use Article;
use EchoDiffParser;
use EchoSummaryParser;
use Language;
use MediaWiki\Extension\Notifications\Hooks\HookRunner;
use MediaWiki\Extension\Notifications\Model\Event;
@ -28,9 +26,11 @@ abstract class DiscussionParser {
/** @var string|null */
protected static $timestampRegex;
/** @var array[][] */
protected static $revisionInterpretationCache = [];
/** @var EchoDiffParser|null */
/** @var DiffParser|null */
protected static $diffParser;
/**
@ -157,7 +157,7 @@ abstract class DiscussionParser {
global $wgEchoMaxMentionsInEditSummary;
if ( $wgEchoMaxMentionsInEditSummary > 0 && !$user->isBot() && !$isRevert ) {
$summaryParser = new EchoSummaryParser();
$summaryParser = new SummaryParser();
$usersInSummary = $summaryParser->parse( $revision->getComment()->text );
// Don't allow pinging yourself
@ -1000,7 +1000,7 @@ abstract class DiscussionParser {
*/
public static function getMachineReadableDiff( $oldText, $newText ) {
if ( !isset( self::$diffParser ) ) {
self::$diffParser = new EchoDiffParser;
self::$diffParser = new DiffParser;
}
return self::$diffParser->getChangeSet( $oldText, $newText );

View file

@ -13,7 +13,6 @@ use MediaWiki\Languages\LanguageFactory;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserOptionsManager;
use MWEchoEventLogging;
use MWEchoNotifUser;
use stdClass;
use User;
use UserMailer;
@ -350,7 +349,7 @@ class EmailBatch {
return;
}
$format = MWEchoNotifUser::newFromUser( $this->mUser )->getEmailFormat();
$format = NotifUser::newFromUser( $this->mUser )->getEmailFormat();
if ( $format == EmailFormat::HTML ) {
$htmlEmailDigestFormatter = new EchoHtmlDigestEmailFormatter( $this->mUser, $this->language, $frequency );
$htmlContent = $htmlEmailDigestFormatter->format( $this->events, 'email' );

View file

@ -1,12 +1,14 @@
<?php
use MediaWiki\Extension\Notifications\AttributeManager;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\Extension\Notifications\UnreadWikis;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserIdentity;
use MediaWiki\WikiMap\WikiMap;
/**
* Caches the result of EchoUnreadWikis::getUnreadCounts() and interprets the results in various useful ways.
* Caches the result of UnreadWikis::getUnreadCounts() and interprets the results in various useful ways.
*
* If the user has disabled cross-wiki notifications in their preferences
* (see {@see EchoForeignNotifications::isEnabledByUser}), this class
@ -81,7 +83,7 @@ class EchoForeignNotifications {
$count = $this->counts[$section] ?? 0;
}
return MWEchoNotifUser::capNotificationCount( $count );
return NotifUser::capNotificationCount( $count );
}
/**
@ -155,7 +157,7 @@ class EchoForeignNotifications {
return;
}
$unreadWikis = EchoUnreadWikis::newFromUser( $this->user );
$unreadWikis = UnreadWikis::newFromUser( $this->user );
if ( !$unreadWikis ) {
return;
}

View file

@ -4,8 +4,8 @@ namespace MediaWiki\Extension\Notifications\Gateway;
use Config;
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\User\UserIdentity;
use MWEchoNotifUser;
/**
* Database gateway which handles direct database interaction with the
@ -128,7 +128,7 @@ class UserNotificationGateway {
}
/**
* Mark all notification as read, use MWEchoNotifUser::markAllRead() instead
* Mark all notification as read, use NotifUser::markAllRead() instead
* @deprecated may need this when running in a job or revive this when we
* have updateJoin()
*/
@ -161,7 +161,7 @@ class UserNotificationGateway {
public function getCappedNotificationCount(
$dbSource,
array $eventTypesToLoad = [],
$cap = MWEchoNotifUser::MAX_BADGE_COUNT
$cap = NotifUser::MAX_BADGE_COUNT
) {
// double check
if ( !in_array( $dbSource, [ DB_REPLICA, DB_PRIMARY ] ) ) {
@ -196,7 +196,7 @@ class UserNotificationGateway {
/**
* IMPORTANT: should only call this function if the number of unread notification
* is reasonable, for example, unread notification count is less than the max
* display defined in MWEchoNotifUser::MAX_BADGE_COUNT
* display defined in oNotifUser::MAX_BADGE_COUNT
* @param string $type
* @return int[]
*/

View file

@ -61,7 +61,6 @@ use MediaWiki\User\Options\Hook\LoadUserOptionsHook;
use MediaWiki\User\Options\Hook\SaveUserOptionsHook;
use MediaWiki\User\UserIdentity;
use MediaWiki\WikiMap\WikiMap;
use MWEchoNotifUser;
use OutputPage;
use RecentChange;
use ResourceLoaderEchoImageModule;
@ -938,7 +937,7 @@ class Hooks implements
} else {
$markAsReadIds = array_map( 'intval', $markAsReadIds );
// Look up the notifications on the foreign wiki
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$notifInfo = $notifUser->getForeignNotificationInfo( $markAsReadIds, $markAsReadWiki, $request );
foreach ( $notifInfo as $id => $info ) {
$subtractions[$info['section']]++;
@ -947,7 +946,7 @@ class Hooks implements
// Schedule a deferred update to mark these notifications as read on the foreign wiki
DeferredUpdates::addCallableUpdate(
static function () use ( $user, $markAsReadIds, $markAsReadWiki, $request ) {
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$notifUser->markReadForeign( $markAsReadIds, $markAsReadWiki, $request );
}
);
@ -957,7 +956,7 @@ class Hooks implements
// Schedule a deferred update to mark local target_page and ?markasread= notifications as read
if ( $eventIds ) {
DeferredUpdates::addCallableUpdate( static function () use ( $user, $eventIds ) {
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$notifUser->markRead( $eventIds );
} );
}
@ -1004,7 +1003,7 @@ class Hooks implements
$subtractions = self::processMarkAsRead( $user, $out->getRequest(), $title );
// Add a "My notifications" item to personal URLs
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$msgCount = $notifUser->getMessageCount() - $subtractions[AttributeManager::MESSAGE];
$alertCount = $notifUser->getAlertCount() - $subtractions[AttributeManager::ALERT];
// But make sure we never show a negative number (T130853)
@ -1058,7 +1057,7 @@ class Hooks implements
$msgLinkClasses[] = 'mw-echo-notifications-badge-all-read';
}
if ( $msgCount > MWEchoNotifUser::MAX_BADGE_COUNT ) {
if ( $msgCount > NotifUser::MAX_BADGE_COUNT ) {
$msgLinkClasses[] = 'mw-echo-notifications-badge-long-label';
}
@ -1077,7 +1076,7 @@ class Hooks implements
$alertLinkClasses[] = 'mw-echo-notifications-badge-all-read';
}
if ( $alertCount > MWEchoNotifUser::MAX_BADGE_COUNT ) {
if ( $alertCount > NotifUser::MAX_BADGE_COUNT ) {
$alertLinkClasses[] = 'mw-echo-notifications-badge-long-label';
}
@ -1225,7 +1224,7 @@ class Hooks implements
$user = $out->getUser();
if ( $user->isRegistered() ) {
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$lastUpdate = $notifUser->getGlobalUpdateTime();
if ( $lastUpdate !== false ) {
$modifiedTimes['notifications-global'] = $lastUpdate;
@ -1326,7 +1325,7 @@ class Hooks implements
// update runs (T318081)
return;
}
MWEchoNotifUser::newFromUser( $user )->resetNotificationCount();
NotifUser::newFromUser( $user )->resetNotificationCount();
} );
}
}
@ -1410,7 +1409,7 @@ class Hooks implements
public function onUserClearNewTalkNotification( $user, $oldid ) {
if ( $user->isRegistered() ) {
DeferredUpdates::addCallableUpdate( static function () use ( $user ) {
MWEchoNotifUser::newFromUser( $user )->clearUserTalkNotifications();
NotifUser::newFromUser( $user )->clearUserTalkNotifications();
} );
}
}
@ -1463,7 +1462,7 @@ class Hooks implements
public static function getConfigVars( RL\Context $context, Config $config ) {
return [
'EchoMaxNotificationCount' => MWEchoNotifUser::MAX_BADGE_COUNT,
'EchoMaxNotificationCount' => NotifUser::MAX_BADGE_COUNT,
'EchoPollForUpdates' => $config->get( 'EchoPollForUpdates' )
];
}

View file

@ -4,8 +4,8 @@ namespace MediaWiki\Extension\Notifications\Jobs;
use Job;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\MediaWikiServices;
use MWEchoNotifUser;
use Title;
use User;
@ -58,7 +58,7 @@ class NotificationDeleteJob extends Job {
$notifMapper->deleteByUserEventOffset(
$user, $notif->getEvent()->getId()
);
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$notifUser->resetNotificationCount();
}

View file

@ -6,8 +6,8 @@ use InvalidArgumentException;
use MediaWiki\Extension\Notifications\Bundleable;
use MediaWiki\Extension\Notifications\Hooks\HookRunner;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\MediaWikiServices;
use MWEchoNotifUser;
use stdClass;
use User;
@ -119,7 +119,7 @@ class Notification extends AbstractEntity implements Bundleable {
$this->bundleHash = $hash;
}
$notifUser = MWEchoNotifUser::newFromUser( $this->user );
$notifUser = NotifUser::newFromUser( $this->user );
// Add listener to refresh notification count upon insert
$notifMapper->attachListener( 'insert', 'refresh-notif-count',

View file

@ -1,8 +1,12 @@
<?php
use MediaWiki\Extension\Notifications\AttributeManager;
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\EmailFormat;
namespace MediaWiki\Extension\Notifications;
use CentralIdLookup;
use EchoForeignNotifications;
use EchoForeignWikiRequest;
use EchoServices;
use InvalidArgumentException;
use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway;
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
@ -12,12 +16,16 @@ use MediaWiki\User\UserFactory;
use MediaWiki\User\UserIdentity;
use MediaWiki\User\UserOptionsLookup;
use MediaWiki\WikiMap\WikiMap;
use MWTimestamp;
use ReadOnlyMode;
use WANObjectCache;
use WebRequest;
use Wikimedia\Rdbms\Database;
/**
* Entity that represents a notification target user
*/
class MWEchoNotifUser {
class NotifUser {
/**
* Notification target user
@ -127,14 +135,14 @@ class MWEchoNotifUser {
/**
* Factory method. The caller should make sure that the user is registered.
* @param UserIdentity $user
* @return MWEchoNotifUser
* @return NotifUser
*/
public static function newFromUser( UserIdentity $user ) {
if ( !$user->isRegistered() ) {
throw new InvalidArgumentException( 'User must be logged in to view notification!' );
}
$services = MediaWikiServices::getInstance();
return new MWEchoNotifUser(
return new NotifUser(
$user,
$services->getMainWANObjectCache(),
new UserNotificationGateway(
@ -192,7 +200,7 @@ class MWEchoNotifUser {
/**
* Retrieves number of unread notifications that a user has, would return
* MWEchoNotifUser::MAX_BADGE_COUNT + 1 at most.
* NotifUser::MAX_BADGE_COUNT + 1 at most.
*
* If $wgEchoCrossWikiNotifications is disabled, the $global parameter is ignored.
*
@ -490,7 +498,7 @@ class MWEchoNotifUser {
$this->cache->delete( $globalMemcKey );
}
$uw = EchoUnreadWikis::newFromUser( $this->mUser );
$uw = UnreadWikis::newFromUser( $this->mUser );
if ( $uw ) {
// Immediately compute new local counts and timestamps
$newLocalData = $this->computeLocalCountsAndTimestamps( DB_PRIMARY );
@ -748,7 +756,7 @@ class MWEchoNotifUser {
/**
* Helper function to produce the capped number of notifications
* based on the value of MWEchoNotifUser::MAX_BADGE_COUNT
* based on the value of NotifUser::MAX_BADGE_COUNT
*
* @param int $number Raw notification count to cap
* @return int Capped notification count

View file

@ -11,7 +11,6 @@ use MediaWiki\Extension\Notifications\Model\Event;
use MediaWiki\Extension\Notifications\Model\Notification;
use MediaWiki\MediaWikiServices;
use MWEchoEventLogging;
use MWEchoNotifUser;
use User;
use UserMailer;
@ -131,7 +130,7 @@ class Notifier {
* @return array|false An array of 'subject' and 'body', or false if things went wrong
*/
private static function generateEmail( Event $event, User $user ) {
$emailFormat = MWEchoNotifUser::newFromUser( $user )->getEmailFormat();
$emailFormat = NotifUser::newFromUser( $user )->getEmailFormat();
$services = MediaWikiServices::getInstance();
$userOptionsLookup = $services->getUserOptionsLookup();
$lang = $services->getLanguageFactory()

View file

@ -2,12 +2,12 @@
namespace MediaWiki\Extension\Notifications\Special;
use EchoDataOutputFormatter;
use Html;
use MediaWiki\Extension\Notifications\DataOutputFormatter;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\Extension\Notifications\OOUI\LabelIconWidget;
use MediaWiki\Extension\Notifications\SeenTime;
use MWEchoEventLogging;
use MWEchoNotifUser;
use OOUI;
use SpecialPage;
@ -69,7 +69,7 @@ class SpecialNotifications extends SpecialPage {
$notif = [];
foreach ( $notifications as $notification ) {
$output = EchoDataOutputFormatter::formatOutput( $notification, 'special', $user, $this->getLanguage() );
$output = DataOutputFormatter::formatOutput( $notification, 'special', $user, $this->getLanguage() );
if ( $output ) {
$notif[] = $output;
}
@ -121,7 +121,7 @@ class SpecialNotifications extends SpecialPage {
if ( $anyUnread ) {
$markReadSpecialPage = new SpecialNotificationsMarkRead();
$markReadSpecialPage->setContext( $this->getContext() );
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$unreadCount = $notifUser->getAlertCount() + $notifUser->getMessageCount();
$markAllAsReadText = $this

View file

@ -4,7 +4,7 @@ namespace MediaWiki\Extension\Notifications\Special;
use FormSpecialPage;
use HTMLForm;
use MWEchoNotifUser;
use MediaWiki\Extension\Notifications\NotifUser;
use SpecialPage;
/**
@ -135,7 +135,7 @@ class SpecialNotificationsMarkRead extends FormSpecialPage {
* @return bool
*/
public function onSubmit( array $data ) {
$notifUser = MWEchoNotifUser::newFromUser( $this->getUser() );
$notifUser = NotifUser::newFromUser( $this->getUser() );
// Allow for all IDs
if ( $data['id'] === [ 'ALL' ] ) {

View file

@ -1,13 +1,18 @@
<?php
class EchoSummaryParser {
namespace MediaWiki\Extension\Notifications;
use Title;
use User;
class SummaryParser {
/** @var callable */
private $userLookup;
/**
* @param callable|null $userLookup Function that receives User object and returns its id
* or 0 if the user doesn't exist. Passing null to this parameter will result in default
* implementation being used.
* or 0 if the user doesn't exist. Passing null to this parameter will result in default
* implementation being used.
*/
public function __construct( callable $userLookup = null ) {
$this->userLookup = $userLookup;

View file

@ -1,14 +1,17 @@
<?php
use MediaWiki\Extension\Notifications\AttributeManager;
use MediaWiki\Extension\Notifications\DbFactory;
namespace MediaWiki\Extension\Notifications;
use CentralIdLookup;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\UserIdentity;
use MWTimestamp;
use Wikimedia\Rdbms\IDatabase;
/**
* Manages what wikis a user has unread notifications on
*/
class EchoUnreadWikis {
class UnreadWikis {
private const DEFAULT_TS = '00000000000000';
private const DEFAULT_TS_DB = '00010101010101';
@ -35,7 +38,7 @@ class EchoUnreadWikis {
* Use the user id provided by the CentralIdLookup
*
* @param UserIdentity $user
* @return EchoUnreadWikis|false
* @return UnreadWikis|false
*/
public static function newFromUser( UserIdentity $user ) {
$id = MediaWikiServices::getInstance()
@ -50,7 +53,8 @@ class EchoUnreadWikis {
/**
* @param int $index DB_* constant
* @return bool|\Wikimedia\Rdbms\IDatabase
*
* @return bool|IDatabase
*/
private function getDB( $index ) {
return $this->dbFactory->getSharedDb( $index );

View file

@ -9,7 +9,6 @@ use MediaWiki\Extension\UserMerge\Hooks\AccountDeleteTablesHook;
use MediaWiki\Extension\UserMerge\Hooks\AccountFieldsHook;
use MediaWiki\Extension\UserMerge\Hooks\MergeAccountFromToHook;
use MWEchoDbFactory;
use MWEchoNotifUser;
use User;
class UserMergeHooks implements
@ -106,9 +105,9 @@ class UserMergeHooks implements
}
}
MWEchoNotifUser::newFromUser( $oldUser )->resetNotificationCount();
NotifUser::newFromUser( $oldUser )->resetNotificationCount();
if ( $newUser->isRegistered() ) {
MWEchoNotifUser::newFromUser( $newUser )->resetNotificationCount();
NotifUser::newFromUser( $newUser )->resetNotificationCount();
}
} );
}

View file

@ -2,6 +2,8 @@
use MediaWiki\Extension\Notifications\AttributeManager;
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\Extension\Notifications\UnreadWikis;
use MediaWiki\MediaWikiServices;
use MediaWiki\WikiMap\WikiMap;
@ -60,8 +62,8 @@ class BackfillUnreadWikis extends Maintenance {
$user = User::newFromRow( $row );
}
$notifUser = MWEchoNotifUser::newFromUser( $user );
$uw = EchoUnreadWikis::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$uw = UnreadWikis::newFromUser( $user );
if ( $uw ) {
$alertCount = $notifUser->getNotificationCount( AttributeManager::ALERT, false );
$alertUnread = $notifUser->getLastUnreadNotificationTime( AttributeManager::ALERT, false );

View file

@ -6,6 +6,7 @@
*/
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\NotifUser;
require_once getenv( 'MW_INSTALL_PATH' ) !== false
? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
@ -79,7 +80,7 @@ class RecomputeNotifCounts extends Maintenance {
} else {
$user = User::newFromId( is_object( $rowOrID ) ? $rowOrID->notification_user : $rowOrID );
}
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$notifUser->resetNotificationCount();
}
$count += count( $batch );

View file

@ -6,6 +6,7 @@ use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
use MediaWiki\Extension\Notifications\Model\Event;
use MediaWiki\Extension\Notifications\Model\Notification;
use MediaWiki\Extension\Notifications\NotifUser;
use MediaWiki\MediaWikiServices;
use MediaWiki\User\TalkPageNotificationManager;
use MediaWiki\User\UserFactory;
@ -13,10 +14,10 @@ use MediaWiki\User\UserGroupManager;
use MediaWiki\User\UserOptionsLookup;
/**
* @covers \MWEchoNotifUser
* @covers \MediaWiki\Extension\Notifications\NotifUser
* @group Echo
*/
class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
class NotifUserTest extends MediaWikiIntegrationTestCase {
/**
* @var WANObjectCache
@ -33,7 +34,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
public function testNewFromUser() {
$exception = false;
try {
MWEchoNotifUser::newFromUser( User::newFromId( 0 ) );
NotifUser::newFromUser( User::newFromId( 0 ) );
} catch ( Exception $e ) {
$exception = true;
$this->assertEquals( "User must be logged in to view notification!",
@ -41,8 +42,8 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
}
$this->assertTrue( $exception, "Got exception" );
$notifUser = MWEchoNotifUser::newFromUser( User::newFromId( 2 ) );
$this->assertInstanceOf( MWEchoNotifUser::class, $notifUser );
$notifUser = NotifUser::newFromUser( User::newFromId( 2 ) );
$this->assertInstanceOf( NotifUser::class, $notifUser );
}
public function testGetEmailFormat() {
@ -54,7 +55,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
->with( $user, 'echo-email-format' )
->willReturn( $pref );
$this->setService( 'UserOptionsLookup', $userOptionsLookup );
$notifUser = MWEchoNotifUser::newFromUser( $user );
$notifUser = NotifUser::newFromUser( $user );
$this->setMwGlobals( 'wgAllowHTMLEmail', true );
$this->assertEquals( $notifUser->getEmailFormat(), $pref );
@ -65,7 +66,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
public function testMarkRead() {
$this->setService( 'UserFactory', $this->createMock( UserFactory::class ) );
$this->setService( 'TalkPageNotificationManager', $this->createMock( TalkPageNotificationManager::class ) );
$notifUser = new MWEchoNotifUser(
$notifUser = new NotifUser(
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => true ] ),
@ -78,7 +79,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
$this->assertFalse( $notifUser->markRead( [] ) );
$this->assertTrue( $notifUser->markRead( [ 1 ] ) );
$notifUser = new MWEchoNotifUser(
$notifUser = new NotifUser(
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => false ] ),
@ -98,7 +99,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
$this->setService( 'UserGroupManager', $this->createMock( UserGroupManager::class ) );
$this->setService( 'UserOptionsLookup', $this->createMock( UserOptionsLookup::class ) );
// Successful mark as read & non empty fetch
$notifUser = new MWEchoNotifUser(
$notifUser = new NotifUser(
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => true ] ),
@ -111,7 +112,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
$this->assertTrue( $notifUser->markAllRead() );
// Unsuccessful mark as read & non empty fetch
$notifUser = new MWEchoNotifUser(
$notifUser = new NotifUser(
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => false ] ),
@ -124,7 +125,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
$this->assertFalse( $notifUser->markAllRead() );
// Successful mark as read & empty fetch
$notifUser = new MWEchoNotifUser(
$notifUser = new NotifUser(
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => true ] ),
@ -137,7 +138,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
$this->assertFalse( $notifUser->markAllRead() );
// Unsuccessful mark as read & empty fetch
$notifUser = new MWEchoNotifUser(
$notifUser = new NotifUser(
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway( [ 'markRead' => false ] ),
@ -188,7 +189,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
}
protected function newNotifUser() {
return new MWEchoNotifUser(
return new NotifUser(
User::newFromId( 2 ),
$this->cache,
$this->mockUserNotificationGateway(),

View file

@ -1,9 +1,11 @@
<?php
use MediaWiki\Extension\Notifications\SummaryParser;
/**
* @group Echo
*/
class EchoSummaryParserTest extends MediaWikiIntegrationTestCase {
class SummaryParserTest extends MediaWikiIntegrationTestCase {
/** @var string[] */
private $existingUsers = [
'Werdna',
@ -12,14 +14,14 @@ class EchoSummaryParserTest extends MediaWikiIntegrationTestCase {
];
/**
* @covers \EchoSummaryParser::parse
* @covers \MediaWiki\Extension\Notifications\SummaryParser::parse
* @dataProvider provideParse
*
* @param string $summary
* @param string[] $expectedUsers
*/
public function testParse( $summary, array $expectedUsers ) {
$parser = new EchoSummaryParser( function ( User $user ) {
$parser = new SummaryParser( function ( User $user ) {
if ( in_array( $user->getName(), $this->existingUsers ) ) {
return crc32( $user->getName() );
}

View file

@ -1,18 +1,19 @@
<?php
use MediaWiki\Extension\Notifications\DbFactory;
use MediaWiki\Extension\Notifications\UnreadWikis;
use Wikimedia\TestingAccessWrapper;
/**
* Tests for unread wiki database access
*
* @group Database
* @covers \EchoUnreadWikis
* @covers \MediaWiki\Extension\Notifications\UnreadWikis
*/
class UnreadWikisTest extends MediaWikiIntegrationTestCase {
public function testUpdateCount() {
$unread = TestingAccessWrapper::newFromObject( new EchoUnreadWikis( 1 ) );
$unread = TestingAccessWrapper::newFromObject( new UnreadWikis( 1 ) );
$unread->dbFactory = $this->mockDbFactory( $this->db );
$unread->updateCount(
'foobar',
@ -33,7 +34,7 @@ class UnreadWikisTest extends MediaWikiIntegrationTestCase {
}
public function testUpdateCountFalse() {
$unread = TestingAccessWrapper::newFromObject( new EchoUnreadWikis( 1 ) );
$unread = TestingAccessWrapper::newFromObject( new UnreadWikis( 1 ) );
$unread->dbFactory = $this->mockDbFactory( $this->db );
$unread->updateCount(
'foobar',

View file

@ -3,7 +3,7 @@
use MediaWiki\Extension\Notifications\DiscussionParser;
/**
* @covers \EchoDiffParser
* @covers \MediaWiki\Extension\Notifications\DiffParser
* @group Echo
*/
class DiffParserTest extends MediaWikiUnitTestCase {