mediawiki-extensions-Echo/model/Notification.php
Andrew Garrett 8da85396d6 Initial commit of Echo, a notifications framework for MediaWiki.
This version is very rough.

For an example set of Minimum Releasable Functionality, this version will notify users on
changes to their watchlists or to their user talk pages.

However, it is still missing a conversion script to turn watchlists into echo subscriptions.

For now, notifications can be viewed through the new special page Special:Notifications, or through the API module provided.

Change-Id: I5867226e3e6195fbed81f4b5803e2310f057ffc4
2012-05-13 00:53:21 +10:00

69 lines
1.6 KiB
PHP

<?php
class EchoNotification {
protected $user = false;
protected $event = false;
protected $timestamp = false;
protected $readTimestamp = false;
/**
* Do not use this constructor.
*/
protected function __construct() {
}
/**
* Creates an EchoNotification object
* @param $info Named arguments:
* event: (required) The EchoEvent being notified about.
* user: (required) The User being notified.
*
* @return The created EchoNotification.
*/
public static function create( $info = array() ) {
$obj = new EchoNotification;
static $validFields = array( 'event', 'user' );
$obj->id = false;
$obj->timestamp = wfTimestampNow();
$obj->readTimestamp = null;
foreach( $validFields as $field ) {
if ( isset($info[$field]) ) {
$obj->$field = $info[$field];
} else {
throw new MWException( "Field $field is required" );
}
}
if ( ! $obj->user instanceof User &&
! $obj->user instanceof StubObject
) {
throw new MWException( "Invalid user parameter: ".get_class($obj->user) );
}
if ( !$obj->event instanceof EchoEvent ) {
throw new MWException( "Invalid event parameter" );
}
$obj->insert();
return $obj;
}
/**
* Adds this new object to the database.
*/
protected function insert() {
$dbw = wfGetDB( DB_MASTER );
$row = array(
'notification_event' => $this->event->getId(),
'notification_user' => $this->user->getId(),
'notification_timestamp' => $dbw->timestamp( $this->timestamp ),
'notification_read_timestamp' => null,
);
$dbw->insert( 'echo_notification', $row, __METHOD__ );
}
}