mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-09-23 10:22:05 +00:00
Namespace Model
Depends-On: Id28792658de950b99a8786f881563476def59eba Change-Id: Ib57ea2db947285946f31fa9912b37181044df9d3
This commit is contained in:
parent
69139e663e
commit
5611662f06
|
@ -1072,7 +1072,6 @@
|
|||
"BackfillUnreadWikis": "maintenance/backfillUnreadWikis.php",
|
||||
"Bundleable": "includes/Bundleable.php",
|
||||
"Bundler": "includes/Bundler.php",
|
||||
"EchoAbstractEntity": "includes/model/AbstractEntity.php",
|
||||
"EchoArrayList": "includes/EchoArrayList.php",
|
||||
"EchoAttributeManager": "includes/AttributeManager.php",
|
||||
"EchoCachedList": "includes/EchoCachedList.php",
|
||||
|
@ -1089,8 +1088,8 @@
|
|||
"MediaWiki\\Extension\\Notifications\\Formatters\\EchoEditUserTalkPresentationModel": "includes/Formatters/EchoEditUserTalkPresentationModel.php",
|
||||
"EchoEmailFormat": "includes/EmailFormat.php",
|
||||
"EchoEmailFrequency": "includes/EmailFrequency.php",
|
||||
"EchoEvent": "includes/model/Event.php",
|
||||
"MediaWiki\\Extension\\Notifications\\Model\\Event": "includes/model/Event.php",
|
||||
"EchoEvent": "includes/Model/Event.php",
|
||||
"MediaWiki\\Extension\\Notifications\\Model\\Event": "includes/Model/Event.php",
|
||||
"EchoEventPresentationModel": "includes/Formatters/EchoEventPresentationModel.php",
|
||||
"MediaWiki\\Extension\\Notifications\\Formatters\\EchoEventPresentationModel": "includes/Formatters/EchoEventPresentationModel.php",
|
||||
"EchoForeignNotifications": "includes/ForeignNotifications.php",
|
||||
|
@ -1099,7 +1098,8 @@
|
|||
"MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionPresentationModel": "includes/Formatters/EchoMentionPresentationModel.php",
|
||||
"EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php",
|
||||
"MediaWiki\\Extension\\Notifications\\Formatters\\EchoMentionStatusPresentationModel": "includes/Formatters/EchoMentionStatusPresentationModel.php",
|
||||
"EchoNotification": "includes/model/Notification.php",
|
||||
"EchoNotification": "includes/Model/Notification.php",
|
||||
"MediaWiki\\Extension\\Notifications\\Model\\Notification": "includes/Model/Notification.php",
|
||||
"EchoNotificationMapper": "includes/Mapper/NotificationMapper.php",
|
||||
"MediaWiki\\Extension\\Notifications\\Mapper\\NotificationMapper": "includes/Mapper/NotificationMapper.php",
|
||||
"EchoNotifier": "includes/Notifier.php",
|
||||
|
@ -1110,7 +1110,6 @@
|
|||
"EchoServices": "includes/EchoServices.php",
|
||||
"EchoSummaryParser": "includes/EchoSummaryParser.php",
|
||||
"EchoSuppressionRowUpdateGenerator": "includes/schemaUpdate.php",
|
||||
"EchoTargetPage": "includes/model/TargetPage.php",
|
||||
"EchoUnreadWikis": "includes/UnreadWikis.php",
|
||||
"EchoUserLocator": "includes/UserLocator.php",
|
||||
"GenerateSampleNotifications": "maintenance/generateSampleNotifications.php",
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace MediaWiki\Extension\Notifications\Api;
|
|||
use ApiBase;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use EchoEvent;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MWTimestamp;
|
||||
use Wikimedia\ParamValidator\ParamValidator;
|
||||
|
||||
|
@ -29,7 +29,7 @@ class ApiEchoArticleReminder extends ApiBase {
|
|||
$this->dieWithError( [ 'apierror-badparameter', 'timestamp' ], 'timestamp-not-in-future', null, 400 );
|
||||
}
|
||||
|
||||
$eventCreation = EchoEvent::create( [
|
||||
$eventCreation = Event::create( [
|
||||
'type' => 'article-reminder',
|
||||
'agent' => $user,
|
||||
'title' => $this->getTitleFromTitleOrPageId( $params ),
|
||||
|
|
|
@ -10,11 +10,11 @@ use Config;
|
|||
use EchoAttributeManager;
|
||||
use EchoDataOutputFormatter;
|
||||
use EchoForeignNotifications;
|
||||
use EchoNotification;
|
||||
use EchoSeenTime;
|
||||
use EchoServices;
|
||||
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
||||
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use MWEchoNotifUser;
|
||||
use Title;
|
||||
use User;
|
||||
|
@ -265,7 +265,7 @@ class ApiEchoNotifications extends ApiQueryBase {
|
|||
* discard unread & fetch read
|
||||
*/
|
||||
if ( $notifs && $continue ) {
|
||||
/** @var EchoNotification $first */
|
||||
/** @var Notification $first */
|
||||
$first = reset( $notifs );
|
||||
$continueId = intval( trim( strrchr( $continue, '|' ), '|' ) );
|
||||
if ( $first->getEvent()->getId() !== $continueId ) {
|
||||
|
@ -307,7 +307,7 @@ class ApiEchoNotifications extends ApiQueryBase {
|
|||
}
|
||||
|
||||
// get $overfetchedItem before bundling and rendering so that it is not affected by filtering
|
||||
/** @var EchoNotification $overfetchedItem */
|
||||
/** @var Notification $overfetchedItem */
|
||||
$overfetchedItem = count( $notifs ) > $limit ? array_pop( $notifs ) : null;
|
||||
|
||||
$bundler = null;
|
||||
|
@ -317,7 +317,7 @@ class ApiEchoNotifications extends ApiQueryBase {
|
|||
}
|
||||
|
||||
while ( $notifs !== [] ) {
|
||||
/** @var EchoNotification $notif */
|
||||
/** @var Notification $notif */
|
||||
$notif = array_shift( $notifs );
|
||||
$output = EchoDataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() );
|
||||
if ( $output !== false ) {
|
||||
|
@ -443,7 +443,7 @@ class ApiEchoNotifications extends ApiQueryBase {
|
|||
];
|
||||
|
||||
// Format output like any other notification
|
||||
$notif = EchoNotification::newFromRow( $row );
|
||||
$notif = Notification::newFromRow( $row );
|
||||
$output = EchoDataOutputFormatter::formatOutput( $notif, $format, $user, $this->getLanguage() );
|
||||
|
||||
// Add cross-wiki-specific data
|
||||
|
|
|
@ -7,7 +7,6 @@ use EchoAttributeManager;
|
|||
use EchoCachedList;
|
||||
use EchoContainmentList;
|
||||
use EchoContainmentSet;
|
||||
use EchoEvent;
|
||||
use EchoOnWikiList;
|
||||
use EchoServices;
|
||||
use Hooks;
|
||||
|
@ -17,6 +16,7 @@ use MediaWiki\Extension\Notifications\Exception\CatchableFatalErrorException;
|
|||
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\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionStore;
|
||||
|
@ -101,9 +101,9 @@ class NotificationController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Processes notifications for a newly-created EchoEvent
|
||||
* Processes notifications for a newly-created Event
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param bool $defer Defer to job queue or not
|
||||
*/
|
||||
public static function notify( $event, $defer = true ) {
|
||||
|
@ -176,10 +176,10 @@ class NotificationController {
|
|||
/**
|
||||
* Check if an event is associated with a minor revision.
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @return bool
|
||||
*/
|
||||
private static function hasMinorRevision( EchoEvent $event ) {
|
||||
private static function hasMinorRevision( Event $event ) {
|
||||
$revId = $event->getExtraParam( 'revid' );
|
||||
if ( !$revId ) {
|
||||
return false;
|
||||
|
@ -206,9 +206,9 @@ class NotificationController {
|
|||
* Schedule a job to check and delete older notifications
|
||||
*
|
||||
* @param int[] $userIds
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
*/
|
||||
public static function enqueueDeleteJob( array $userIds, EchoEvent $event ) {
|
||||
public static function enqueueDeleteJob( array $userIds, Event $event ) {
|
||||
// Do nothing if there is no user
|
||||
if ( !$userIds ) {
|
||||
return;
|
||||
|
@ -242,10 +242,10 @@ class NotificationController {
|
|||
|
||||
/**
|
||||
* Helper function to extract event task params
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @return array Event params
|
||||
*/
|
||||
public static function getEventParams( EchoEvent $event ) {
|
||||
public static function getEventParams( Event $event ) {
|
||||
$delay = $event->getExtraParam( 'delay' );
|
||||
$rootJobSignature = $event->getExtraParam( 'rootJobSignature' );
|
||||
$rootJobTimestamp = $event->getExtraParam( 'rootJobTimestamp' );
|
||||
|
@ -259,9 +259,9 @@ class NotificationController {
|
|||
/**
|
||||
* Push $event onto the mediawiki job queue
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
*/
|
||||
public static function enqueueEvent( EchoEvent $event ) {
|
||||
public static function enqueueEvent( Event $event ) {
|
||||
$queue = MediaWikiServices::getInstance()->getJobQueueGroup();
|
||||
$params = self::getEventParams( $event );
|
||||
|
||||
|
@ -288,11 +288,11 @@ class NotificationController {
|
|||
* Implements blacklist per active wiki expected to be initialized
|
||||
* from InitializeSettings.php
|
||||
*
|
||||
* @param EchoEvent $event The event to test for exclusion
|
||||
* @param Event $event The event to test for exclusion
|
||||
* @param User $user recipient of the notification for per-user blacklists
|
||||
* @return bool True when the event agent is blacklisted
|
||||
*/
|
||||
public static function isBlacklistedByUser( EchoEvent $event, User $user ) {
|
||||
public static function isBlacklistedByUser( Event $event, User $user ) {
|
||||
global $wgEchoAgentBlacklist, $wgEchoPerUserBlacklist;
|
||||
|
||||
if ( !$event->getAgent() ) {
|
||||
|
@ -380,11 +380,11 @@ class NotificationController {
|
|||
/**
|
||||
* Implements per-user whitelist sourced from a user wiki page
|
||||
*
|
||||
* @param EchoEvent $event The event to test for inclusion in whitelist
|
||||
* @param Event $event The event to test for inclusion in whitelist
|
||||
* @param User $user The user that owns the whitelist
|
||||
* @return bool True when the event agent is in the user whitelist
|
||||
*/
|
||||
public static function isWhitelistedByUser( EchoEvent $event, User $user ) {
|
||||
public static function isWhitelistedByUser( Event $event, User $user ) {
|
||||
$clusterCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
|
||||
global $wgEchoPerUserWhitelistFormat;
|
||||
|
||||
|
@ -420,9 +420,9 @@ class NotificationController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Processes a single notification for an EchoEvent
|
||||
* Processes a single notification for an Event
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param User $user The user to be notified.
|
||||
* @param string $type The type of notification delivery to process, e.g. 'email'.
|
||||
* @throws MWException
|
||||
|
@ -446,11 +446,11 @@ class NotificationController {
|
|||
* Returns an array each element of which is the result of a
|
||||
* user-locator|user-filters attached to the event type.
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param string $locator Either EchoAttributeManager::ATTR_LOCATORS or EchoAttributeManager::ATTR_FILTERS
|
||||
* @return array
|
||||
*/
|
||||
public static function evaluateUserCallable( EchoEvent $event, $locator = EchoAttributeManager::ATTR_LOCATORS ) {
|
||||
public static function evaluateUserCallable( Event $event, $locator = EchoAttributeManager::ATTR_LOCATORS ) {
|
||||
$attributeManager = EchoServices::getInstance()->getAttributeManager();
|
||||
$type = $event->getType();
|
||||
$result = [];
|
||||
|
@ -475,12 +475,12 @@ class NotificationController {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieves an array of User objects to be notified for an EchoEvent.
|
||||
* Retrieves an array of User objects to be notified for an Event.
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @return Iterator values are User objects
|
||||
*/
|
||||
public static function getUsersToNotifyForEvent( EchoEvent $event ) {
|
||||
public static function getUsersToNotifyForEvent( Event $event ) {
|
||||
$notify = new FilteredSequentialIterator;
|
||||
foreach ( self::evaluateUserCallable( $event, EchoAttributeManager::ATTR_LOCATORS ) as $users ) {
|
||||
$notify->add( $users );
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Formatters\EchoEventFormatter;
|
||||
use MediaWiki\Extension\Notifications\Formatters\EchoFlyoutFormatter;
|
||||
use MediaWiki\Extension\Notifications\Formatters\EchoModelFormatter;
|
||||
use MediaWiki\Extension\Notifications\Formatters\SpecialNotificationsFormatter;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
|
||||
/**
|
||||
|
@ -29,14 +32,14 @@ class EchoDataOutputFormatter {
|
|||
* so mark it as safe for html and safe to be escaped again.
|
||||
* @return-taint onlysafefor_htmlnoent
|
||||
*
|
||||
* @param EchoNotification $notification
|
||||
* @param Notification $notification
|
||||
* @param string|false $format Output format, false to not format any notifications
|
||||
* @param User $user the target user viewing the notification
|
||||
* @param Language $lang Language to format the notification in
|
||||
* @return array|false False if it could not be formatted
|
||||
*/
|
||||
public static function formatOutput(
|
||||
EchoNotification $notification,
|
||||
Notification $notification,
|
||||
$format,
|
||||
User $user,
|
||||
Language $lang
|
||||
|
@ -50,7 +53,7 @@ class EchoDataOutputFormatter {
|
|||
|
||||
$bundledNotifs = $notification->getBundledNotifications();
|
||||
if ( $bundledNotifs ) {
|
||||
$bundledEvents = array_map( static function ( EchoNotification $notif ) {
|
||||
$bundledEvents = array_map( static function ( Notification $notif ) {
|
||||
return $notif->getEvent();
|
||||
}, $bundledNotifs );
|
||||
$event->setBundledEvents( $bundledEvents );
|
||||
|
@ -162,7 +165,7 @@ class EchoDataOutputFormatter {
|
|||
EchoServices::getInstance()->getAttributeManager()->isBundleExpandable( $event->getType() )
|
||||
) {
|
||||
$output['bundledNotifications'] = array_values( array_filter( array_map(
|
||||
function ( EchoNotification $notification ) use ( $format, $user, $lang ) {
|
||||
static function ( Notification $notification ) use ( $format, $user, $lang ) {
|
||||
// remove nested notifications to
|
||||
// - ensure they are formatted as single notifications (not bundled)
|
||||
// - prevent further re-entrance on the current notification
|
||||
|
@ -179,13 +182,13 @@ class EchoDataOutputFormatter {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param User $user
|
||||
* @param string $format
|
||||
* @param Language $lang
|
||||
* @return string[]|string|false False if it could not be formatted
|
||||
*/
|
||||
protected static function formatNotification( EchoEvent $event, User $user, $format, $lang ) {
|
||||
protected static function formatNotification( Event $event, User $user, $format, $lang ) {
|
||||
if ( isset( self::$formatters[$format] ) ) {
|
||||
$class = self::$formatters[$format];
|
||||
/** @var EchoEventFormatter $formatter */
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Controller\ModerationController;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
|
||||
/**
|
||||
|
@ -9,14 +10,14 @@ use MediaWiki\Logger\LoggerFactory;
|
|||
*/
|
||||
class EchoDeferredMarkAsDeletedUpdate implements DeferrableUpdate {
|
||||
/**
|
||||
* @var EchoEvent[]
|
||||
* @var Event[]
|
||||
*/
|
||||
protected $events = [];
|
||||
|
||||
/**
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
*/
|
||||
public static function add( EchoEvent $event ) {
|
||||
public static function add( Event $event ) {
|
||||
static $update;
|
||||
if ( $update === null ) {
|
||||
$update = new self();
|
||||
|
@ -26,16 +27,16 @@ class EchoDeferredMarkAsDeletedUpdate implements DeferrableUpdate {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
*/
|
||||
private function addInternal( EchoEvent $event ) {
|
||||
private function addInternal( Event $event ) {
|
||||
$this->events[] = $event;
|
||||
}
|
||||
|
||||
private function filterEventsWithTitleDbLag() {
|
||||
return array_filter(
|
||||
$this->events,
|
||||
static function ( EchoEvent $event ) {
|
||||
static function ( Event $event ) {
|
||||
if ( !$event->getTitle() && $event->getTitle( true ) ) {
|
||||
// It is very likely this event was found
|
||||
// unrenderable because of replica lag.
|
||||
|
@ -63,7 +64,7 @@ class EchoDeferredMarkAsDeletedUpdate implements DeferrableUpdate {
|
|||
$events = $this->filterEventsWithTitleDbLag();
|
||||
|
||||
$eventIds = array_map(
|
||||
static function ( EchoEvent $event ) {
|
||||
static function ( Event $event ) {
|
||||
return $event->getId();
|
||||
},
|
||||
$events
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
|
@ -18,7 +19,7 @@ abstract class EchoDiscussionParser {
|
|||
protected static $diffParser;
|
||||
|
||||
/**
|
||||
* Given a RevisionRecord object, generates EchoEvent objects for
|
||||
* Given a RevisionRecord object, generates Event objects for
|
||||
* the discussion-related actions that occurred in that Revision.
|
||||
*
|
||||
* @param RevisionRecord $revision
|
||||
|
@ -166,7 +167,7 @@ abstract class EchoDiscussionParser {
|
|||
|
||||
// Create events
|
||||
foreach ( $events as $event ) {
|
||||
EchoEvent::create( $event );
|
||||
Event::create( $event );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,7 +236,7 @@ abstract class EchoDiscussionParser {
|
|||
) {
|
||||
$events = self::collectMentionEvents( $header, $userLinks, $content, $revision, $agent );
|
||||
foreach ( $events as $event ) {
|
||||
EchoEvent::create( $event );
|
||||
Event::create( $event );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -545,7 +546,7 @@ abstract class EchoDiscussionParser {
|
|||
*
|
||||
* @todo Expand recognisable actions.
|
||||
*
|
||||
* @param array[] $changes Output of EchoEvent::getMachineReadableDiff
|
||||
* @param array[] $changes Output of Event::getMachineReadableDiff
|
||||
* @param string $username
|
||||
* @param Title|null $title
|
||||
* @return array[] Array of associative arrays.
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use MediaWiki\Extension\Notifications\Formatters\EchoHtmlDigestEmailFormatter;
|
||||
use MediaWiki\Extension\Notifications\Formatters\EchoPlainTextDigestEmailFormatter;
|
||||
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserOptionsManager;
|
||||
use Wikimedia\Rdbms\IResultWrapper;
|
||||
|
@ -28,12 +29,12 @@ class MWEchoEmailBatch {
|
|||
protected $userOptionsManager;
|
||||
|
||||
/**
|
||||
* @var EchoEvent[] events included in this email
|
||||
* @var Event[] events included in this email
|
||||
*/
|
||||
protected $events = [];
|
||||
|
||||
/**
|
||||
* @var EchoEvent the last notification event of this batch
|
||||
* @var Event the last notification event of this batch
|
||||
*/
|
||||
protected $lastEvent;
|
||||
|
||||
|
@ -138,7 +139,7 @@ class MWEchoEmailBatch {
|
|||
if ( $this->count > self::$displaySize ) {
|
||||
break;
|
||||
}
|
||||
$event = EchoEvent::newFromRow( $row );
|
||||
$event = Event::newFromRow( $row );
|
||||
if ( !$event ) {
|
||||
continue;
|
||||
}
|
||||
|
@ -235,7 +236,7 @@ class MWEchoEmailBatch {
|
|||
if ( $this->lastEvent ) {
|
||||
$conds[] = 'eeb_event_id <= ' . (int)$this->lastEvent;
|
||||
}
|
||||
$fields = array_merge( EchoEvent::selectFields(), [
|
||||
$fields = array_merge( Event::selectFields(), [
|
||||
'eeb_id',
|
||||
'eeb_user_id',
|
||||
'eeb_event_priority',
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Formatters;
|
||||
|
||||
use EchoEvent;
|
||||
use Language;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use User;
|
||||
|
||||
|
@ -17,7 +17,7 @@ class EchoEditUserTalkPresentationModel extends EchoEventPresentationModel {
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function __construct( EchoEvent $event, Language $language, User $user, $distributionType ) {
|
||||
protected function __construct( Event $event, Language $language, User $user, $distributionType ) {
|
||||
parent::__construct( $event, $language, $user, $distributionType );
|
||||
$this->section = new EchoPresentationModelSection( $event, $user, $language );
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Formatters;
|
||||
|
||||
use EchoEvent;
|
||||
use Language;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use Message;
|
||||
use User;
|
||||
|
||||
|
@ -42,7 +42,7 @@ abstract class EchoEventDigestFormatter {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param EchoEvent[] $events
|
||||
* @param Event[] $events
|
||||
* @param string $distributionType 'web' or 'email'
|
||||
* @return string[]|false Output format depends on implementation, false if it cannot be formatted
|
||||
*/
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Formatters;
|
||||
|
||||
use EchoEvent;
|
||||
use Language;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use Message;
|
||||
use User;
|
||||
|
@ -48,11 +48,11 @@ abstract class EchoEventFormatter {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param string $distributionType 'web' or 'email'
|
||||
* @return string[]|string|false Output format depends on implementation, false if it cannot be formatted
|
||||
*/
|
||||
final public function format( EchoEvent $event, string $distributionType = "web" ) {
|
||||
final public function format( Event $event, string $distributionType = "web" ) {
|
||||
// Deleted events should have been filtered out before getting there.
|
||||
// This is just to be sure.
|
||||
if ( $event->isDeleted() ) {
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Formatters;
|
||||
|
||||
use EchoEvent;
|
||||
use InvalidArgumentException;
|
||||
use JsonSerializable;
|
||||
use Language;
|
||||
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use Message;
|
||||
|
@ -55,7 +55,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo
|
|||
public const SECTION_TITLE_RECOMMENDED_LENGTH = 50;
|
||||
|
||||
/**
|
||||
* @var EchoEvent
|
||||
* @var Event
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
|
@ -80,13 +80,13 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo
|
|||
private $distributionType;
|
||||
|
||||
/**
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param Language $language
|
||||
* @param User $user Only used for permissions checking and GENDER
|
||||
* @param string $distributionType
|
||||
*/
|
||||
protected function __construct(
|
||||
EchoEvent $event,
|
||||
Event $event,
|
||||
Language $language,
|
||||
User $user,
|
||||
$distributionType
|
||||
|
@ -112,14 +112,14 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo
|
|||
}
|
||||
|
||||
/**
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param Language $language
|
||||
* @param User $user
|
||||
* @param string $distributionType 'web' or 'email'
|
||||
* @return EchoEventPresentationModel
|
||||
*/
|
||||
public static function factory(
|
||||
EchoEvent $event,
|
||||
Event $event,
|
||||
Language $language,
|
||||
User $user,
|
||||
$distributionType = 'web'
|
||||
|
@ -189,7 +189,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo
|
|||
}
|
||||
|
||||
/**
|
||||
* @return EchoEvent[]
|
||||
* @return Event[]
|
||||
*/
|
||||
final protected function getBundledEvents() {
|
||||
return $this->event->getBundledEvents() ?: [];
|
||||
|
@ -202,7 +202,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo
|
|||
*/
|
||||
public function getBundledIds() {
|
||||
if ( $this->isBundled() ) {
|
||||
return array_map( static function ( EchoEvent $event ) {
|
||||
return array_map( static function ( Event $event ) {
|
||||
return $event->getId();
|
||||
}, $this->getBundledEvents() );
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo
|
|||
* If $includeCurrent is false, all events in the same group as the current one will be ignored.
|
||||
*
|
||||
* @param bool $includeCurrent Include the current event (and its group)
|
||||
* @param callable|null $groupCallback Callback that takes an EchoEvent and returns a grouping value
|
||||
* @param callable|null $groupCallback Callback that takes an Event and returns a grouping value
|
||||
* @return int Number of bundled events or groups
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
|
@ -280,7 +280,7 @@ abstract class EchoEventPresentationModel implements JsonSerializable, MessageLo
|
|||
}
|
||||
|
||||
/**
|
||||
* Helper for EchoEvent::userCan
|
||||
* Helper for Event::userCan
|
||||
*
|
||||
* @param int $type RevisionRecord::DELETED_* constant
|
||||
* @return bool
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace MediaWiki\Extension\Notifications\Formatters;
|
||||
|
||||
use EchoDiscussionParser;
|
||||
use EchoEvent;
|
||||
use Language;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use User;
|
||||
|
||||
|
@ -18,7 +18,7 @@ class EchoMentionPresentationModel extends EchoEventPresentationModel {
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function __construct( EchoEvent $event, Language $language, User $user, $distributionType ) {
|
||||
protected function __construct( Event $event, Language $language, User $user, $distributionType ) {
|
||||
parent::__construct( $event, $language, $user, $distributionType );
|
||||
$this->section = new EchoPresentationModelSection( $event, $user, $language );
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Formatters;
|
||||
|
||||
use EchoEvent;
|
||||
use Language;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use User;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +23,7 @@ class EchoMentionStatusPresentationModel extends EchoEventPresentationModel {
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function __construct( EchoEvent $event, Language $language, User $user, $distributionType ) {
|
||||
protected function __construct( Event $event, Language $language, User $user, $distributionType ) {
|
||||
parent::__construct( $event, $language, $user, $distributionType );
|
||||
$this->section = new EchoPresentationModelSection( $event, $user, $language );
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ class EchoMentionStatusPresentationModel extends EchoEventPresentationModel {
|
|||
return [ $talkPageLink ];
|
||||
}
|
||||
|
||||
public function isMentionSuccessEvent( EchoEvent $event ) {
|
||||
public function isMentionSuccessEvent( Event $event ) {
|
||||
return $event->getType() === 'mention-success';
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Formatters;
|
||||
|
||||
use EchoEvent;
|
||||
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use SpecialPage;
|
||||
use Title;
|
||||
|
@ -147,10 +147,10 @@ class EchoPageLinkedPresentationModel extends EchoEventPresentationModel {
|
|||
|
||||
/**
|
||||
* Get the page ID of the linked-from page for a given event.
|
||||
* @param EchoEvent $event page-linked event
|
||||
* @param Event $event page-linked event
|
||||
* @return int Page ID, or 0 if the page doesn't exist
|
||||
*/
|
||||
public function getLinkedPageId( EchoEvent $event ) {
|
||||
public function getLinkedPageId( Event $event ) {
|
||||
$extra = $event->getExtra();
|
||||
if ( isset( $extra['link-from-page-id'] ) ) {
|
||||
return $extra['link-from-page-id'];
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
namespace MediaWiki\Extension\Notifications\Formatters;
|
||||
|
||||
use EchoDiscussionParser;
|
||||
use EchoEvent;
|
||||
use Language;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MWException;
|
||||
use Parser;
|
||||
|
@ -27,7 +27,7 @@ class EchoPresentationModelSection {
|
|||
private $parsedSectionTitle = null;
|
||||
|
||||
/**
|
||||
* @var EchoEvent
|
||||
* @var Event
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
|
@ -42,11 +42,11 @@ class EchoPresentationModelSection {
|
|||
protected $language;
|
||||
|
||||
/**
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param User $user
|
||||
* @param Language $language
|
||||
*/
|
||||
public function __construct( EchoEvent $event, User $user, Language $language ) {
|
||||
public function __construct( Event $event, User $user, Language $language ) {
|
||||
$this->event = $event;
|
||||
$this->user = $user;
|
||||
$this->language = $language;
|
||||
|
|
|
@ -11,8 +11,6 @@ use EchoAttributeManager;
|
|||
use EchoDiscussionParser;
|
||||
use EchoEmailFormat;
|
||||
use EchoEmailFrequency;
|
||||
use EchoEvent;
|
||||
use EchoNotification;
|
||||
use EchoSeenTime;
|
||||
use EchoServices;
|
||||
use EmailNotification;
|
||||
|
@ -30,6 +28,8 @@ use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
|||
use MediaWiki\Extension\Notifications\Formatters\EchoEventPresentationModel;
|
||||
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
|
||||
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use MediaWiki\Extension\Notifications\Push\Api\ApiEchoPushSubscriptions;
|
||||
use MediaWiki\Hook\AbortTalkPageEmailNotificationHook;
|
||||
use MediaWiki\Hook\BeforePageDisplayHook;
|
||||
|
@ -316,7 +316,7 @@ class Hooks implements
|
|||
/**
|
||||
* Handler for EchoGetBundleRule hook, which defines the bundle rule for each notification
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param string &$bundleString Determines how the notification should be bundled, for example,
|
||||
* talk page notification is bundled based on namespace and title, the bundle string would be
|
||||
* 'edit-user-talk-' + namespace + title, email digest/email bundling would use this hash as
|
||||
|
@ -626,7 +626,7 @@ class Hooks implements
|
|||
DeferredUpdates::addCallableUpdate( static function () use ( $userIdentity, $title, $thresholdCount ) {
|
||||
$notificationMapper = new NotificationMapper();
|
||||
$notifications = $notificationMapper->fetchByUser( $userIdentity, 10, null, [ 'thank-you-edit' ] );
|
||||
/** @var EchoNotification $notification */
|
||||
/** @var Notification $notification */
|
||||
foreach ( $notifications as $notification ) {
|
||||
if ( $notification->getEvent()->getExtraParam( 'editCount' ) === $thresholdCount ) {
|
||||
LoggerFactory::getInstance( 'Echo' )->debug(
|
||||
|
@ -641,7 +641,7 @@ class Hooks implements
|
|||
}
|
||||
}
|
||||
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'thank-you-edit',
|
||||
'title' => $title,
|
||||
'agent' => $userIdentity,
|
||||
|
@ -669,7 +669,7 @@ class Hooks implements
|
|||
$revertedUser = $undidRevision->getUser();
|
||||
// No notifications for anonymous users
|
||||
if ( $revertedUser && $revertedUser->getId() ) {
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'reverted',
|
||||
'title' => $title,
|
||||
'extra' => [
|
||||
|
@ -705,7 +705,7 @@ class Hooks implements
|
|||
/**
|
||||
* Handler for EchoAbortEmailNotification hook
|
||||
* @param User $user
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @return bool true - send email, false - do not send email
|
||||
*/
|
||||
public static function onEchoAbortEmailNotification( $user, $event ) {
|
||||
|
@ -770,7 +770,7 @@ class Hooks implements
|
|||
foreach ( $overrides as $prefKey => $value ) {
|
||||
$userOptionsManager->setOption( $user, $prefKey, $value );
|
||||
}
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'welcome',
|
||||
'agent' => $user,
|
||||
] );
|
||||
|
@ -828,7 +828,7 @@ class Hooks implements
|
|||
if ( $expiryChanged ) {
|
||||
// use a separate notification for these, so the notification text doesn't
|
||||
// get too long
|
||||
EchoEvent::create(
|
||||
Event::create(
|
||||
[
|
||||
'type' => 'user-rights',
|
||||
'extra' => [
|
||||
|
@ -842,7 +842,7 @@ class Hooks implements
|
|||
}
|
||||
|
||||
if ( $reallyAdded || $remove ) {
|
||||
EchoEvent::create(
|
||||
Event::create(
|
||||
[
|
||||
'type' => 'user-rights',
|
||||
'extra' => [
|
||||
|
@ -901,7 +901,7 @@ class Hooks implements
|
|||
}
|
||||
|
||||
$linkFromPageId = $linksUpdate->getTitle()->getArticleID();
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'page-linked',
|
||||
'title' => $title,
|
||||
'agent' => $user,
|
||||
|
@ -1337,7 +1337,7 @@ class Hooks implements
|
|||
$revertedUser->getId() && // No notifications for anonymous users
|
||||
!$oldRevision->hasSameContent( $newRevision ) // No notifications for null rollbacks
|
||||
) {
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'reverted',
|
||||
'title' => $wikiPage->getTitle(),
|
||||
'extra' => [
|
||||
|
@ -1480,7 +1480,7 @@ class Hooks implements
|
|||
$preview = $subject;
|
||||
}
|
||||
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'emailuser',
|
||||
'extra' => [
|
||||
'to-user-id' => $userTo->getId(),
|
||||
|
@ -1543,7 +1543,7 @@ class Hooks implements
|
|||
$thankYouIds = [];
|
||||
$thankYouRows = $dbw->select(
|
||||
[ 'echo_notification', 'echo_event' ],
|
||||
EchoEvent::selectFields(),
|
||||
Event::selectFields(),
|
||||
[
|
||||
'notification_user' => $newUser->getId(),
|
||||
'notification_event = event_id',
|
||||
|
@ -1553,7 +1553,7 @@ class Hooks implements
|
|||
[ 'ORDER BY' => 'notification_timestamp ASC' ]
|
||||
) ?: [];
|
||||
foreach ( $thankYouRows as $row ) {
|
||||
$event = EchoEvent::newFromRow( $row );
|
||||
$event = Event::newFromRow( $row );
|
||||
$editCount = $event ? $event->getExtraParam( 'editCount' ) : null;
|
||||
if ( $editCount ) {
|
||||
if ( isset( $counts[$editCount] ) ) {
|
||||
|
@ -1698,7 +1698,7 @@ class Hooks implements
|
|||
} else {
|
||||
$type = 'watchlist-change';
|
||||
}
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => $type,
|
||||
'title' => $change->getTitle(),
|
||||
'extra' => [
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Mapper;
|
||||
|
||||
use EchoEvent;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MWException;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* Database mapper for EchoEvent model, which is an immutable class, there should
|
||||
* Database mapper for Event model, which is an immutable class, there should
|
||||
* not be any update to it
|
||||
*/
|
||||
class EventMapper extends AbstractMapper {
|
||||
|
@ -15,10 +15,10 @@ class EventMapper extends AbstractMapper {
|
|||
/**
|
||||
* Insert an event record
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @return int
|
||||
*/
|
||||
public function insert( EchoEvent $event ) {
|
||||
public function insert( Event $event ) {
|
||||
$dbw = $this->dbFactory->getEchoDb( DB_PRIMARY );
|
||||
|
||||
$row = $event->toDbArray();
|
||||
|
@ -36,26 +36,26 @@ class EventMapper extends AbstractMapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create an EchoEvent by id
|
||||
* Create an Event by id
|
||||
*
|
||||
* @param int $id
|
||||
* @param bool $fromPrimary
|
||||
* @return EchoEvent|false False if it wouldn't load/unserialize
|
||||
* @return Event|false False if it wouldn't load/unserialize
|
||||
* @throws MWException
|
||||
*/
|
||||
public function fetchById( $id, $fromPrimary = false ) {
|
||||
$db = $fromPrimary ? $this->dbFactory->getEchoDb( DB_PRIMARY ) : $this->dbFactory->getEchoDb( DB_REPLICA );
|
||||
|
||||
$row = $db->selectRow( 'echo_event', EchoEvent::selectFields(), [ 'event_id' => $id ], __METHOD__ );
|
||||
$row = $db->selectRow( 'echo_event', Event::selectFields(), [ 'event_id' => $id ], __METHOD__ );
|
||||
|
||||
// If the row was not found, fall back on the primary database if it makes sense to do so
|
||||
if ( !$row && !$fromPrimary && $this->dbFactory->canRetryPrimary() ) {
|
||||
return $this->fetchById( $id, true );
|
||||
} elseif ( !$row ) {
|
||||
throw new MWException( "No EchoEvent found with ID: $id" );
|
||||
throw new MWException( "No Event found with ID: $id" );
|
||||
}
|
||||
|
||||
return EchoEvent::newFromRow( $row );
|
||||
return Event::newFromRow( $row );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +84,7 @@ class EventMapper extends AbstractMapper {
|
|||
* Fetch events associated with a page
|
||||
*
|
||||
* @param int $pageId
|
||||
* @return EchoEvent[] Events
|
||||
* @return Event[] Events
|
||||
*/
|
||||
public function fetchByPage( $pageId ) {
|
||||
$events = [];
|
||||
|
@ -94,13 +94,13 @@ class EventMapper extends AbstractMapper {
|
|||
// From echo_event
|
||||
$res = $dbr->select(
|
||||
[ 'echo_event' ],
|
||||
EchoEvent::selectFields(),
|
||||
Event::selectFields(),
|
||||
[ 'event_page_id' => $pageId ],
|
||||
__METHOD__
|
||||
);
|
||||
if ( $res ) {
|
||||
foreach ( $res as $row ) {
|
||||
$event = EchoEvent::newFromRow( $row );
|
||||
$event = Event::newFromRow( $row );
|
||||
$events[] = $event;
|
||||
$seenEventIds[] = $event->getId();
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class EventMapper extends AbstractMapper {
|
|||
}
|
||||
$res = $dbr->select(
|
||||
[ 'echo_event', 'echo_target_page' ],
|
||||
EchoEvent::selectFields(),
|
||||
Event::selectFields(),
|
||||
$conds,
|
||||
__METHOD__,
|
||||
[ 'DISTINCT' ],
|
||||
|
@ -123,7 +123,7 @@ class EventMapper extends AbstractMapper {
|
|||
);
|
||||
if ( $res ) {
|
||||
foreach ( $res as $row ) {
|
||||
$events[] = EchoEvent::newFromRow( $row );
|
||||
$events[] = Event::newFromRow( $row );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,7 +139,7 @@ class EventMapper extends AbstractMapper {
|
|||
public function fetchIdsByPage( $pageId ) {
|
||||
$events = $this->fetchByPage( $pageId );
|
||||
$eventIds = array_map(
|
||||
static function ( EchoEvent $event ) {
|
||||
static function ( Event $event ) {
|
||||
return $event->getId();
|
||||
},
|
||||
$events
|
||||
|
@ -152,11 +152,11 @@ class EventMapper extends AbstractMapper {
|
|||
*
|
||||
* @param User $user
|
||||
* @param int $pageId
|
||||
* @return EchoEvent[]
|
||||
* @return Event[]
|
||||
*/
|
||||
public function fetchUnreadByUserAndPage( User $user, $pageId ) {
|
||||
$dbr = $this->dbFactory->getEchoDb( DB_REPLICA );
|
||||
$fields = array_merge( EchoEvent::selectFields(), [ 'notification_timestamp' ] );
|
||||
$fields = array_merge( Event::selectFields(), [ 'notification_timestamp' ] );
|
||||
|
||||
$res = $dbr->select(
|
||||
[ 'echo_event', 'echo_notification', 'echo_target_page' ],
|
||||
|
@ -177,7 +177,7 @@ class EventMapper extends AbstractMapper {
|
|||
|
||||
$data = [];
|
||||
foreach ( $res as $row ) {
|
||||
$data[] = EchoEvent::newFromRow( $row );
|
||||
$data[] = Event::newFromRow( $row );
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
|
|
@ -5,8 +5,8 @@ namespace MediaWiki\Extension\Notifications\Mapper;
|
|||
use AtomicSectionUpdate;
|
||||
use BatchRowIterator;
|
||||
use DeferredUpdates;
|
||||
use EchoNotification;
|
||||
use Exception;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MWException;
|
||||
|
@ -15,15 +15,15 @@ use Title;
|
|||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
||||
/**
|
||||
* Database mapper for EchoNotification model
|
||||
* Database mapper for Notification model
|
||||
*/
|
||||
class NotificationMapper extends AbstractMapper {
|
||||
|
||||
/**
|
||||
* Insert a notification record
|
||||
* @param EchoNotification $notification
|
||||
* @param Notification $notification
|
||||
*/
|
||||
public function insert( EchoNotification $notification ) {
|
||||
public function insert( Notification $notification ) {
|
||||
$dbw = $this->dbFactory->getEchoDb( DB_PRIMARY );
|
||||
|
||||
$listeners = $this->getMethodListeners( __FUNCTION__ );
|
||||
|
@ -81,7 +81,7 @@ class NotificationMapper extends AbstractMapper {
|
|||
* @param Title[]|null $titles If set, only return notifications for these pages.
|
||||
* To find notifications not associated with any page, add null as an element to this array.
|
||||
* @param int $dbSource Use primary database or replica database
|
||||
* @return EchoNotification[]
|
||||
* @return Notification[]
|
||||
*/
|
||||
public function fetchUnreadByUser(
|
||||
UserIdentity $userIdentity,
|
||||
|
@ -121,7 +121,7 @@ class NotificationMapper extends AbstractMapper {
|
|||
* @param Title[]|null $titles If set, only return notifications for these pages.
|
||||
* To find notifications not associated with any page, add null as an element to this array.
|
||||
* @param int $dbSource Use primary database or replica database
|
||||
* @return EchoNotification[]
|
||||
* @return Notification[]
|
||||
*/
|
||||
public function fetchReadByUser(
|
||||
UserIdentity $userIdentity,
|
||||
|
@ -158,7 +158,7 @@ class NotificationMapper extends AbstractMapper {
|
|||
* @param array $excludeEventIds Event id's to exclude.
|
||||
* @param Title[]|null $titles If set, only return notifications for these pages.
|
||||
* To find notifications not associated with any page, add null as an element to this array.
|
||||
* @return EchoNotification[]
|
||||
* @return Notification[]
|
||||
*/
|
||||
public function fetchByUser(
|
||||
UserIdentity $userIdentity,
|
||||
|
@ -209,7 +209,7 @@ class NotificationMapper extends AbstractMapper {
|
|||
* @param array $eventTypes Event types to load
|
||||
* @param array $conds Additional query conditions.
|
||||
* @param int $dbSource Use primary database or replica database
|
||||
* @return EchoNotification[]
|
||||
* @return Notification[]
|
||||
*/
|
||||
protected function fetchByUserInternal(
|
||||
UserIdentity $userIdentity,
|
||||
|
@ -249,7 +249,7 @@ class NotificationMapper extends AbstractMapper {
|
|||
|
||||
$res = $dbr->select(
|
||||
[ 'echo_notification', 'echo_event' ],
|
||||
EchoNotification::selectFields(),
|
||||
Notification::selectFields(),
|
||||
$conds,
|
||||
__METHOD__,
|
||||
[
|
||||
|
@ -266,11 +266,11 @@ class NotificationMapper extends AbstractMapper {
|
|||
return [];
|
||||
}
|
||||
|
||||
/** @var EchoNotification[] $allNotifications */
|
||||
/** @var Notification[] $allNotifications */
|
||||
$allNotifications = [];
|
||||
foreach ( $res as $row ) {
|
||||
try {
|
||||
$notification = EchoNotification::newFromRow( $row );
|
||||
$notification = Notification::newFromRow( $row );
|
||||
if ( $notification ) {
|
||||
$allNotifications[] = $notification;
|
||||
}
|
||||
|
@ -290,18 +290,18 @@ class NotificationMapper extends AbstractMapper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Fetch EchoNotifications by user and event IDs.
|
||||
* Fetch Notifications by user and event IDs.
|
||||
*
|
||||
* @param UserIdentity $userIdentity
|
||||
* @param int[] $eventIds
|
||||
* @return EchoNotification[]|false
|
||||
* @return Notification[]|false
|
||||
*/
|
||||
public function fetchByUserEvents( UserIdentity $userIdentity, array $eventIds ) {
|
||||
$dbr = $this->dbFactory->getEchoDb( DB_REPLICA );
|
||||
|
||||
$result = $dbr->select(
|
||||
[ 'echo_notification', 'echo_event' ],
|
||||
EchoNotification::selectFields(),
|
||||
Notification::selectFields(),
|
||||
[
|
||||
'notification_user' => $userIdentity->getId(),
|
||||
'notification_event' => $eventIds
|
||||
|
@ -316,7 +316,7 @@ class NotificationMapper extends AbstractMapper {
|
|||
if ( $result ) {
|
||||
$notifications = [];
|
||||
foreach ( $result as $row ) {
|
||||
$notifications[] = EchoNotification::newFromRow( $row );
|
||||
$notifications[] = Notification::newFromRow( $row );
|
||||
}
|
||||
return $notifications;
|
||||
} else {
|
||||
|
@ -329,13 +329,13 @@ class NotificationMapper extends AbstractMapper {
|
|||
* know that passing a big number for offset is NOT going to work
|
||||
* @param UserIdentity $userIdentity
|
||||
* @param int $offset
|
||||
* @return EchoNotification|false
|
||||
* @return Notification|false
|
||||
*/
|
||||
public function fetchByUserOffset( UserIdentity $userIdentity, $offset ) {
|
||||
$dbr = $this->dbFactory->getEchoDb( DB_REPLICA );
|
||||
$row = $dbr->selectRow(
|
||||
[ 'echo_notification', 'echo_event' ],
|
||||
EchoNotification::selectFields(),
|
||||
Notification::selectFields(),
|
||||
[
|
||||
'notification_user' => $userIdentity->getId(),
|
||||
'event_deleted' => 0,
|
||||
|
@ -352,7 +352,7 @@ class NotificationMapper extends AbstractMapper {
|
|||
);
|
||||
|
||||
if ( $row ) {
|
||||
return EchoNotification::newFromRow( $row );
|
||||
return Notification::newFromRow( $row );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Mapper;
|
||||
|
||||
use EchoTargetPage;
|
||||
use MediaWiki\Extension\Notifications\Model\TargetPage;
|
||||
|
||||
/**
|
||||
* Database mapper for EchoTargetPage model
|
||||
* Database mapper for TargetPage model
|
||||
*/
|
||||
class TargetPageMapper extends AbstractMapper {
|
||||
|
||||
/**
|
||||
* List of db fields used to construct an EchoTargetPage model
|
||||
* List of db fields used to construct an TargetPage model
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $fields = [
|
||||
|
@ -19,12 +19,12 @@ class TargetPageMapper extends AbstractMapper {
|
|||
];
|
||||
|
||||
/**
|
||||
* Insert an EchoTargetPage instance into the database
|
||||
* Insert an TargetPage instance into the database
|
||||
*
|
||||
* @param EchoTargetPage $targetPage
|
||||
* @param TargetPage $targetPage
|
||||
* @return bool
|
||||
*/
|
||||
public function insert( EchoTargetPage $targetPage ) {
|
||||
public function insert( TargetPage $targetPage ) {
|
||||
$dbw = $this->dbFactory->getEchoDb( DB_PRIMARY );
|
||||
|
||||
$row = $targetPage->toDbArray();
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Notifications\Model;
|
||||
|
||||
/**
|
||||
* Abstract entity for Echo model
|
||||
*/
|
||||
abstract class EchoAbstractEntity {
|
||||
abstract class AbstractEntity {
|
||||
|
||||
/**
|
||||
* Convert an entity's property to array
|
|
@ -1,5 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Notifications\Model;
|
||||
|
||||
use Bundleable;
|
||||
use EchoServices;
|
||||
use Exception;
|
||||
use Hooks;
|
||||
use InvalidArgumentException;
|
||||
use MediaWiki\Extension\Notifications\Cache\RevisionLocalCache;
|
||||
use MediaWiki\Extension\Notifications\Cache\TitleLocalCache;
|
||||
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
||||
|
@ -9,12 +16,17 @@ use MediaWiki\Logger\LoggerFactory;
|
|||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
use MWEchoDbFactory;
|
||||
use MWException;
|
||||
use stdClass;
|
||||
use Title;
|
||||
use User;
|
||||
|
||||
/**
|
||||
* Immutable class to represent an event.
|
||||
* In Echo nomenclature, an event is a single occurrence.
|
||||
*/
|
||||
class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
||||
class Event extends AbstractEntity implements Bundleable {
|
||||
|
||||
/** @var string|null */
|
||||
protected $type = null;
|
||||
|
@ -62,7 +74,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
/**
|
||||
* Other events bundled with this one
|
||||
*
|
||||
* @var EchoEvent[]
|
||||
* @var Event[]
|
||||
*/
|
||||
protected $bundledEvents;
|
||||
|
||||
|
@ -75,10 +87,10 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
|
||||
/**
|
||||
* You should not call the constructor.
|
||||
* Instead use one of the factory functions:
|
||||
* EchoEvent::create To create a new event
|
||||
* EchoEvent::newFromRow To create an event object from a row object
|
||||
* EchoEvent::newFromID To create an event object from the database given its ID
|
||||
* Instead, use one of the factory functions:
|
||||
* Event::create To create a new event
|
||||
* Event::newFromRow To create an event object from a row object
|
||||
* Event::newFromID To create an event object from the database given its ID
|
||||
*/
|
||||
protected function __construct() {
|
||||
}
|
||||
|
@ -86,7 +98,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
## Save the id and timestamp
|
||||
public function __sleep() {
|
||||
if ( !$this->id ) {
|
||||
throw new MWException( "Unable to serialize an uninitialized EchoEvent" );
|
||||
throw new MWException( "Unable to serialize an uninitialized Event" );
|
||||
}
|
||||
|
||||
return [ 'id', 'timestamp' ];
|
||||
|
@ -97,11 +109,11 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
}
|
||||
|
||||
public function __toString() {
|
||||
return "EchoEvent(id={$this->id}; type={$this->type})";
|
||||
return "Event(id={$this->id}; type={$this->type})";
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an EchoEvent object
|
||||
* Creates an Event object
|
||||
* @param array $info Named arguments:
|
||||
* type (required): The event type;
|
||||
* variant: A variant of the type;
|
||||
|
@ -122,7 +134,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
* [ 'extra' => Job::newRootJobParams('example') ]
|
||||
*
|
||||
* @throws MWException
|
||||
* @return EchoEvent|false False if aborted via hook or Echo DB is read-only
|
||||
* @return Event|false False if aborted via hook or Echo DB is read-only
|
||||
*/
|
||||
public static function create( $info = [] ) {
|
||||
global $wgEchoNotifications;
|
||||
|
@ -134,7 +146,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
return false;
|
||||
}
|
||||
|
||||
$obj = new EchoEvent;
|
||||
$obj = new Event;
|
||||
static $validFields = [ 'type', 'variant', 'agent', 'title', 'extra' ];
|
||||
|
||||
if ( empty( $info['type'] ) ) {
|
||||
|
@ -188,7 +200,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
// @Todo - Database insert logic should not be inside the model
|
||||
$obj->insert();
|
||||
|
||||
Hooks::run( 'EchoEventInsertComplete', [ $obj ] );
|
||||
Hooks::run( 'EventInsertComplete', [ $obj ] );
|
||||
|
||||
global $wgEchoUseJobQueue;
|
||||
|
||||
|
@ -258,7 +270,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
if ( $targetPages ) {
|
||||
$targetMapper = new TargetPageMapper();
|
||||
foreach ( $targetPages as $title ) {
|
||||
$targetPage = EchoTargetPage::create( $title, $this );
|
||||
$targetPage = TargetPage::create( $title, $this );
|
||||
if ( $targetPage ) {
|
||||
$targetMapper->insert( $targetPage );
|
||||
}
|
||||
|
@ -387,26 +399,26 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates an EchoEvent from a row object
|
||||
* Creates an Event from a row object
|
||||
*
|
||||
* @param stdClass $row row object from echo_event
|
||||
* @return EchoEvent|false
|
||||
* @return Event|false
|
||||
*/
|
||||
public static function newFromRow( $row ) {
|
||||
$obj = new EchoEvent();
|
||||
$obj = new Event();
|
||||
return $obj->loadFromRow( $row )
|
||||
? $obj
|
||||
: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an EchoEvent from the database by ID
|
||||
* Creates an Event from the database by ID
|
||||
*
|
||||
* @param int $id Event ID
|
||||
* @return EchoEvent|false
|
||||
* @return Event|false
|
||||
*/
|
||||
public static function newFromID( $id ) {
|
||||
$obj = new EchoEvent();
|
||||
$obj = new Event();
|
||||
return $obj->loadFromID( $id )
|
||||
? $obj
|
||||
: false;
|
||||
|
@ -597,9 +609,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
* @return string
|
||||
*/
|
||||
public function getCategory() {
|
||||
$attributeManager = EchoServices::getInstance()->getAttributeManager();
|
||||
|
||||
return $attributeManager->getNotificationCategory( $this->type );
|
||||
return EchoServices::getInstance()->getAttributeManager()->getNotificationCategory( $this->type );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -607,9 +617,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
* @return string
|
||||
*/
|
||||
public function getSection() {
|
||||
$attributeManager = EchoServices::getInstance()->getAttributeManager();
|
||||
|
||||
return $attributeManager->getNotificationSection( $this->type );
|
||||
return EchoServices::getInstance()->getAttributeManager()->getNotificationSection( $this->type );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -735,7 +743,7 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
|
||||
/**
|
||||
* Return the list of fields that should be selected to create
|
||||
* a new event with EchoEvent::newFromRow
|
||||
* a new event with Event::newFromRow
|
||||
* @return string[]
|
||||
*/
|
||||
public static function selectFields() {
|
||||
|
@ -753,5 +761,4 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
|
|||
|
||||
}
|
||||
|
||||
// Needed to help migrate AbuseFilter
|
||||
class_alias( EchoEvent::class, 'MediaWiki\\Extension\\Notifications\\Model\\Event' );
|
||||
class_alias( Event::class, 'EchoEvent' );
|
|
@ -1,9 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Notifications\Model;
|
||||
|
||||
use Bundleable;
|
||||
use Hooks;
|
||||
use InvalidArgumentException;
|
||||
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MWEchoNotifUser;
|
||||
use MWException;
|
||||
use stdClass;
|
||||
use User;
|
||||
|
||||
class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
||||
class Notification extends AbstractEntity implements Bundleable {
|
||||
|
||||
/**
|
||||
* @var User
|
||||
|
@ -11,7 +20,7 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
protected $user;
|
||||
|
||||
/**
|
||||
* @var EchoEvent
|
||||
* @var Event
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
|
@ -19,7 +28,7 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
* The target page object for the notification if there is one. Null means
|
||||
* the information has not been loaded.
|
||||
*
|
||||
* @var EchoTargetPage[]|null
|
||||
* @var TargetPage[]|null
|
||||
*/
|
||||
protected $targetPages;
|
||||
|
||||
|
@ -40,7 +49,7 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
protected $bundleHash = '';
|
||||
|
||||
/**
|
||||
* @var EchoNotification[]
|
||||
* @var Notification[]
|
||||
*/
|
||||
protected $bundledNotifications;
|
||||
|
||||
|
@ -51,15 +60,15 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates an EchoNotification object based on event and user
|
||||
* Creates an Notification object based on event and user
|
||||
* @param array $info The following keys are required:
|
||||
* - 'event' The EchoEvent being notified about.
|
||||
* - 'event' The Event being notified about.
|
||||
* - 'user' The User being notified.
|
||||
* @throws MWException
|
||||
* @return EchoNotification
|
||||
* @return Notification
|
||||
*/
|
||||
public static function create( array $info ) {
|
||||
$obj = new EchoNotification();
|
||||
$obj = new Notification();
|
||||
static $validFields = [ 'event', 'user' ];
|
||||
|
||||
foreach ( $validFields as $field ) {
|
||||
|
@ -74,8 +83,8 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
throw new InvalidArgumentException( 'Invalid user parameter, expected: User object' );
|
||||
}
|
||||
|
||||
if ( !$obj->event instanceof EchoEvent ) {
|
||||
throw new InvalidArgumentException( 'Invalid event parameter, expected: EchoEvent object' );
|
||||
if ( !$obj->event instanceof Event ) {
|
||||
throw new InvalidArgumentException( 'Invalid event parameter, expected: Event object' );
|
||||
}
|
||||
|
||||
// Notification timestamp should be the same as event timestamp
|
||||
|
@ -133,16 +142,16 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
/**
|
||||
* Load a notification record from std class
|
||||
* @param stdClass $row
|
||||
* @param EchoTargetPage[]|null $targetPages An array of EchoTargetPage instances, or null if not loaded.
|
||||
* @return EchoNotification|false False if failed to load/unserialize
|
||||
* @param TargetPage[]|null $targetPages An array of TargetPage instances, or null if not loaded.
|
||||
* @return Notification|false False if failed to load/unserialize
|
||||
*/
|
||||
public static function newFromRow( $row, array $targetPages = null ) {
|
||||
$notification = new EchoNotification();
|
||||
$notification = new Notification();
|
||||
|
||||
if ( property_exists( $row, 'event_type' ) ) {
|
||||
$notification->event = EchoEvent::newFromRow( $row );
|
||||
$notification->event = Event::newFromRow( $row );
|
||||
} else {
|
||||
$notification->event = EchoEvent::newFromID( $row->notification_event );
|
||||
$notification->event = Event::newFromID( $row->notification_event );
|
||||
}
|
||||
|
||||
if ( $notification->event === false ) {
|
||||
|
@ -175,7 +184,7 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
|
||||
/**
|
||||
* Getter method
|
||||
* @return EchoEvent The event for this notification
|
||||
* @return Event The event for this notification
|
||||
*/
|
||||
public function getEvent() {
|
||||
return $this->event;
|
||||
|
@ -218,10 +227,10 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
}
|
||||
|
||||
/**
|
||||
* Getter method. Returns an array of EchoTargetPages, or null if they have
|
||||
* Getter method. Returns an array of TargetPage's, or null if they have
|
||||
* not been loaded.
|
||||
*
|
||||
* @return EchoTargetPage[]|null
|
||||
* @return TargetPage[]|null
|
||||
*/
|
||||
public function getTargetPages() {
|
||||
return $this->targetPages;
|
||||
|
@ -265,11 +274,11 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
|
||||
/**
|
||||
* Return the list of fields that should be selected to create
|
||||
* a new event with EchoNotification::newFromRow
|
||||
* a new event with Notification::newFromRow
|
||||
* @return string[]
|
||||
*/
|
||||
public static function selectFields() {
|
||||
return array_merge( EchoEvent::selectFields(), [
|
||||
return array_merge( Event::selectFields(), [
|
||||
'notification_event',
|
||||
'notification_user',
|
||||
'notification_timestamp',
|
||||
|
@ -278,3 +287,5 @@ class EchoNotification extends EchoAbstractEntity implements Bundleable {
|
|||
] );
|
||||
}
|
||||
}
|
||||
|
||||
class_alias( Notification::class, 'EchoNotification' );
|
|
@ -1,11 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Notifications\Model;
|
||||
|
||||
use MWException;
|
||||
use stdClass;
|
||||
use Title;
|
||||
|
||||
/**
|
||||
* Map a title to an echo event so that we can mark a notification as read
|
||||
* when visiting the page. This only supports titles with ids because majority
|
||||
* of notifications have page_id and searching by namespace and title is slow
|
||||
*/
|
||||
class EchoTargetPage extends EchoAbstractEntity {
|
||||
class TargetPage extends AbstractEntity {
|
||||
|
||||
/**
|
||||
* @var Title|null|false False if not initialized yet
|
||||
|
@ -18,7 +24,7 @@ class EchoTargetPage extends EchoAbstractEntity {
|
|||
protected $pageId;
|
||||
|
||||
/**
|
||||
* @var EchoEvent|null
|
||||
* @var Event|null
|
||||
*/
|
||||
protected $event;
|
||||
|
||||
|
@ -39,13 +45,13 @@ class EchoTargetPage extends EchoAbstractEntity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a EchoTargetPage instance from Title and EchoEvent
|
||||
* Create a TargetPage instance from Title and Event
|
||||
*
|
||||
* @param Title $title
|
||||
* @param EchoEvent $event
|
||||
* @return EchoTargetPage|null
|
||||
* @param Event $event
|
||||
* @return TargetPage|null
|
||||
*/
|
||||
public static function create( Title $title, EchoEvent $event ) {
|
||||
public static function create( Title $title, Event $event ) {
|
||||
// This only support title with a page_id
|
||||
if ( !$title->getArticleID() ) {
|
||||
return null;
|
||||
|
@ -61,10 +67,10 @@ class EchoTargetPage extends EchoAbstractEntity {
|
|||
}
|
||||
|
||||
/**
|
||||
* Create a EchoTargetPage instance from stdClass object
|
||||
* Create a TargetPage instance from stdClass object
|
||||
*
|
||||
* @param stdClass $row
|
||||
* @return EchoTargetPage
|
||||
* @return TargetPage
|
||||
* @throws MWException
|
||||
*/
|
||||
public static function newFromRow( $row ) {
|
||||
|
@ -106,11 +112,11 @@ class EchoTargetPage extends EchoAbstractEntity {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return EchoEvent
|
||||
* @return Event
|
||||
*/
|
||||
public function getEvent() {
|
||||
if ( !$this->event ) {
|
||||
$this->event = EchoEvent::newFromID( $this->eventId );
|
||||
$this->event = Event::newFromID( $this->eventId );
|
||||
}
|
||||
|
||||
return $this->event;
|
|
@ -3,6 +3,7 @@
|
|||
use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway;
|
||||
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
||||
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\User\UserFactory;
|
||||
use MediaWiki\User\UserIdentity;
|
||||
|
@ -385,7 +386,7 @@ class MWEchoNotifUser {
|
|||
$notifs = $this->notifMapper->fetchUnreadByUser( $this->mUser, $wgEchoMaxUpdateCount, null, $eventTypes );
|
||||
|
||||
$eventIds = array_filter(
|
||||
array_map( static function ( EchoNotification $notif ) {
|
||||
array_map( static function ( Notification $notif ) {
|
||||
// This should not happen at all, but use 0 in
|
||||
// such case so to keep the code running
|
||||
if ( $notif->getEvent() ) {
|
||||
|
|
|
@ -2,16 +2,18 @@
|
|||
|
||||
use MediaWiki\Extension\Notifications\Formatters\EchoHtmlEmailFormatter;
|
||||
use MediaWiki\Extension\Notifications\Formatters\EchoPlainTextEmailFormatter;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
// @todo Fill in
|
||||
class EchoNotifier {
|
||||
/**
|
||||
* Record an EchoNotification for an EchoEvent
|
||||
* Record a Notification for an Event
|
||||
* Currently used for web-based notifications.
|
||||
*
|
||||
* @param User $user User to notify.
|
||||
* @param EchoEvent $event EchoEvent to notify about.
|
||||
* @param Event $event Event to notify about.
|
||||
*/
|
||||
public static function notifyWithNotification( $user, $event ) {
|
||||
// Only create the notification if the user wants to receive that type
|
||||
|
@ -22,14 +24,14 @@ class EchoNotifier {
|
|||
return;
|
||||
}
|
||||
|
||||
EchoNotification::create( [ 'user' => $user, 'event' => $event ] );
|
||||
Notification::create( [ 'user' => $user, 'event' => $event ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a Notification to a user by email
|
||||
*
|
||||
* @param User $user User to notify.
|
||||
* @param EchoEvent $event EchoEvent to notify about.
|
||||
* @param Event $event Event to notify about.
|
||||
* @return bool
|
||||
*/
|
||||
public static function notifyWithEmail( $user, $event ) {
|
||||
|
@ -115,11 +117,11 @@ class EchoNotifier {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param User $user
|
||||
* @return array|false An array of 'subject' and 'body', or false if things went wrong
|
||||
*/
|
||||
private static function generateEmail( EchoEvent $event, User $user ) {
|
||||
private static function generateEmail( Event $event, User $user ) {
|
||||
$emailFormat = MWEchoNotifUser::newFromUser( $user )->getEmailFormat();
|
||||
$userOptionsLookup = MediaWikiServices::getInstance()->getUserOptionsLookup();
|
||||
$lang = Language::factory( $userOptionsLookup->getOption( $user, 'language' ) );
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Push;
|
||||
|
||||
use EchoEvent;
|
||||
use EchoServices;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use User;
|
||||
|
||||
|
@ -13,9 +13,9 @@ class PushNotifier {
|
|||
* Submits a notification derived from an Echo event to each push notifications service
|
||||
* subscription found for a user, via a configured service handler implementation
|
||||
* @param User $user
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
*/
|
||||
public static function notifyWithPush( User $user, EchoEvent $event ): void {
|
||||
public static function notifyWithPush( User $user, Event $event ): void {
|
||||
$attributeManager = EchoServices::getInstance()->getAttributeManager();
|
||||
$userEnabledEvents = $attributeManager->getUserEnabledEvents( $user, 'push' );
|
||||
if ( in_array( $event->getType(), $userEnabledEvents ) ) {
|
||||
|
@ -25,10 +25,10 @@ class PushNotifier {
|
|||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param EchoEvent|null $event
|
||||
* @param Event|null $event
|
||||
* @return NotificationRequestJob
|
||||
*/
|
||||
private static function createJob( User $user, EchoEvent $event = null ): NotificationRequestJob {
|
||||
private static function createJob( User $user, Event $event = null ): NotificationRequestJob {
|
||||
$centralId = Utils::getPushUserId( $user );
|
||||
$params = [ 'centralId' => $centralId ];
|
||||
// below params are only needed for debug logging (T255068)
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
namespace MediaWiki\Extension\Notifications\Special;
|
||||
|
||||
use EchoNotification;
|
||||
use EchoServices;
|
||||
use Exception;
|
||||
use IContextSource;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use MWEchoDbFactory;
|
||||
use ReverseChronologicalPager;
|
||||
|
||||
|
@ -28,7 +28,7 @@ class NotificationPager extends ReverseChronologicalPager {
|
|||
public function formatRow( $row ) {
|
||||
// @phan-suppress-previous-line PhanPluginNeverReturnMethod LSP violation
|
||||
throw new Exception( "This pager does not support row formatting. " .
|
||||
"Use 'getNotifications()' to get a list of EchoNotification objects." );
|
||||
"Use 'getNotifications()' to get a list of Notification objects." );
|
||||
}
|
||||
|
||||
public function getQueryInfo() {
|
||||
|
@ -37,7 +37,7 @@ class NotificationPager extends ReverseChronologicalPager {
|
|||
|
||||
return [
|
||||
'tables' => [ 'echo_notification', 'echo_event' ],
|
||||
'fields' => EchoNotification::selectFields(),
|
||||
'fields' => Notification::selectFields(),
|
||||
'conds' => [
|
||||
'notification_user' => $this->getUser()->getId(),
|
||||
'event_type' => $eventTypes,
|
||||
|
@ -61,7 +61,7 @@ class NotificationPager extends ReverseChronologicalPager {
|
|||
|
||||
$notifications = [];
|
||||
foreach ( $this->mResult as $row ) {
|
||||
$notifications[] = EchoNotification::newFromRow( $row );
|
||||
$notifications[] = Notification::newFromRow( $row );
|
||||
}
|
||||
|
||||
// get rid of the overfetched
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Iterator\CallbackIterator;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
class EchoUserLocator {
|
||||
|
@ -10,11 +11,11 @@ class EchoUserLocator {
|
|||
* The echo job queue must be enabled to prevent timeouts submitting to
|
||||
* heavily watched pages when this is used.
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param int $batchSize
|
||||
* @return User[]|Iterator<User>
|
||||
*/
|
||||
public static function locateUsersWatchingTitle( EchoEvent $event, $batchSize = 500 ) {
|
||||
public static function locateUsersWatchingTitle( Event $event, $batchSize = 500 ) {
|
||||
$title = $event->getTitle();
|
||||
if ( !$title ) {
|
||||
return [];
|
||||
|
@ -47,10 +48,10 @@ class EchoUserLocator {
|
|||
* If the event occurred on the talk page of a registered
|
||||
* user return that user.
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @return User[]
|
||||
*/
|
||||
public static function locateTalkPageOwner( EchoEvent $event ) {
|
||||
public static function locateTalkPageOwner( Event $event ) {
|
||||
$title = $event->getTitle();
|
||||
if ( !$title || $title->getNamespace() !== NS_USER_TALK ) {
|
||||
return [];
|
||||
|
@ -67,10 +68,10 @@ class EchoUserLocator {
|
|||
/**
|
||||
* Return the event agent
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @return User[]
|
||||
*/
|
||||
public static function locateEventAgent( EchoEvent $event ) {
|
||||
public static function locateEventAgent( Event $event ) {
|
||||
$agent = $event->getAgent();
|
||||
if ( $agent && $agent->isRegistered() ) {
|
||||
return [ $agent->getId() => $agent ];
|
||||
|
@ -83,10 +84,10 @@ class EchoUserLocator {
|
|||
* Return the user that created the first revision of the
|
||||
* associated title.
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @return User[]
|
||||
*/
|
||||
public static function locateArticleCreator( EchoEvent $event ) {
|
||||
public static function locateArticleCreator( Event $event ) {
|
||||
$title = $event->getTitle();
|
||||
|
||||
if ( !$title || $title->getArticleID() <= 0 ) {
|
||||
|
@ -125,11 +126,11 @@ class EchoUserLocator {
|
|||
* array of user ids. It will return all these users as notification
|
||||
* targets.
|
||||
*
|
||||
* @param EchoEvent $event
|
||||
* @param Event $event
|
||||
* @param string[] $keys one or more keys to check for user ids
|
||||
* @return User[]
|
||||
*/
|
||||
public static function locateFromEventExtra( EchoEvent $event, array $keys ) {
|
||||
public static function locateFromEventExtra( Event $event, array $keys ) {
|
||||
$users = [];
|
||||
foreach ( $keys as $key ) {
|
||||
$userIds = $event->getExtraParam( $key );
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// phpcs:disable Generic.Files.LineLength -- Long html test examples
|
||||
// @phan-file-suppress PhanUndeclaredClassMethod, PhanUndeclaredClassConstant Other extensions used for testing purposes
|
||||
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
|
@ -322,7 +323,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
|
||||
private function generateWelcome( User $user ) {
|
||||
$this->output( "Welcoming {$user->getName()}\n" );
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'welcome',
|
||||
'agent' => $user,
|
||||
'timestamp' => $this->getTimestamp(),
|
||||
|
@ -332,7 +333,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
private function generateEmail( User $user, User $agent ) {
|
||||
$output = $this->addTimestampToOutput( "{$agent->getName()} is emailing {$user->getName()}" );
|
||||
$this->output( "$output\n" );
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'emailuser',
|
||||
'extra' => [
|
||||
'to-user-id' => $user->getId(),
|
||||
|
@ -352,7 +353,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
}
|
||||
|
||||
private function createUserRightsNotification( User $user, User $agent, $add, $remove ) {
|
||||
EchoEvent::create(
|
||||
Event::create(
|
||||
[
|
||||
'type' => 'user-rights',
|
||||
'extra' => [
|
||||
|
@ -374,7 +375,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
|
||||
$this->output( "Generating CX notifications\n" );
|
||||
foreach ( [ 'cx-first-translation', 'cx-tenth-translation', 'cx-hundredth-translation' ] as $eventType ) {
|
||||
EchoEvent::create(
|
||||
Event::create(
|
||||
[
|
||||
'type' => $eventType,
|
||||
'extra' => [
|
||||
|
@ -385,7 +386,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
);
|
||||
}
|
||||
|
||||
EchoEvent::create(
|
||||
Event::create(
|
||||
[
|
||||
'type' => 'cx-suggestions-available',
|
||||
'extra' => [
|
||||
|
@ -428,7 +429,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
$this->output( "Generating OpenStackManager notifications\n" );
|
||||
|
||||
foreach ( [ 'build-completed', 'reboot-completed', 'deleted' ] as $action ) {
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => "osm-instance-$action",
|
||||
'title' => Title::newFromText( "Moai" ),
|
||||
'agent' => $user,
|
||||
|
@ -441,7 +442,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
] );
|
||||
}
|
||||
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'osm-projectmembers-add',
|
||||
'title' => Title::newFromText( "Moai" ),
|
||||
'agent' => $agent,
|
||||
|
@ -466,7 +467,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
// make an edit, thank it once
|
||||
$title = $this->generateNewPageTitle();
|
||||
$revisionRecord = $this->addToPageContent( $title, $user, "an awesome edit! ~~~~" );
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'edit-thank',
|
||||
'title' => $title,
|
||||
'extra' => [
|
||||
|
@ -488,7 +489,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
// make an edit, thank it twice
|
||||
$title = $this->generateNewPageTitle();
|
||||
$revisionRecord = $this->addToPageContent( $title, $user, "an even better edit! ~~~~" );
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'edit-thank',
|
||||
'title' => $title,
|
||||
'extra' => [
|
||||
|
@ -499,7 +500,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
'agent' => $agent,
|
||||
'timestamp' => $this->getTimestamp(),
|
||||
] );
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'edit-thank',
|
||||
'title' => $title,
|
||||
'extra' => [
|
||||
|
@ -564,7 +565,7 @@ class GenerateSampleNotifications extends Maintenance {
|
|||
|
||||
$output = $this->addTimestampToOutput( "{$agent->getName()} is connecting {$user->getName()}'s page {$title->getPrefixedText()} to an item" );
|
||||
$this->output( "$output\n" );
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => EchoNotificationsHandlers::NOTIFICATION_TYPE,
|
||||
'title' => $title,
|
||||
'extra' => [
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\User\UserOptionsLookup;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
||||
|
@ -83,7 +84,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
] );
|
||||
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getType' )
|
||||
->willReturn( 'unit-test' );
|
||||
|
||||
|
@ -97,7 +98,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
public function testEvaluateUserLocatorPassesParameters() {
|
||||
$callback = function ( $event, $firstOption, $secondOption ) {
|
||||
$this->assertInstanceOf( EchoEvent::class, $event );
|
||||
$this->assertInstanceOf( Event::class, $event );
|
||||
$this->assertEquals( 'first', $firstOption );
|
||||
$this->assertEquals( 'second', $secondOption );
|
||||
|
||||
|
@ -157,7 +158,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
],
|
||||
] );
|
||||
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getType' )
|
||||
->willReturn( 'unit-test' );
|
||||
|
||||
|
@ -170,7 +171,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
public function testDoesNotDeliverDisabledEvent() {
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'isEnabledEvent' )
|
||||
->willReturn( false );
|
||||
// Assume it would have to check the event type to
|
||||
|
@ -257,7 +258,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
public function testEnqueueEvent() {
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getExtraParam' )
|
||||
->willReturn( null );
|
||||
$event->expects( $this->once() )
|
||||
|
@ -280,7 +281,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
$queueGroup = $this->getServiceContainer()->getJobQueueGroup();
|
||||
$this->assertCount( 0, $queueGroup->getQueuesWithJobs() );
|
||||
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getExtraParam' )
|
||||
->will( $this->returnValueMap(
|
||||
[
|
||||
|
@ -303,7 +304,7 @@ class NotificationControllerTest extends MediaWikiIntegrationTestCase {
|
|||
$rootJobTimestamp = wfTimestamp();
|
||||
MWTimestamp::setFakeTime( 0 );
|
||||
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getExtraParam' )
|
||||
->will( $this->returnValueMap(
|
||||
[
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
// phpcs:disable Generic.Files.LineLength -- Long html test examples
|
||||
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\MutableRevisionRecord;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
|
@ -208,7 +209,7 @@ class EchoDiscussionParserTest extends MediaWikiIntegrationTestCase {
|
|||
'agent' => 'Cwobeel',
|
||||
'section-title' => 'Grand jury no bill reception',
|
||||
/*
|
||||
* I wish I could also compare EchoEvent::$extra data to
|
||||
* I wish I could also compare Event::$extra data to
|
||||
* compare user ids of mentioned users. However, due to
|
||||
* How PHPUnit works, setUp won't be run by the time
|
||||
* this dataset is generated, so we don't yet know the
|
||||
|
@ -389,7 +390,7 @@ class EchoDiscussionParserTest extends MediaWikiIntegrationTestCase {
|
|||
);
|
||||
$events = [];
|
||||
$this->setupEventCallbackForEventGeneration(
|
||||
static function ( EchoEvent $event ) use ( &$events ) {
|
||||
static function ( Event $event ) use ( &$events ) {
|
||||
$events[] = [
|
||||
'type' => $event->getType(),
|
||||
'agent' => $event->getAgent()->getName(),
|
||||
|
@ -707,7 +708,7 @@ class EchoDiscussionParserTest extends MediaWikiIntegrationTestCase {
|
|||
);
|
||||
$events = [];
|
||||
$this->setupEventCallbackForEventGeneration(
|
||||
static function ( EchoEvent $event ) use ( &$events ) {
|
||||
static function ( Event $event ) use ( &$events ) {
|
||||
$events[] = [
|
||||
'type' => $event->getType(),
|
||||
'agent' => $event->getAgent()->getName(),
|
||||
|
@ -908,7 +909,7 @@ TEXT
|
|||
|
||||
$events = [];
|
||||
$this->setupEventCallbackForEventGeneration(
|
||||
static function ( EchoEvent $event ) use ( &$events ) {
|
||||
static function ( Event $event ) use ( &$events ) {
|
||||
$events[] = [
|
||||
'type' => $event->getType(),
|
||||
'agent' => $event->getAgent()->getName(),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
|
||||
/**
|
||||
* @covers \MediaWiki\Extension\Notifications\Formatters\EchoPresentationModelSection
|
||||
|
@ -72,7 +73,7 @@ class EchoPresentationModelSectionTest extends MediaWikiIntegrationTestCase {
|
|||
|
||||
private function makeEvent( $config = [] ) {
|
||||
$agent = $this->getTestSysop()->getUser();
|
||||
return EchoEvent::newFromRow( (object)array_merge( [
|
||||
return Event::newFromRow( (object)array_merge( [
|
||||
'event_id' => 12,
|
||||
'event_type' => 'welcome',
|
||||
'event_variant' => '1',
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +36,7 @@ class EventMapperTest extends MediaWikiIntegrationTestCase {
|
|||
* @dataProvider provideDataTestInsert
|
||||
*/
|
||||
public function testInsert( $message, $dbResult, $result ) {
|
||||
$event = $this->mockEchoEvent();
|
||||
$event = $this->mockEvent();
|
||||
$eventMapper = new EventMapper( $this->mockMWEchoDbFactory( $dbResult ) );
|
||||
$this->assertEquals( $result, $eventMapper->insert( $event ), $message );
|
||||
}
|
||||
|
@ -61,7 +62,7 @@ class EventMapperTest extends MediaWikiIntegrationTestCase {
|
|||
)
|
||||
);
|
||||
$res = $eventMapper->fetchById( 1 );
|
||||
$this->assertInstanceOf( EchoEvent::class, $res );
|
||||
$this->assertInstanceOf( Event::class, $res );
|
||||
}
|
||||
|
||||
public function testUnsuccessfulFetchById() {
|
||||
|
@ -77,10 +78,10 @@ class EventMapperTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return EchoEvent
|
||||
* @return Event
|
||||
*/
|
||||
protected function mockEchoEvent() {
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
protected function mockEvent() {
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'toDbArray' )
|
||||
->willReturn( [] );
|
||||
|
||||
|
@ -128,20 +129,20 @@ class EventMapperTest extends MediaWikiIntegrationTestCase {
|
|||
$page = $this->getExistingTestPage();
|
||||
|
||||
// Create a notification that is not associated with any page
|
||||
EchoEvent::create( [
|
||||
Event::create( [
|
||||
'type' => 'welcome',
|
||||
'agent' => $user,
|
||||
] );
|
||||
|
||||
// Create a notification with a title
|
||||
$eventWithTitle = EchoEvent::create( [
|
||||
$eventWithTitle = Event::create( [
|
||||
'type' => 'welcome',
|
||||
'agent' => $user,
|
||||
'title' => $page->getTitle()
|
||||
] );
|
||||
|
||||
// Create a notification with a target-page
|
||||
$eventWithTargetPage = EchoEvent::create( [
|
||||
$eventWithTargetPage = Event::create( [
|
||||
'type' => 'welcome',
|
||||
'agent' => $user,
|
||||
'extra' => [ 'target-page' => $page->getId() ]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
||||
/**
|
||||
|
@ -46,7 +47,7 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertIsArray( $res );
|
||||
$this->assertNotEmpty( $res );
|
||||
foreach ( $res as $row ) {
|
||||
$this->assertInstanceOf( EchoNotification::class, $row );
|
||||
$this->assertInstanceOf( Notification::class, $row );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +93,7 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertIsArray( $res );
|
||||
$this->assertNotEmpty( $res );
|
||||
foreach ( $res as $row ) {
|
||||
$this->assertInstanceOf( EchoNotification::class, $row );
|
||||
$this->assertInstanceOf( Notification::class, $row );
|
||||
}
|
||||
|
||||
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [] ) );
|
||||
|
@ -123,7 +124,7 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase {
|
|||
];
|
||||
$notifMapper = new NotificationMapper( $this->mockMWEchoDbFactory( [ 'selectRow' => $dbResult ] ) );
|
||||
$row = $notifMapper->fetchByUserOffset( User::newFromId( 1 ), 500 );
|
||||
$this->assertInstanceOf( EchoNotification::class, $row );
|
||||
$this->assertInstanceOf( Notification::class, $row );
|
||||
}
|
||||
|
||||
public function testDeleteByUserEventOffset() {
|
||||
|
@ -207,11 +208,11 @@ class NotificationMapperTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Mock object of EchoNotification
|
||||
* @return EchoNotification
|
||||
* Mock object of Notification
|
||||
* @return Notification
|
||||
*/
|
||||
protected function mockEchoNotification() {
|
||||
$event = $this->createMock( EchoNotification::class );
|
||||
protected function mockNotification() {
|
||||
$event = $this->createMock( Notification::class );
|
||||
$event->method( 'toDbArray' )
|
||||
->willReturn( [] );
|
||||
|
||||
|
|
|
@ -1,39 +1,43 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
use MediaWiki\Extension\Notifications\Model\TargetPage;
|
||||
|
||||
/**
|
||||
* @covers \EchoNotification
|
||||
* @covers \MediaWiki\Extension\Notifications\Model\Notification
|
||||
*/
|
||||
class EchoNotificationTest extends MediaWikiIntegrationTestCase {
|
||||
class NotificationTest extends MediaWikiIntegrationTestCase {
|
||||
|
||||
public function testNewFromRow() {
|
||||
$row = $this->mockNotificationRow() + $this->mockEventRow();
|
||||
|
||||
$notif = EchoNotification::newFromRow( (object)$row );
|
||||
$this->assertInstanceOf( EchoNotification::class, $notif );
|
||||
$notif = Notification::newFromRow( (object)$row );
|
||||
$this->assertInstanceOf( Notification::class, $notif );
|
||||
// getReadTimestamp() should return null
|
||||
$this->assertNull( $notif->getReadTimestamp() );
|
||||
$this->assertEquals(
|
||||
$notif->getTimestamp(),
|
||||
wfTimestamp( TS_MW, $row['notification_timestamp'] )
|
||||
);
|
||||
$this->assertInstanceOf( EchoEvent::class, $notif->getEvent() );
|
||||
$this->assertInstanceOf( Event::class, $notif->getEvent() );
|
||||
$this->assertNull( $notif->getTargetPages() );
|
||||
|
||||
// Provide a read timestamp
|
||||
$row['notification_read_timestamp'] = time() + 1000;
|
||||
$notif = EchoNotification::newFromRow( (object)$row );
|
||||
$notif = Notification::newFromRow( (object)$row );
|
||||
// getReadTimestamp() should return the timestamp in MW format
|
||||
$this->assertEquals(
|
||||
$notif->getReadTimestamp(),
|
||||
wfTimestamp( TS_MW, $row['notification_read_timestamp'] )
|
||||
);
|
||||
|
||||
$notif = EchoNotification::newFromRow( (object)$row, [
|
||||
EchoTargetPage::newFromRow( (object)$this->mockTargetPageRow() )
|
||||
$notif = Notification::newFromRow( (object)$row, [
|
||||
TargetPage::newFromRow( (object)$this->mockTargetPageRow() )
|
||||
] );
|
||||
$this->assertNotEmpty( $notif->getTargetPages() );
|
||||
foreach ( $notif->getTargetPages() as $targetPage ) {
|
||||
$this->assertInstanceOf( EchoTargetPage::class, $targetPage );
|
||||
$this->assertInstanceOf( TargetPage::class, $targetPage );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +46,7 @@ class EchoNotificationTest extends MediaWikiIntegrationTestCase {
|
|||
// Provide an invalid event id
|
||||
$row['notification_event'] = -1;
|
||||
$this->expectException( MWException::class );
|
||||
EchoNotification::newFromRow( (object)$row );
|
||||
Notification::newFromRow( (object)$row );
|
||||
}
|
||||
|
||||
/**
|
|
@ -3,6 +3,8 @@
|
|||
use MediaWiki\Extension\Notifications\Gateway\UserNotificationGateway;
|
||||
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\MediaWikiServices;
|
||||
use MediaWiki\User\UserOptionsLookup;
|
||||
|
||||
|
@ -85,7 +87,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
User::newFromId( 2 ),
|
||||
$this->cache,
|
||||
$this->mockUserNotificationGateway( [ 'markRead' => true ] ),
|
||||
$this->mockNotificationMapper( [ $this->mockEchoNotification() ] ),
|
||||
$this->mockNotificationMapper( [ $this->mockNotification() ] ),
|
||||
$this->createMock( TargetPageMapper::class ),
|
||||
$this->createNoOpMock( UserOptionsLookup::class ),
|
||||
$this->getServiceContainer()->getUserFactory(),
|
||||
|
@ -98,7 +100,7 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
User::newFromId( 2 ),
|
||||
$this->cache,
|
||||
$this->mockUserNotificationGateway( [ 'markRead' => false ] ),
|
||||
$this->mockNotificationMapper( [ $this->mockEchoNotification() ] ),
|
||||
$this->mockNotificationMapper( [ $this->mockNotification() ] ),
|
||||
$this->createMock( TargetPageMapper::class ),
|
||||
$this->createNoOpMock( UserOptionsLookup::class ),
|
||||
$this->getServiceContainer()->getUserFactory(),
|
||||
|
@ -154,16 +156,16 @@ class MWEchoNotifUserTest extends MediaWikiIntegrationTestCase {
|
|||
return $mapper;
|
||||
}
|
||||
|
||||
protected function mockEchoNotification() {
|
||||
$notification = $this->createMock( EchoNotification::class );
|
||||
protected function mockNotification() {
|
||||
$notification = $this->createMock( Notification::class );
|
||||
$notification->method( 'getEvent' )
|
||||
->willReturn( $this->mockEchoEvent() );
|
||||
->willReturn( $this->mockEvent() );
|
||||
|
||||
return $notification;
|
||||
}
|
||||
|
||||
protected function mockEchoEvent() {
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
protected function mockEvent() {
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getId' )
|
||||
->willReturn( 1 );
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Mapper\NotificationMapper;
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
|
||||
/**
|
||||
* Tests for the built in notification types
|
||||
|
@ -20,7 +21,7 @@ class NotificationsTest extends MediaWikiIntegrationTestCase {
|
|||
/**
|
||||
* Helper function to get a user's latest notification
|
||||
* @param User $user
|
||||
* @return EchoEvent
|
||||
* @return Event
|
||||
*/
|
||||
public static function getLatestNotification( $user ) {
|
||||
$notifMapper = new NotificationMapper();
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
|
||||
/**
|
||||
* @group Echo
|
||||
* @group Database
|
||||
|
@ -89,7 +91,7 @@ class EchoTalkPageFunctionalTest extends ApiTestCase {
|
|||
* @return \stdClass[] All talk page edit events in db sorted from oldest to newest
|
||||
*/
|
||||
protected function fetchAllEvents() {
|
||||
$res = $this->db->select( 'echo_event', EchoEvent::selectFields(), [
|
||||
$res = $this->db->select( 'echo_event', Event::selectFields(), [
|
||||
'event_type' => 'edit-user-talk',
|
||||
], __METHOD__, [ 'ORDER BY' => 'event_id ASC' ] );
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class MWEchoThankYouEditTest extends MediaWikiIntegrationTestCase {
|
|||
$notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] );
|
||||
$this->assertCount( 1, $notifications );
|
||||
|
||||
/** @var EchoNotification $notification */
|
||||
/** @var Notification $notification */
|
||||
$notification = reset( $notifications );
|
||||
$this->assertSame( 1, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) );
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ class MWEchoThankYouEditTest extends MediaWikiIntegrationTestCase {
|
|||
$notifications = $notificationMapper->fetchByUser( $user, 10, null, [ 'thank-you-edit' ] );
|
||||
$this->assertCount( 2, $notifications );
|
||||
|
||||
/** @var EchoNotification $notification */
|
||||
/** @var Notification $notification */
|
||||
$notification = reset( $notifications );
|
||||
$this->assertSame( 10, $notification->getEvent()->getExtraParam( 'editCount', 'not found' ) );
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
|
||||
/**
|
||||
* @group Database
|
||||
* @covers \EchoUserLocator
|
||||
|
@ -22,7 +24,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
}
|
||||
wfGetDB( DB_PRIMARY )->insert( 'watchlist', $rows, __METHOD__ );
|
||||
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getTitle' )
|
||||
->willReturn( $title );
|
||||
|
||||
|
@ -73,7 +75,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
if ( $expect instanceof Closure ) {
|
||||
[ $expect, $title ] = $expect();
|
||||
}
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getTitle' )
|
||||
->willReturn( $title );
|
||||
|
||||
|
@ -110,7 +112,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
/* $summary = */ 'summary'
|
||||
);
|
||||
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getTitle' )
|
||||
->willReturn( $title );
|
||||
$event->method( 'getAgent' )
|
||||
|
@ -152,7 +154,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
* @dataProvider locateEventAgentProvider
|
||||
*/
|
||||
public function testLocateEventAgent( $message, $expect, User $agent = null ) {
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getAgent' )
|
||||
->willReturn( $agent );
|
||||
|
||||
|
@ -229,7 +231,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
* @dataProvider locateFromEventExtraProvider
|
||||
*/
|
||||
public function testLocateFromEventExtra( $message, $expect, array $extra, array $keys ) {
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getExtra' )
|
||||
->willReturn( $extra );
|
||||
$event->method( 'getExtraParam' )
|
||||
|
@ -242,7 +244,7 @@ class EchoUserLocatorTest extends MediaWikiIntegrationTestCase {
|
|||
protected static function arrayToValueMap( array $array ) {
|
||||
$result = [];
|
||||
foreach ( $array as $key => $value ) {
|
||||
// EchoEvent::getExtraParam second argument defaults to null
|
||||
// Event::getExtraParam second argument defaults to null
|
||||
$result[] = [ $key, null, $value ];
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Model\Notification;
|
||||
|
||||
/**
|
||||
* @covers \Bundler
|
||||
*/
|
||||
|
@ -28,7 +30,7 @@ class BundlerTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
private function createNotificationForBundling( $bundleHash, $timestamp, $readStatus ) {
|
||||
$mock = $this->getMockBuilder( EchoNotification::class )
|
||||
$mock = $this->getMockBuilder( Notification::class )
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods( [
|
||||
'getBundlingKey',
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
|
||||
use MediaWiki\Extension\Notifications\Model\TargetPage;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
|
||||
/**
|
||||
|
@ -27,17 +28,17 @@ class TargetPageMapperTest extends MediaWikiUnitTestCase {
|
|||
* @dataProvider provideDataTestInsert
|
||||
*/
|
||||
public function testInsert( $message, $dbResult, $result ) {
|
||||
$target = $this->mockEchoTargetPage();
|
||||
$target = $this->mockTargetPage();
|
||||
$targetMapper = new TargetPageMapper( $this->mockMWEchoDbFactory( $dbResult ) );
|
||||
$this->assertEquals( $result, $targetMapper->insert( $target ), $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock object of EchoTargetPage
|
||||
* @return EchoTargetPage
|
||||
* Mock object of TargetPage
|
||||
* @return TargetPage
|
||||
*/
|
||||
protected function mockEchoTargetPage() {
|
||||
$target = $this->createMock( EchoTargetPage::class );
|
||||
protected function mockTargetPage() {
|
||||
$target = $this->createMock( TargetPage::class );
|
||||
$target->method( 'toDbArray' )
|
||||
->willReturn( [] );
|
||||
$target->method( 'getPageId' )
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Extension\Notifications\Model\Event;
|
||||
use MediaWiki\Extension\Notifications\Model\TargetPage;
|
||||
|
||||
/**
|
||||
* @covers \EchoTargetPage
|
||||
* @covers \MediaWiki\Extension\Notifications\Model\TargetPage
|
||||
*/
|
||||
class EchoTargetPageTest extends MediaWikiUnitTestCase {
|
||||
class TargetPageTest extends MediaWikiUnitTestCase {
|
||||
|
||||
public function testCreate() {
|
||||
$this->assertNull(
|
||||
EchoTargetPage::create(
|
||||
TargetPage::create(
|
||||
$this->mockTitle( 0 ),
|
||||
$this->mockEchoEvent()
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
EchoTargetPage::class,
|
||||
EchoTargetPage::create(
|
||||
TargetPage::class,
|
||||
TargetPage::create(
|
||||
$this->mockTitle( 1 ),
|
||||
$this->mockEchoEvent()
|
||||
)
|
||||
|
@ -23,15 +26,15 @@ class EchoTargetPageTest extends MediaWikiUnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return EchoTargetPage
|
||||
* @return TargetPage
|
||||
*/
|
||||
public function testNewFromRow() {
|
||||
$row = (object)[
|
||||
'etp_page' => 2,
|
||||
'etp_event' => 3
|
||||
];
|
||||
$obj = EchoTargetPage::newFromRow( $row );
|
||||
$this->assertInstanceOf( EchoTargetPage::class, $obj );
|
||||
$obj = TargetPage::newFromRow( $row );
|
||||
$this->assertInstanceOf( TargetPage::class, $obj );
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
@ -41,13 +44,13 @@ class EchoTargetPageTest extends MediaWikiUnitTestCase {
|
|||
'etp_event' => 3
|
||||
];
|
||||
$this->expectException( MWException::class );
|
||||
EchoTargetPage::newFromRow( $row );
|
||||
TargetPage::newFromRow( $row );
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testNewFromRow
|
||||
*/
|
||||
public function testToDbArray( EchoTargetPage $obj ) {
|
||||
public function testToDbArray( TargetPage $obj ) {
|
||||
$row = $obj->toDbArray();
|
||||
$this->assertIsArray( $row );
|
||||
|
||||
|
@ -73,10 +76,10 @@ class EchoTargetPageTest extends MediaWikiUnitTestCase {
|
|||
|
||||
/**
|
||||
* @param int $eventId
|
||||
* @return EchoEvent
|
||||
* @return Event
|
||||
*/
|
||||
protected function mockEchoEvent( $eventId = 1 ) {
|
||||
$event = $this->createMock( EchoEvent::class );
|
||||
$event = $this->createMock( Event::class );
|
||||
$event->method( 'getId' )
|
||||
->willReturn( $eventId );
|
||||
|
Loading…
Reference in a new issue