2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
namespace MediaWiki\Extension\Notifications\Model;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
use InvalidArgumentException;
|
2022-11-13 06:43:40 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Bundleable;
|
2022-11-02 03:51:15 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Controller\NotificationController;
|
2022-11-12 07:19:00 +00:00
|
|
|
use MediaWiki\Extension\Notifications\DbFactory;
|
2023-06-06 21:02:02 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Hooks\HookRunner;
|
2022-11-02 20:47:04 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Mapper\EventMapper;
|
|
|
|
use MediaWiki\Extension\Notifications\Mapper\TargetPageMapper;
|
2022-11-13 07:53:42 +00:00
|
|
|
use MediaWiki\Extension\Notifications\Services;
|
2017-03-30 19:35:32 +00:00
|
|
|
use MediaWiki\Logger\LoggerFactory;
|
2019-04-17 15:46:06 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2020-01-14 05:09:42 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2023-08-19 04:14:59 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2024-08-25 12:07:20 +00:00
|
|
|
use MediaWiki\User\ActorStore;
|
2023-12-11 15:33:08 +00:00
|
|
|
use MediaWiki\User\User;
|
2021-02-18 21:45:19 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2023-06-07 17:46:16 +00:00
|
|
|
use RuntimeException;
|
2022-11-02 21:34:17 +00:00
|
|
|
use stdClass;
|
2024-08-25 12:07:20 +00:00
|
|
|
use Wikimedia\IPUtils;
|
2024-10-19 22:55:03 +00:00
|
|
|
use Wikimedia\Rdbms\IDBAccessObject;
|
2017-03-30 19:35:32 +00:00
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
/**
|
|
|
|
* Immutable class to represent an event.
|
|
|
|
* In Echo nomenclature, an event is a single occurrence.
|
|
|
|
*/
|
2022-11-02 21:34:17 +00:00
|
|
|
class Event extends AbstractEntity implements Bundleable {
|
2014-08-14 18:46:26 +00:00
|
|
|
|
2019-02-15 20:23:02 +00:00
|
|
|
/** @var string|null */
|
2013-03-04 20:56:42 +00:00
|
|
|
protected $type = null;
|
2019-12-21 05:45:14 +00:00
|
|
|
/** @var int|null|false */
|
2012-04-27 15:14:24 +00:00
|
|
|
protected $id = null;
|
2019-02-15 20:23:02 +00:00
|
|
|
/** @var string|null */
|
2012-04-27 15:14:24 +00:00
|
|
|
protected $variant = null;
|
2012-09-02 09:30:38 +00:00
|
|
|
/**
|
2019-02-15 20:23:02 +00:00
|
|
|
* @var User|null
|
2012-09-02 09:30:38 +00:00
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
protected $agent = null;
|
2012-05-17 00:29:37 +00:00
|
|
|
|
|
|
|
/**
|
2013-05-08 18:11:44 +00:00
|
|
|
* Loaded dynamically on request
|
|
|
|
*
|
2019-02-15 20:23:02 +00:00
|
|
|
* @var Title|null
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
protected $title = null;
|
2019-02-15 20:23:02 +00:00
|
|
|
/** @var int|null */
|
2013-05-08 18:11:44 +00:00
|
|
|
protected $pageId = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loaded dynamically on request
|
|
|
|
*
|
2019-04-17 15:46:06 +00:00
|
|
|
* @var RevisionRecord|null
|
2013-05-08 18:11:44 +00:00
|
|
|
*/
|
|
|
|
protected $revision = null;
|
|
|
|
|
2019-02-15 20:23:02 +00:00
|
|
|
/** @var array */
|
2016-12-05 18:51:07 +00:00
|
|
|
protected $extra = [];
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification timestamp
|
2019-02-15 20:23:02 +00:00
|
|
|
* @var string|null
|
2013-01-15 23:21:39 +00:00
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
protected $timestamp = null;
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
/**
|
|
|
|
* A hash used to bundle a set of events, events that can be
|
|
|
|
* grouped for a user has the same bundle hash
|
2019-12-21 05:45:14 +00:00
|
|
|
* @var string|null
|
2013-01-15 23:21:39 +00:00
|
|
|
*/
|
|
|
|
protected $bundleHash;
|
|
|
|
|
2016-03-04 19:23:02 +00:00
|
|
|
/**
|
|
|
|
* Other events bundled with this one
|
|
|
|
*
|
2022-11-02 21:34:17 +00:00
|
|
|
* @var Event[]
|
2016-03-04 19:23:02 +00:00
|
|
|
*/
|
|
|
|
protected $bundledEvents;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletion flag
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $deleted = 0;
|
|
|
|
|
2024-09-22 09:42:51 +00:00
|
|
|
/** For use in tests */
|
|
|
|
public static bool $alwaysInsert = false;
|
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
/**
|
|
|
|
* You should not call the constructor.
|
2022-11-02 21:34:17 +00:00
|
|
|
* 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
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
2015-10-01 13:48:52 +00:00
|
|
|
protected function __construct() {
|
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
## Save the id and timestamp
|
2018-11-02 17:47:39 +00:00
|
|
|
public function __sleep() {
|
2012-08-31 21:50:46 +00:00
|
|
|
if ( !$this->id ) {
|
2023-06-07 17:46:16 +00:00
|
|
|
throw new RuntimeException( "Unable to serialize an uninitialized Event" );
|
2012-06-06 07:04:28 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2016-12-05 18:51:07 +00:00
|
|
|
return [ 'id', 'timestamp' ];
|
2012-06-06 07:04:28 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 17:47:39 +00:00
|
|
|
public function __wakeup() {
|
2012-06-06 07:04:28 +00:00
|
|
|
$this->loadFromID( $this->id );
|
|
|
|
}
|
|
|
|
|
2018-11-02 17:47:39 +00:00
|
|
|
public function __toString() {
|
2022-11-02 21:34:17 +00:00
|
|
|
return "Event(id={$this->id}; type={$this->type})";
|
2012-06-06 07:04:28 +00:00
|
|
|
}
|
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
/**
|
2022-11-02 21:34:17 +00:00
|
|
|
* Creates an Event object
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param array $info Named arguments:
|
2012-04-27 15:14:24 +00:00
|
|
|
* type (required): The event type;
|
|
|
|
* variant: A variant of the type;
|
|
|
|
* agent: The user who caused the event;
|
|
|
|
* title: The page on which the event was triggered;
|
2020-10-09 14:09:21 +00:00
|
|
|
* extra: Event-specific extra information (e.g. post content, delay time, root job params).
|
|
|
|
*
|
|
|
|
* Delayed jobs extra params:
|
|
|
|
* delay: Amount of time in seconds for the notification to be delayed
|
|
|
|
*
|
|
|
|
* Job deduplication extra params:
|
|
|
|
* rootJobSignature: The sha1 signature of the job
|
|
|
|
* rootJobTimestamp: The timestamp when the job gets submitted
|
|
|
|
*
|
|
|
|
* For example to enqueue a new `example` root job or make a parent job
|
|
|
|
* no-op when submitting a new notification you need to pass this extra params:
|
|
|
|
*
|
|
|
|
* [ 'extra' => Job::newRootJobParams('example') ]
|
2012-04-27 15:14:24 +00:00
|
|
|
*
|
2022-11-02 21:34:17 +00:00
|
|
|
* @return Event|false False if aborted via hook or Echo DB is read-only
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
2016-12-05 18:51:07 +00:00
|
|
|
public static function create( $info = [] ) {
|
2013-02-16 02:20:34 +00:00
|
|
|
global $wgEchoNotifications;
|
|
|
|
|
2023-04-27 21:12:22 +00:00
|
|
|
$services = MediaWikiServices::getInstance();
|
2013-05-08 21:24:47 +00:00
|
|
|
// Do not create event and notifications if write access is locked
|
2023-04-27 21:12:22 +00:00
|
|
|
if ( $services->getReadOnlyMode()->isReadOnly()
|
2022-11-12 07:19:00 +00:00
|
|
|
|| DbFactory::newFromDefault()->getEchoDb( DB_PRIMARY )->isReadOnly()
|
2015-11-01 10:50:44 +00:00
|
|
|
) {
|
|
|
|
return false;
|
2013-05-08 21:24:47 +00:00
|
|
|
}
|
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
$obj = new Event;
|
2016-12-05 18:51:07 +00:00
|
|
|
static $validFields = [ 'type', 'variant', 'agent', 'title', 'extra' ];
|
2012-04-27 15:14:24 +00:00
|
|
|
|
2012-08-01 19:53:05 +00:00
|
|
|
if ( empty( $info['type'] ) ) {
|
2023-06-07 17:46:16 +00:00
|
|
|
throw new InvalidArgumentException( "'type' parameter is mandatory" );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2013-02-16 02:20:34 +00:00
|
|
|
if ( !isset( $wgEchoNotifications[$info['type']] ) ) {
|
2012-08-01 18:20:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
$obj->id = false;
|
2022-06-23 09:17:10 +00:00
|
|
|
$obj->timestamp = $info['timestamp'] ?? wfTimestampNow();
|
2012-08-31 21:50:46 +00:00
|
|
|
foreach ( $validFields as $field ) {
|
2012-08-30 16:04:39 +00:00
|
|
|
if ( isset( $info[$field] ) ) {
|
2012-04-27 15:14:24 +00:00
|
|
|
$obj->$field = $info[$field];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-05 18:56:11 +00:00
|
|
|
// If the extra size is more than 50000 bytes, that means there is
|
2014-02-05 22:21:48 +00:00
|
|
|
// probably a problem with the design of this notification type.
|
|
|
|
// There might be data loss if the size exceeds the DB column size of
|
|
|
|
// event_extra.
|
2014-02-05 18:56:11 +00:00
|
|
|
if ( strlen( $obj->serializeExtra() ) > 50000 ) {
|
|
|
|
wfDebugLog( __CLASS__, __FUNCTION__ . ': event extra data is too huge for ' . $info['type'] );
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-02-05 18:56:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-05-08 18:11:44 +00:00
|
|
|
if ( $obj->title ) {
|
|
|
|
if ( !$obj->title instanceof Title ) {
|
2017-10-03 22:39:23 +00:00
|
|
|
throw new InvalidArgumentException( 'Invalid title parameter' );
|
2013-05-08 18:11:44 +00:00
|
|
|
}
|
2013-11-30 06:20:03 +00:00
|
|
|
$obj->setTitle( $obj->title );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2021-02-18 21:45:19 +00:00
|
|
|
if ( $obj->agent ) {
|
|
|
|
if ( !$obj->agent instanceof UserIdentity ) {
|
|
|
|
throw new InvalidArgumentException( "Invalid user parameter" );
|
|
|
|
}
|
|
|
|
|
2024-08-25 12:07:20 +00:00
|
|
|
// TODO: when no errors are logged in production, turn this into an exception
|
|
|
|
if ( !$obj->agent->isRegistered() && !IPUtils::isValid( $obj->agent->getName() ) ) {
|
|
|
|
LoggerFactory::getInstance( 'Echo' )->error(
|
|
|
|
'Invalid IP agent: {username} for event type {event_type}',
|
|
|
|
[
|
|
|
|
'username' => $obj->agent->getName(),
|
|
|
|
'event_type' => $obj->type,
|
|
|
|
'exception' => new \RuntimeException,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-02-18 21:45:19 +00:00
|
|
|
// RevisionStore returns UserIdentityValue now, convert to User for passing to hooks.
|
|
|
|
if ( !$obj->agent instanceof User ) {
|
2023-04-27 21:12:22 +00:00
|
|
|
$obj->agent = $services->getUserFactory()->newFromUserIdentity( $obj->agent );
|
2021-02-18 21:45:19 +00:00
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 21:02:02 +00:00
|
|
|
$hookRunner = new HookRunner( $services->getHookContainer() );
|
|
|
|
if ( !$hookRunner->onBeforeEchoEventInsert( $obj ) ) {
|
2013-09-28 02:19:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-29 11:23:31 +00:00
|
|
|
// @Todo - Database insert logic should not be inside the model
|
2024-09-22 09:42:51 +00:00
|
|
|
if ( self::$alwaysInsert ) {
|
|
|
|
$obj->insert();
|
|
|
|
}
|
2013-09-28 02:19:08 +00:00
|
|
|
|
2012-12-19 20:28:17 +00:00
|
|
|
global $wgEchoUseJobQueue;
|
|
|
|
|
2022-11-02 03:51:15 +00:00
|
|
|
NotificationController::notify( $obj, $wgEchoUseJobQueue );
|
2012-04-27 15:14:24 +00:00
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
2014-07-18 03:58:21 +00:00
|
|
|
/**
|
|
|
|
* Convert the object's database property to array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toDbArray() {
|
2016-12-05 18:51:07 +00:00
|
|
|
$data = [
|
2014-07-18 03:58:21 +00:00
|
|
|
'event_type' => $this->type,
|
|
|
|
'event_variant' => $this->variant,
|
2016-03-04 19:23:02 +00:00
|
|
|
'event_deleted' => $this->deleted,
|
2014-07-18 03:58:21 +00:00
|
|
|
'event_extra' => $this->serializeExtra()
|
2016-12-05 18:51:07 +00:00
|
|
|
];
|
2014-07-18 03:58:21 +00:00
|
|
|
if ( $this->id ) {
|
|
|
|
$data['event_id'] = $this->id;
|
|
|
|
}
|
|
|
|
if ( $this->agent ) {
|
2020-12-22 15:36:58 +00:00
|
|
|
if ( !$this->agent->isRegistered() ) {
|
2014-07-18 03:58:21 +00:00
|
|
|
$data['event_agent_ip'] = $this->agent->getName();
|
|
|
|
} else {
|
|
|
|
$data['event_agent_id'] = $this->agent->getId();
|
|
|
|
}
|
|
|
|
}
|
2014-08-16 00:24:11 +00:00
|
|
|
|
|
|
|
if ( $this->pageId ) {
|
|
|
|
$data['event_page_id'] = $this->pageId;
|
|
|
|
} elseif ( $this->title ) {
|
2019-04-17 15:46:06 +00:00
|
|
|
$pageId = $this->title->getArticleID();
|
2014-07-18 03:58:21 +00:00
|
|
|
// Don't need any special handling for title with no id
|
|
|
|
// as they are already stored in extra data array
|
|
|
|
if ( $pageId ) {
|
|
|
|
$data['event_page_id'] = $pageId;
|
|
|
|
}
|
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2014-07-18 03:58:21 +00:00
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2024-09-22 09:42:51 +00:00
|
|
|
/**
|
|
|
|
* Creates an Event from an array. The array should be output from ::toDbArray().
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public static function newFromArray( $data ) {
|
|
|
|
$obj = new self();
|
|
|
|
if ( isset( $data['event_id'] ) ) {
|
|
|
|
$obj->id = $data['event_id'];
|
|
|
|
}
|
|
|
|
$obj->type = $data['event_type'];
|
|
|
|
$obj->variant = $data['event_variant'];
|
|
|
|
$obj->extra = $data['event_extra'] ? unserialize( $data['event_extra'] ) : [];
|
|
|
|
if ( isset( $data['event_page_id'] ) ) {
|
|
|
|
$obj->pageId = $data['event_page_id'];
|
|
|
|
}
|
|
|
|
$obj->deleted = $data['event_deleted'];
|
|
|
|
|
|
|
|
if ( $data['event_agent_id'] ?? 0 ) {
|
|
|
|
$obj->agent = User::newFromId( $data['event_agent_id'] );
|
|
|
|
} elseif ( isset( $data['event_agent_ip'] ) ) {
|
|
|
|
$obj->agent = User::newFromName( $data['event_agent_ip'], false );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $obj;
|
|
|
|
}
|
|
|
|
|
2012-11-13 23:06:11 +00:00
|
|
|
/**
|
|
|
|
* Check whether the echo event is an enabled event
|
|
|
|
* @return bool
|
|
|
|
*/
|
2022-06-23 09:17:10 +00:00
|
|
|
public function isEnabledEvent(): bool {
|
2013-02-16 02:20:34 +00:00
|
|
|
global $wgEchoNotifications;
|
2022-06-23 09:17:10 +00:00
|
|
|
return isset( $wgEchoNotifications[$this->getType()] );
|
2012-11-13 23:06:11 +00:00
|
|
|
}
|
|
|
|
|
2024-09-22 09:42:51 +00:00
|
|
|
/**
|
|
|
|
* Insert this event into the database if it hasn't been yet, and return its id.
|
|
|
|
* Subsequent calls on this instance will not cause repeated insertion
|
|
|
|
* and will always return the same id.
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function acquireId() {
|
|
|
|
if ( !$this->id ) {
|
|
|
|
$this->insert();
|
|
|
|
}
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
/**
|
|
|
|
* Inserts the object into the database.
|
|
|
|
*/
|
|
|
|
protected function insert() {
|
2022-11-02 20:47:04 +00:00
|
|
|
$eventMapper = new EventMapper();
|
2014-07-18 03:58:21 +00:00
|
|
|
$this->id = $eventMapper->insert( $this );
|
2016-09-07 17:38:12 +00:00
|
|
|
|
|
|
|
$targetPages = self::resolveTargetPages( $this->getExtraParam( 'target-page' ) );
|
|
|
|
if ( $targetPages ) {
|
2022-11-02 20:47:04 +00:00
|
|
|
$targetMapper = new TargetPageMapper();
|
2016-09-12 18:36:23 +00:00
|
|
|
foreach ( $targetPages as $title ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
$targetPage = TargetPage::create( $title, $this );
|
2016-09-12 18:36:23 +00:00
|
|
|
if ( $targetPage ) {
|
|
|
|
$targetMapper->insert( $targetPage );
|
2016-09-07 17:38:12 +00:00
|
|
|
}
|
2016-09-12 18:36:23 +00:00
|
|
|
}
|
2016-09-07 17:38:12 +00:00
|
|
|
}
|
2024-09-22 09:42:51 +00:00
|
|
|
|
|
|
|
$services = MediaWikiServices::getInstance();
|
|
|
|
$hookRunner = new HookRunner( $services->getHookContainer() );
|
|
|
|
$hookRunner->onEventInsertComplete( $this );
|
|
|
|
|
|
|
|
$stats = $services->getStatsdDataFactory();
|
|
|
|
$type = $this->getType();
|
|
|
|
$stats->increment( 'echo.event.all' );
|
|
|
|
$stats->increment( "echo.event.$type" );
|
2016-09-07 17:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int[]|int|false $targetPageIds
|
|
|
|
* @return Title[]
|
|
|
|
*/
|
|
|
|
protected static function resolveTargetPages( $targetPageIds ) {
|
|
|
|
if ( !$targetPageIds ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
return [];
|
2016-09-07 17:38:12 +00:00
|
|
|
}
|
|
|
|
if ( !is_array( $targetPageIds ) ) {
|
2016-12-05 18:51:07 +00:00
|
|
|
$targetPageIds = [ $targetPageIds ];
|
2016-09-07 17:38:12 +00:00
|
|
|
}
|
2016-12-05 18:51:07 +00:00
|
|
|
$result = [];
|
2016-09-07 17:38:12 +00:00
|
|
|
foreach ( $targetPageIds as $targetPageId ) {
|
|
|
|
// Make sure the target-page id is a valid id
|
|
|
|
$title = Title::newFromID( $targetPageId );
|
2021-05-13 00:04:54 +00:00
|
|
|
// Try primary database if there is no match
|
2016-09-07 17:38:12 +00:00
|
|
|
if ( !$title ) {
|
2024-01-26 18:23:23 +00:00
|
|
|
$title = Title::newFromID( $targetPageId, IDBAccessObject::READ_LATEST );
|
2016-09-07 17:38:12 +00:00
|
|
|
}
|
|
|
|
if ( $title ) {
|
|
|
|
$result[] = $title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-06 07:04:28 +00:00
|
|
|
* Loads data from the provided $row into this object.
|
2012-04-27 15:14:24 +00:00
|
|
|
*
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param stdClass $row row object from echo_event
|
2016-05-13 23:39:17 +00:00
|
|
|
* @return bool Whether loading was successful
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
2012-08-30 16:04:39 +00:00
|
|
|
public function loadFromRow( $row ) {
|
2019-04-10 20:09:40 +00:00
|
|
|
$this->id = (int)$row->event_id;
|
2012-06-06 07:04:28 +00:00
|
|
|
$this->type = $row->event_type;
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
// If the object is loaded from __sleep(), timestamp should be already set
|
|
|
|
if ( !$this->timestamp ) {
|
|
|
|
if ( isset( $row->notification_timestamp ) ) {
|
2013-08-22 21:51:01 +00:00
|
|
|
$this->timestamp = wfTimestamp( TS_MW, $row->notification_timestamp );
|
2013-01-15 23:21:39 +00:00
|
|
|
} else {
|
|
|
|
$this->timestamp = wfTimestampNow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-06 07:04:28 +00:00
|
|
|
$this->variant = $row->event_variant;
|
2016-05-13 23:39:17 +00:00
|
|
|
try {
|
2016-12-05 18:51:07 +00:00
|
|
|
$this->extra = $row->event_extra ? unserialize( $row->event_extra ) : [];
|
2016-05-13 23:39:17 +00:00
|
|
|
} catch ( Exception $e ) {
|
|
|
|
// T73489: unserializing can fail for old notifications
|
2017-03-01 21:02:59 +00:00
|
|
|
LoggerFactory::getInstance( 'Echo' )->warning(
|
|
|
|
'Failed to unserialize event {id}',
|
|
|
|
[
|
|
|
|
'id' => $row->event_id
|
|
|
|
]
|
|
|
|
);
|
2016-05-13 23:39:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-05-08 18:11:44 +00:00
|
|
|
$this->pageId = $row->event_page_id;
|
2016-03-04 19:23:02 +00:00
|
|
|
$this->deleted = $row->event_deleted;
|
2012-04-27 15:14:24 +00:00
|
|
|
|
|
|
|
if ( $row->event_agent_id ) {
|
2020-08-11 09:33:33 +00:00
|
|
|
$this->agent = User::newFromId( (int)$row->event_agent_id );
|
2012-04-27 15:14:24 +00:00
|
|
|
} elseif ( $row->event_agent_ip ) {
|
2024-08-25 12:07:20 +00:00
|
|
|
// Due to an oversight, non-existing users could be inserted as IPs.
|
|
|
|
// This wouldn't cause problems if there wasn't the limit of 39 bytes for
|
|
|
|
// the database field, leading to silent truncation of long user names.
|
|
|
|
// Ignoring such entries and setting the agent to null could cause
|
|
|
|
// exceptions in presentation models, hence we accept the name if it's
|
|
|
|
// definitely not been truncated, otherwise return a fallback user.
|
|
|
|
if ( IPUtils::isValid( $row->event_agent_ip )
|
|
|
|
|| strlen( $row->event_agent_ip ) < 39
|
|
|
|
) {
|
|
|
|
$this->agent = User::newFromName( $row->event_agent_ip, false );
|
|
|
|
} else {
|
|
|
|
$this->agent = User::newFromName( ActorStore::UNKNOWN_USER_NAME, false );
|
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2014-08-16 00:24:11 +00:00
|
|
|
// Lazy load the title from getTitle() so that we can do a batch-load
|
|
|
|
if (
|
2020-02-09 10:58:49 +00:00
|
|
|
isset( $this->extra['page_title'] ) && isset( $this->extra['page_namespace'] )
|
2014-08-16 00:24:11 +00:00
|
|
|
&& !$row->event_page_id
|
|
|
|
) {
|
2013-05-09 18:50:05 +00:00
|
|
|
$this->title = Title::makeTitleSafe(
|
|
|
|
$this->extra['page_namespace'],
|
|
|
|
$this->extra['page_title']
|
|
|
|
);
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2014-08-16 03:10:09 +00:00
|
|
|
if ( $row->event_page_id ) {
|
2022-11-13 07:53:42 +00:00
|
|
|
$titleCache = Services::getInstance()->getTitleLocalCache();
|
2020-08-11 09:33:33 +00:00
|
|
|
$titleCache->add( (int)$row->event_page_id );
|
2014-08-16 03:10:09 +00:00
|
|
|
}
|
2014-08-16 07:00:08 +00:00
|
|
|
if ( isset( $this->extra['revid'] ) && $this->extra['revid'] ) {
|
2022-11-13 07:53:42 +00:00
|
|
|
$revisionCache = Services::getInstance()->getRevisionLocalCache();
|
2014-08-16 07:00:08 +00:00
|
|
|
$revisionCache->add( $this->extra['revid'] );
|
|
|
|
}
|
2016-05-13 23:39:17 +00:00
|
|
|
|
|
|
|
return true;
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-06-06 07:04:28 +00:00
|
|
|
* Loads data from the database into this object, given the event ID.
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param int $id Event ID
|
2021-05-13 00:04:54 +00:00
|
|
|
* @param bool $fromPrimary
|
2016-05-13 23:39:17 +00:00
|
|
|
* @return bool Whether it loaded successfully
|
2012-04-27 15:14:24 +00:00
|
|
|
*/
|
2021-05-13 00:04:54 +00:00
|
|
|
public function loadFromID( $id, $fromPrimary = false ) {
|
2022-11-02 20:47:04 +00:00
|
|
|
$eventMapper = new EventMapper();
|
2021-05-13 00:04:54 +00:00
|
|
|
$event = $eventMapper->fetchById( $id, $fromPrimary );
|
2016-05-13 23:39:17 +00:00
|
|
|
if ( !$event ) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-07-18 03:58:21 +00:00
|
|
|
|
|
|
|
// Copy over the attribute
|
|
|
|
$this->id = $event->id;
|
|
|
|
$this->type = $event->type;
|
|
|
|
$this->variant = $event->variant;
|
|
|
|
$this->extra = $event->extra;
|
|
|
|
$this->pageId = $event->pageId;
|
|
|
|
$this->agent = $event->agent;
|
|
|
|
$this->title = $event->title;
|
2016-03-04 19:23:02 +00:00
|
|
|
$this->deleted = $event->deleted;
|
2014-07-18 03:58:21 +00:00
|
|
|
// Don't overwrite timestamp if it exists already
|
|
|
|
if ( !$this->timestamp ) {
|
|
|
|
$this->timestamp = $event->timestamp;
|
|
|
|
}
|
2016-05-13 23:39:17 +00:00
|
|
|
|
|
|
|
return true;
|
2012-06-06 07:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-11-02 21:34:17 +00:00
|
|
|
* Creates an Event from a row object
|
2012-06-06 07:04:28 +00:00
|
|
|
*
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param stdClass $row row object from echo_event
|
2022-11-02 21:34:17 +00:00
|
|
|
* @return Event|false
|
2012-06-06 07:04:28 +00:00
|
|
|
*/
|
2012-08-30 16:04:39 +00:00
|
|
|
public static function newFromRow( $row ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
$obj = new Event();
|
2016-05-13 23:39:17 +00:00
|
|
|
return $obj->loadFromRow( $row )
|
|
|
|
? $obj
|
|
|
|
: false;
|
2012-06-06 07:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-11-02 21:34:17 +00:00
|
|
|
* Creates an Event from the database by ID
|
2012-06-06 07:04:28 +00:00
|
|
|
*
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param int $id Event ID
|
2022-11-02 21:34:17 +00:00
|
|
|
* @return Event|false
|
2012-06-06 07:04:28 +00:00
|
|
|
*/
|
|
|
|
public static function newFromID( $id ) {
|
2022-11-02 21:34:17 +00:00
|
|
|
$obj = new Event();
|
2016-05-13 23:39:17 +00:00
|
|
|
return $obj->loadFromID( $id )
|
|
|
|
? $obj
|
|
|
|
: false;
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2012-12-26 22:05:29 +00:00
|
|
|
/**
|
|
|
|
* Serialize the extra data for event
|
2019-12-21 05:45:14 +00:00
|
|
|
* @return string|null
|
2012-12-26 22:05:29 +00:00
|
|
|
*/
|
2013-01-15 23:21:39 +00:00
|
|
|
public function serializeExtra() {
|
2012-12-26 22:05:29 +00:00
|
|
|
if ( is_array( $this->extra ) || is_object( $this->extra ) ) {
|
|
|
|
$extra = serialize( $this->extra );
|
2020-01-14 05:09:42 +00:00
|
|
|
} elseif ( $this->extra === null ) {
|
2012-12-26 22:05:29 +00:00
|
|
|
$extra = null;
|
|
|
|
} else {
|
2016-12-05 18:51:07 +00:00
|
|
|
$extra = serialize( [ $this->extra ] );
|
2012-12-26 22:05:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $extra;
|
|
|
|
}
|
|
|
|
|
2013-05-08 18:11:44 +00:00
|
|
|
/**
|
|
|
|
* Determine if the current user is allowed to view a particular
|
|
|
|
* field of this revision, if it's marked as deleted. When no
|
|
|
|
* revision is attached always returns true.
|
|
|
|
*
|
2019-04-17 15:46:06 +00:00
|
|
|
* @param int $field One of RevisionRecord::DELETED_TEXT,
|
|
|
|
* RevisionRecord::DELETED_COMMENT,
|
|
|
|
* RevisionRecord::DELETED_USER
|
2017-08-09 15:20:55 +00:00
|
|
|
* @param User $user User object to check
|
|
|
|
* @return bool
|
2013-05-08 18:11:44 +00:00
|
|
|
*/
|
2015-11-24 00:08:17 +00:00
|
|
|
public function userCan( $field, User $user ) {
|
2013-05-08 18:11:44 +00:00
|
|
|
$revision = $this->getRevision();
|
2015-08-28 23:15:06 +00:00
|
|
|
// User is handled specially
|
2019-04-17 15:46:06 +00:00
|
|
|
if ( $field === RevisionRecord::DELETED_USER ) {
|
2015-08-28 23:15:06 +00:00
|
|
|
$agent = $this->getAgent();
|
|
|
|
if ( !$agent ) {
|
|
|
|
// No user associated, so they can see it.
|
|
|
|
return true;
|
2019-04-17 15:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
$revision
|
|
|
|
&& $agent->getName() === $revision->getUser( RevisionRecord::RAW )->getName()
|
2015-08-28 23:15:06 +00:00
|
|
|
) {
|
|
|
|
// If the agent and the revision user are the same, use rev_deleted
|
2019-04-17 15:46:06 +00:00
|
|
|
return $revision->audienceCan( $field, RevisionRecord::FOR_THIS_USER, $user );
|
2015-08-28 23:15:06 +00:00
|
|
|
} else {
|
|
|
|
// Use User::isHidden()
|
2020-03-05 19:55:54 +00:00
|
|
|
$permManager = MediaWikiServices::getInstance()->getPermissionManager();
|
2021-03-09 18:29:11 +00:00
|
|
|
return $permManager->userHasAnyRight( $user, 'viewsuppressed', 'hideuser' )
|
|
|
|
|| !$agent->isHidden();
|
2015-08-28 23:15:06 +00:00
|
|
|
}
|
|
|
|
} elseif ( $revision ) {
|
|
|
|
// A revision is set, use rev_deleted
|
2019-04-17 15:46:06 +00:00
|
|
|
return $revision->audienceCan( $field, RevisionRecord::FOR_THIS_USER, $user );
|
2013-05-08 18:11:44 +00:00
|
|
|
} else {
|
2015-08-28 23:15:06 +00:00
|
|
|
// Not a user, and there is no associated revision, so the user can see it
|
2013-05-08 18:11:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 15:14:24 +00:00
|
|
|
## Accessors
|
2019-07-14 10:57:45 +00:00
|
|
|
|
2013-03-04 20:56:42 +00:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public function getId() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:56:42 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public function getTimestamp() {
|
|
|
|
return $this->timestamp;
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:56:42 +00:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public function getType() {
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:56:42 +00:00
|
|
|
/**
|
2015-08-19 19:18:27 +00:00
|
|
|
* @return string|null
|
2013-03-04 20:56:42 +00:00
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public function getVariant() {
|
|
|
|
return $this->variant;
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:56:42 +00:00
|
|
|
/**
|
2018-08-13 07:33:57 +00:00
|
|
|
* @return array
|
2013-03-04 20:56:42 +00:00
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public function getExtra() {
|
|
|
|
return $this->extra;
|
|
|
|
}
|
|
|
|
|
2022-06-23 09:17:10 +00:00
|
|
|
/**
|
|
|
|
* @param string $key
|
|
|
|
* @param mixed|null $default
|
|
|
|
* @return mixed|null
|
|
|
|
*/
|
2013-05-08 18:11:44 +00:00
|
|
|
public function getExtraParam( $key, $default = null ) {
|
2019-03-12 20:04:00 +00:00
|
|
|
return $this->extra[$key] ?? $default;
|
2013-05-08 18:11:44 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 20:56:42 +00:00
|
|
|
/**
|
2015-08-19 19:18:27 +00:00
|
|
|
* @return User|null
|
2013-03-04 20:56:42 +00:00
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public function getAgent() {
|
|
|
|
return $this->agent;
|
|
|
|
}
|
|
|
|
|
2018-10-26 23:46:16 +00:00
|
|
|
/**
|
|
|
|
* Check whether this event allows its agent to be notified.
|
|
|
|
*
|
|
|
|
* Notifying the agent is only allowed if the event's type allows it, or if the event extra
|
2022-06-23 09:17:10 +00:00
|
|
|
* explicitly specifies 'notifyAgent' => true.
|
2018-10-26 23:46:16 +00:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canNotifyAgent() {
|
|
|
|
global $wgEchoNotifications;
|
|
|
|
$allowedInConfig = $wgEchoNotifications[$this->getType()]['canNotifyAgent'] ?? false;
|
|
|
|
$allowedInExtra = $this->getExtraParam( 'notifyAgent', false );
|
|
|
|
return $allowedInConfig || $allowedInExtra;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
2021-05-13 00:04:54 +00:00
|
|
|
* @param bool $fromPrimary
|
2016-07-27 14:52:18 +00:00
|
|
|
* @return null|Title
|
2012-05-17 00:29:37 +00:00
|
|
|
*/
|
2021-05-13 00:04:54 +00:00
|
|
|
public function getTitle( $fromPrimary = false ) {
|
2013-05-08 18:11:44 +00:00
|
|
|
if ( $this->title ) {
|
|
|
|
return $this->title;
|
2021-11-03 14:47:50 +00:00
|
|
|
}
|
|
|
|
if ( $this->pageId ) {
|
2022-11-13 07:53:42 +00:00
|
|
|
$titleCache = Services::getInstance()->getTitleLocalCache();
|
2014-08-16 03:10:09 +00:00
|
|
|
$title = $titleCache->get( $this->pageId );
|
|
|
|
if ( $title ) {
|
2018-02-05 19:56:54 +00:00
|
|
|
$this->title = $title;
|
|
|
|
return $this->title;
|
2014-08-16 03:10:09 +00:00
|
|
|
}
|
2024-01-26 18:23:23 +00:00
|
|
|
$this->title = Title::newFromID( $this->pageId, $fromPrimary ? IDBAccessObject::READ_LATEST : 0 );
|
2021-11-03 14:47:50 +00:00
|
|
|
if ( $this->title ) {
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( isset( $this->extra['page_title'] ) && isset( $this->extra['page_namespace'] ) ) {
|
2018-02-05 19:56:54 +00:00
|
|
|
$this->title = Title::makeTitleSafe(
|
2014-03-02 08:03:38 +00:00
|
|
|
$this->extra['page_namespace'],
|
|
|
|
$this->extra['page_title']
|
2013-05-08 18:11:44 +00:00
|
|
|
);
|
2018-02-05 19:56:54 +00:00
|
|
|
return $this->title;
|
2013-05-08 18:11:44 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-12-25 15:38:02 +00:00
|
|
|
/**
|
|
|
|
* @return int|null
|
|
|
|
*/
|
|
|
|
public function getPageId(): ?int {
|
|
|
|
return $this->pageId;
|
|
|
|
}
|
|
|
|
|
2013-05-08 18:11:44 +00:00
|
|
|
/**
|
2019-04-17 15:46:06 +00:00
|
|
|
* @return RevisionRecord|null
|
2013-05-08 18:11:44 +00:00
|
|
|
*/
|
|
|
|
public function getRevision() {
|
|
|
|
if ( $this->revision ) {
|
|
|
|
return $this->revision;
|
2019-04-17 15:46:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $this->extra['revid'] ) ) {
|
2022-11-13 07:53:42 +00:00
|
|
|
$revisionCache = Services::getInstance()->getRevisionLocalCache();
|
2014-08-16 07:00:08 +00:00
|
|
|
$revision = $revisionCache->get( $this->extra['revid'] );
|
|
|
|
if ( $revision ) {
|
2018-02-05 19:56:54 +00:00
|
|
|
$this->revision = $revision;
|
|
|
|
return $this->revision;
|
2014-08-16 07:00:08 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2019-04-17 15:46:06 +00:00
|
|
|
$store = MediaWikiServices::getInstance()->getRevisionStore();
|
|
|
|
$this->revision = $store->getRevisionById( $this->extra['revid'] );
|
2018-02-05 19:56:54 +00:00
|
|
|
return $this->revision;
|
2013-05-08 18:11:44 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2013-05-08 18:11:44 +00:00
|
|
|
return null;
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2013-03-09 00:32:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the category of the event type
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCategory() {
|
2022-11-13 07:53:42 +00:00
|
|
|
return Services::getInstance()->getAttributeManager()->getNotificationCategory( $this->type );
|
2013-03-09 00:32:28 +00:00
|
|
|
}
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2014-08-05 21:50:54 +00:00
|
|
|
/**
|
|
|
|
* Get the section of the event type
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getSection() {
|
2022-11-13 07:53:42 +00:00
|
|
|
return Services::getInstance()->getAttributeManager()->getNotificationSection( $this->type );
|
2014-08-05 21:50:54 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 18:39:53 +00:00
|
|
|
/**
|
2015-07-02 03:36:47 +00:00
|
|
|
* Determine whether an event can use the job queue, or should be immediate
|
2017-07-26 19:34:44 +00:00
|
|
|
* @return bool
|
2014-08-27 18:39:53 +00:00
|
|
|
*/
|
|
|
|
public function getUseJobQueue() {
|
|
|
|
global $wgEchoNotifications;
|
2015-07-02 03:36:47 +00:00
|
|
|
if ( isset( $wgEchoNotifications[$this->type]['immediate'] ) ) {
|
|
|
|
return !(bool)$wgEchoNotifications[$this->type]['immediate'];
|
2014-08-27 18:39:53 +00:00
|
|
|
}
|
2015-10-01 13:48:52 +00:00
|
|
|
|
2015-07-02 03:36:47 +00:00
|
|
|
return true;
|
2014-08-27 18:39:53 +00:00
|
|
|
}
|
|
|
|
|
2013-11-30 06:20:03 +00:00
|
|
|
public function setType( $type ) {
|
|
|
|
$this->type = $type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setVariant( $variant ) {
|
|
|
|
$this->variant = $variant;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setAgent( User $agent ) {
|
|
|
|
$this->agent = $agent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setTitle( Title $title ) {
|
|
|
|
$this->title = $title;
|
2016-03-04 19:23:02 +00:00
|
|
|
$pageId = $title->getArticleID();
|
2013-11-30 06:20:03 +00:00
|
|
|
if ( $pageId ) {
|
|
|
|
$this->pageId = $pageId;
|
|
|
|
} else {
|
2016-03-04 19:23:02 +00:00
|
|
|
$this->extra['page_title'] = $title->getDBkey();
|
2013-11-30 06:20:03 +00:00
|
|
|
$this->extra['page_namespace'] = $title->getNamespace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setExtra( $name, $value ) {
|
|
|
|
$this->extra[$name] = $value;
|
|
|
|
}
|
|
|
|
|
2013-06-12 23:18:26 +00:00
|
|
|
/**
|
|
|
|
* Get the message key of the primary or secondary link for a notification type.
|
|
|
|
*
|
2020-03-20 15:37:25 +00:00
|
|
|
* @param string $rank 'primary' or 'secondary'
|
|
|
|
* @return string i18n message key
|
2013-06-12 23:18:26 +00:00
|
|
|
*/
|
|
|
|
public function getLinkMessage( $rank ) {
|
|
|
|
global $wgEchoNotifications;
|
2014-08-16 06:41:39 +00:00
|
|
|
$type = $this->getType();
|
2019-05-07 16:52:01 +00:00
|
|
|
return $wgEchoNotifications[$type][$rank . '-link']['message'] ?? '';
|
2013-06-12 23:18:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the link destination of the primary or secondary link for a notification type.
|
|
|
|
*
|
2020-03-20 15:37:25 +00:00
|
|
|
* @param string $rank 'primary' or 'secondary'
|
|
|
|
* @return string The link destination, e.g. 'agent'
|
2013-06-12 23:18:26 +00:00
|
|
|
*/
|
|
|
|
public function getLinkDestination( $rank ) {
|
|
|
|
global $wgEchoNotifications;
|
2014-08-16 06:41:39 +00:00
|
|
|
$type = $this->getType();
|
2019-05-07 16:52:01 +00:00
|
|
|
return $wgEchoNotifications[$type][$rank . '-link']['destination'] ?? '';
|
2013-06-12 23:18:26 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
/**
|
2019-12-21 05:45:14 +00:00
|
|
|
* @return string|null
|
2013-01-15 23:21:39 +00:00
|
|
|
*/
|
|
|
|
public function getBundleHash() {
|
|
|
|
return $this->bundleHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-21 05:45:14 +00:00
|
|
|
* @param string|null $hash
|
2013-01-15 23:21:39 +00:00
|
|
|
*/
|
|
|
|
public function setBundleHash( $hash ) {
|
|
|
|
$this->bundleHash = $hash;
|
|
|
|
}
|
2016-03-04 19:23:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function isDeleted() {
|
|
|
|
return $this->deleted === 1;
|
|
|
|
}
|
|
|
|
|
2019-10-23 10:44:35 +00:00
|
|
|
public function setBundledEvents( array $events ) {
|
2016-03-04 19:23:02 +00:00
|
|
|
$this->bundledEvents = $events;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBundledEvents() {
|
|
|
|
return $this->bundledEvents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-09 15:20:55 +00:00
|
|
|
* @inheritDoc
|
2016-03-04 19:23:02 +00:00
|
|
|
*/
|
|
|
|
public function canBeBundled() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-09 15:20:55 +00:00
|
|
|
* @inheritDoc
|
2016-03-04 19:23:02 +00:00
|
|
|
*/
|
|
|
|
public function getBundlingKey() {
|
|
|
|
return $this->getBundleHash();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-09 15:20:55 +00:00
|
|
|
* @inheritDoc
|
2016-03-04 19:23:02 +00:00
|
|
|
*/
|
2019-10-23 10:44:35 +00:00
|
|
|
public function setBundledElements( array $bundleables ) {
|
2016-03-04 19:23:02 +00:00
|
|
|
$this->setBundledEvents( $bundleables );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-08-09 15:20:55 +00:00
|
|
|
* @inheritDoc
|
2016-03-04 19:23:02 +00:00
|
|
|
*/
|
|
|
|
public function getSortingKey() {
|
|
|
|
return $this->getTimestamp();
|
|
|
|
}
|
2019-03-02 20:25:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the list of fields that should be selected to create
|
2022-11-02 21:34:17 +00:00
|
|
|
* a new event with Event::newFromRow
|
2019-03-02 20:25:33 +00:00
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public static function selectFields() {
|
|
|
|
return [
|
|
|
|
'event_id',
|
|
|
|
'event_type',
|
|
|
|
'event_variant',
|
|
|
|
'event_agent_id',
|
|
|
|
'event_agent_ip',
|
|
|
|
'event_extra',
|
|
|
|
'event_page_id',
|
|
|
|
'event_deleted',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2012-08-30 16:04:39 +00:00
|
|
|
}
|
2022-11-02 23:50:53 +00:00
|
|
|
|
2022-11-02 21:34:17 +00:00
|
|
|
class_alias( Event::class, 'EchoEvent' );
|