Getting rid of confusing abstraction regarding formatter classes

Specifying the class directly is much less confusing and fragile.
Plus we have way too many things named 'type'.
Also changing MWEchoArticleLinkedFormatter to EchoArticleLinkedFormatter
to match the convention of the other formatter classes.
Also making EchoBasicFormatter the default, so that the Hello World
case is easier to implement.

Change-Id: Ibd9b15008d37ad815e466ab81ba9a5b668ee2791
This commit is contained in:
Kaldari 2013-02-15 15:34:47 -08:00
parent 35cf44e4a6
commit 335fc1fab0
3 changed files with 14 additions and 24 deletions

View file

@ -56,7 +56,7 @@ $wgAutoloadClasses['EchoNotificationFormatter'] = $dir . 'formatters/Notificatio
$wgAutoloadClasses['EchoBasicFormatter'] = $dir . 'formatters/BasicFormatter.php';
$wgAutoloadClasses['EchoEditFormatter'] = $dir . 'formatters/EditFormatter.php';
$wgAutoloadClasses['EchoCommentFormatter'] = $dir . 'formatters/CommentFormatter.php';
$wgAutoloadClasses['MWEchoArticleLinkedFormatter'] = $dir . 'formatters/ArticleLinkedFormatter.php';
$wgAutoloadClasses['EchoArticleLinkedFormatter'] = $dir . 'formatters/ArticleLinkedFormatter.php';
// Internal stuff
$wgAutoloadClasses['EchoNotifier'] = $dir . 'Notifier.php';
@ -259,17 +259,17 @@ $wgEchoEventDetails = array(
),
);
// Definitions of the notification event types built into Echo
// Definitions of the notification event types built into Echo.
// If formatter-class isn't specified, defaults to EchoBasicFormatter.
$wgEchoNotificationFormatters = array(
'welcome' => array(
'type' => 'system',
'title-message' => 'notification-new-user',
'title-params' => array( 'agent' ),
'payload' => array( 'welcome' ),
'icon' => 'w',
),
'edit-user-talk' => array(
'type' => 'edit',
'formatter-class' => 'EchoEditFormatter',
'title-message' => 'notification-edit-talk-page2',
'title-params' => array( 'agent', 'user' ),
'payload' => array( 'summary' ),
@ -283,7 +283,7 @@ $wgEchoNotificationFormatters = array(
'icon' => 'chat',
),
'add-comment' => array(
'type' => 'comment',
'formatter-class' => 'EchoCommentFormatter',
'title-message' => 'notification-add-comment2',
'title-message-yours' => 'notification-add-comment-yours2',
'title-params' => array( 'agent', 'subject', 'title', 'content-page' ),
@ -291,7 +291,7 @@ $wgEchoNotificationFormatters = array(
'icon' => 'chat',
),
'add-talkpage-topic' => array(
'type' => 'comment',
'formatter-class' => 'EchoCommentFormatter',
'title-message' => 'notification-add-talkpage-topic2',
'title-message-yours' => 'notification-add-talkpage-topic-yours2',
'title-params' => array( 'agent', 'subject', 'title', 'content-page' ),
@ -299,7 +299,7 @@ $wgEchoNotificationFormatters = array(
'icon' => 'chat',
),
'reverted' => array(
'type' => 'edit',
'formatter-class' => 'EchoEditFormatter',
'title-message' => 'notification-reverted2',
'title-params' => array( 'agent', 'title', 'difflink', 'number' ),
'payload' => array( 'summary' ),
@ -314,7 +314,7 @@ $wgEchoNotificationFormatters = array(
'icon' => 'revert',
),
'article-linked' => array(
'class' => 'MWEchoArticleLinkedFormatter',
'formatter-class' => 'EchoArticleLinkedFormatter',
'title-message' => 'notification-article-linked2',
'title-params' => array( 'agent', 'title', 'title-linked' ),
'payload' => array( 'summary' ),

View file

@ -3,7 +3,7 @@
/**
* Formatter for 'article-linked' notifications
*/
class MWEchoArticleLinkedFormatter extends EchoEditFormatter {
class EchoArticleLinkedFormatter extends EchoEditFormatter {
/**
* @param $event EchoEvent

View file

@ -7,12 +7,6 @@
* content or requirements.
*/
abstract class EchoNotificationFormatter {
static $formatterClasses = array(
'basic' => 'EchoBasicFormatter',
'edit' => 'EchoEditFormatter',
'comment' => 'EchoCommentFormatter',
'system' => 'EchoBasicFormatter',
);
protected $validOutputFormats = array( 'text', 'flyout', 'html', 'email' );
protected $outputFormat = 'text';
protected $parameters = array();
@ -67,24 +61,20 @@ abstract class EchoNotificationFormatter {
/**
* Create an EchoNotificationFormatter from the supplied parameters.
* @param $parameters array Associative array.
* Select the class of formatter to use with the 'type' or 'class' field.
* Select the class of formatter to use with the 'class' field.
* For other parameters, see the appropriate class' constructor.
* @throws MWException
* @return EchoNotificationFormatter object.
*/
public static function factory( $parameters ) {
$class = null;
if ( isset( $parameters['type'] ) ) {
$type = $parameters['type'];
if ( isset( self::$formatterClasses[$type] ) ) {
$class = self::$formatterClasses[$type];
}
} elseif ( isset( $parameters['class'] ) ) {
$class = $parameters['class'];
if ( isset( $parameters['formatter-class'] ) ) {
$class = $parameters['formatter-class'];
}
// Default to basic formatter
if ( !$class || !class_exists( $class ) ) {
throw new MWException( "No valid class ($class) or type ($type) specified for " . __METHOD__ );
$class = 'EchoBasicFormatter';
}
return new $class( $parameters );