Merge "Getting rid of confusing abstraction regarding formatter classes"

This commit is contained in:
Bsitu 2013-02-22 21:24:18 +00:00 committed by Gerrit Code Review
commit e6d9e93393
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 );