Extension:Echo/Creating a new notification type

Notifications system allows logged in users to receive alerts and notices about their interactions with connected wikis. In Wikimedia projects, this means wikis in the cluster, but the Notifications system can also be used by third-parties - either in a single wiki or a series of connected wikis to utilize the cross-wiki notification system

The system allows extension developers the ability to add new notification types that users can receive under certain circumstances. This document will outline the way to create such notification, explain best practices and formulate the known pitfalls to avoid.

Introduction to how notifications work
Notifications are, very generally, made of two concepts - the Event and the PresentationModel. The event stores details of the triggered event and the presentation model defines the way it is presented in the user interface.

EchoEvent
EchoEvent class defines general events, collects information about the related page, user and wiki and inserts them into the database. Events are general, and one even may define multiple views.

For example, mentioning 4 people will create a single event, that will then be referenced (and 'trigger' a notification) for the four mentioned users. All of their individual notifications, however, will reference the same event.

''Note: This is a slight generalization of the process for the sake of clarity. Explaining how things work in practice with database table rows (per user, wiki, cross-wiki, etc) is outside the scope of this tutorial.''

EchoPresentationModel
Every type of notifications requires a presentation model, a way to define what the notification will display, where it will link to, and what secondary actions is will present. The front-end of the notifications system (the notifications popup and the Special:Notifications page) read that information to produce a proper display of notification.

The presentation of a notification type is always based on the base definition in EchoEventPresentationModel. That class defines the base behavior of all notifications, and each child notification must extend it, and then adjust the details to its needs.