2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
2013-03-07 03:08:12 +00:00
|
|
|
/**
|
|
|
|
* @Todo - Consider having $event/$user as class properties since the formatter is
|
|
|
|
* always tied to these two entities, in this case, we won't have to pass it around
|
|
|
|
* in all the internal method
|
2013-09-26 23:25:46 +00:00
|
|
|
* @Todo - Instance variable $distributionType has been added, the local distribution
|
|
|
|
* type variable $type passed along all the protected/private method should be removed
|
|
|
|
* from all formatters
|
2013-03-07 03:08:12 +00:00
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
class EchoBasicFormatter extends EchoNotificationFormatter {
|
2013-04-04 21:56:05 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification title data for archive page
|
|
|
|
* @param array
|
|
|
|
*/
|
|
|
|
protected $title;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification title data for flyout
|
|
|
|
* @param array
|
|
|
|
*/
|
|
|
|
protected $flyoutTitle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification title data for bundling ( flyout and archive page )
|
|
|
|
*/
|
|
|
|
protected $bundleTitle;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification email data
|
|
|
|
* @param array
|
|
|
|
*/
|
|
|
|
protected $email;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification icon for each type
|
|
|
|
* @param string
|
|
|
|
*/
|
|
|
|
protected $icon;
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2013-08-27 00:55:45 +00:00
|
|
|
/**
|
|
|
|
* The language to format a message, default language
|
|
|
|
* is the current language
|
|
|
|
* @param mixed Language code or Language object
|
|
|
|
*/
|
|
|
|
protected $language;
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
/**
|
|
|
|
* Data for constructing bundle message, data in this array
|
|
|
|
* should be used in function processParams()
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $bundleData = array (
|
2013-10-02 22:28:22 +00:00
|
|
|
'use-bundle' => false,
|
|
|
|
'raw-data-count' => 1
|
2013-01-15 23:21:39 +00:00
|
|
|
);
|
2012-04-27 15:14:24 +00:00
|
|
|
|
2013-09-26 23:25:46 +00:00
|
|
|
/**
|
|
|
|
* Max number of raw bundle data to query for each bundle event
|
|
|
|
*/
|
|
|
|
protected static $maxRawBundleData = 250;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array
|
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public function __construct( $params ) {
|
2012-08-30 16:04:39 +00:00
|
|
|
parent::__construct( $params );
|
2012-07-31 00:29:49 +00:00
|
|
|
|
2015-06-16 22:32:12 +00:00
|
|
|
if ( !isset( $params['title-message'] ) ) {
|
|
|
|
// Required, no default value set
|
|
|
|
throw new InvalidArgumentException( "'title-message' parameter not set" );
|
|
|
|
}
|
|
|
|
|
2013-08-02 00:52:47 +00:00
|
|
|
// Set up default params if any are missing
|
2013-08-16 00:53:24 +00:00
|
|
|
$params = $this->setDefaultParams( $params );
|
2013-08-02 00:52:47 +00:00
|
|
|
|
2013-04-04 21:56:05 +00:00
|
|
|
// Title for archive page
|
|
|
|
$this->title = array(
|
|
|
|
'message' => $params['title-message'],
|
|
|
|
'params' => $params['title-params']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Title for the flyout
|
|
|
|
$this->flyoutTitle = array(
|
|
|
|
'message' => $params['flyout-message'],
|
|
|
|
'params' => $params['flyout-params']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Bundle title for both archive page and flyout
|
|
|
|
$this->bundleTitle = array(
|
|
|
|
'message' => $params['bundle-message'],
|
|
|
|
'params' => $params['bundle-params']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Notification payload data, eg, summary
|
|
|
|
$this->payload = $params['payload'];
|
|
|
|
|
|
|
|
// Notification email subject and body
|
|
|
|
$this->email = array(
|
|
|
|
'subject' => array(
|
|
|
|
'message' => $params['email-subject-message'],
|
|
|
|
'params' => $params['email-subject-params']
|
|
|
|
),
|
|
|
|
'batch-body' => array(
|
|
|
|
'message' => $params['email-body-batch-message'],
|
|
|
|
'params' => $params['email-body-batch-params']
|
2013-03-06 00:04:48 +00:00
|
|
|
),
|
|
|
|
'batch-bundle-body' => array(
|
|
|
|
'message' => $params['email-body-batch-bundle-message'],
|
|
|
|
'params' => $params['email-body-batch-bundle-params']
|
2013-04-04 21:56:05 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Notification icon for the event type
|
|
|
|
$this->icon = $params['icon'];
|
|
|
|
}
|
2012-10-25 20:39:41 +00:00
|
|
|
|
2013-04-04 21:56:05 +00:00
|
|
|
/**
|
2013-08-16 00:53:24 +00:00
|
|
|
* Internal function for setting notification default params
|
|
|
|
* @param $params array
|
2013-04-04 21:56:05 +00:00
|
|
|
* @return array
|
|
|
|
*/
|
2013-08-16 00:53:24 +00:00
|
|
|
protected function setDefaultParams( $params ) {
|
|
|
|
$params += array(
|
2013-08-02 00:52:47 +00:00
|
|
|
'title-params' => array(),
|
2013-04-04 21:56:05 +00:00
|
|
|
'bundle-message' => '',
|
|
|
|
'bundle-params' => array(),
|
|
|
|
'payload' => array(),
|
|
|
|
'email-subject-message' => 'echo-email-subject-default',
|
|
|
|
'email-subject-params' => array(),
|
|
|
|
'email-body-batch-message' => 'echo-email-batch-body-default',
|
|
|
|
'email-body-batch-params' => array(),
|
2013-03-06 00:04:48 +00:00
|
|
|
'email-body-batch-bundle-message' => '',
|
|
|
|
'email-body-batch-bundle-params' => array(),
|
2013-04-04 21:56:05 +00:00
|
|
|
'icon' => 'placeholder'
|
|
|
|
);
|
2013-08-16 00:53:24 +00:00
|
|
|
|
|
|
|
// default flyout-message to title-message if not defined
|
|
|
|
$params += array ( 'flyout-message' => $params['title-message'], 'flyout-params' => $params['title-params'] );
|
|
|
|
|
|
|
|
return $params;
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2012-09-02 09:30:38 +00:00
|
|
|
/**
|
2013-09-30 20:28:58 +00:00
|
|
|
* Apply some custom change before formatting, child class overwriting this method
|
2013-07-24 03:50:43 +00:00
|
|
|
* should always invoke a call to the parent method unless child class wants to overwrite
|
|
|
|
* the default completely
|
2012-11-26 22:57:28 +00:00
|
|
|
*
|
|
|
|
* @param $event EchoEvent that the notification is for.
|
|
|
|
* @param $user User to format the notification for.
|
2013-11-23 05:31:26 +00:00
|
|
|
* @param $type string deprecated
|
2012-09-02 09:30:38 +00:00
|
|
|
*/
|
2013-07-24 03:50:43 +00:00
|
|
|
protected function applyChangeBeforeFormatting( EchoEvent $event, User $user, $type ) {
|
2013-01-15 23:21:39 +00:00
|
|
|
// Use the bundle message if use-bundle is true and there is a bundle message
|
2013-03-06 00:04:48 +00:00
|
|
|
$this->generateBundleData( $event, $user, $type );
|
2013-09-30 20:28:58 +00:00
|
|
|
if ( $this->bundleData['use-bundle'] && $this->bundleTitle['message'] ) {
|
2013-01-15 23:21:39 +00:00
|
|
|
$this->title = $this->flyoutTitle = $this->bundleTitle;
|
|
|
|
}
|
2013-07-24 03:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a notification
|
|
|
|
*
|
|
|
|
* @param $event EchoEvent that the notification is for.
|
|
|
|
* @param $user User to format the notification for.
|
|
|
|
* @param $type string The type of notification being distributed (e.g. email, web)
|
|
|
|
* @return array|string
|
|
|
|
*/
|
|
|
|
public function format( $event, $user, $type ) {
|
2015-08-13 17:52:24 +00:00
|
|
|
global $wgLang;
|
2013-07-24 03:50:43 +00:00
|
|
|
|
2013-09-26 23:25:46 +00:00
|
|
|
$this->setDistributionType( $type );
|
2013-07-24 03:50:43 +00:00
|
|
|
$this->applyChangeBeforeFormatting( $event, $user, $type );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2012-05-17 15:36:18 +00:00
|
|
|
if ( $this->outputFormat === 'email' ) {
|
|
|
|
return $this->formatEmail( $event, $user, $type );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-31 00:29:49 +00:00
|
|
|
if ( $this->outputFormat === 'text' ) {
|
|
|
|
return $this->formatNotificationTitle( $event, $user )->text();
|
|
|
|
}
|
2012-05-17 15:36:18 +00:00
|
|
|
|
2015-08-05 19:41:12 +00:00
|
|
|
$iconUrl = $this->getIconUrl( $this->icon, $wgLang->getDir() );
|
2013-04-29 03:40:56 +00:00
|
|
|
|
2012-11-26 22:57:28 +00:00
|
|
|
// Assume html as the format for the notification
|
2013-04-29 03:40:56 +00:00
|
|
|
$output = Html::element(
|
|
|
|
'img',
|
|
|
|
array(
|
|
|
|
'class' => "mw-echo-icon",
|
|
|
|
'src' => $iconUrl,
|
|
|
|
)
|
2013-04-02 23:47:54 +00:00
|
|
|
);
|
2012-11-30 23:58:54 +00:00
|
|
|
|
2012-11-26 22:57:28 +00:00
|
|
|
// Build the notification title
|
2013-04-02 23:47:54 +00:00
|
|
|
$content = Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'class' => 'mw-echo-title' ),
|
|
|
|
$this->formatNotificationTitle( $event, $user )->parse()
|
|
|
|
) . "\n";
|
2012-11-26 22:57:28 +00:00
|
|
|
|
2012-11-30 23:58:54 +00:00
|
|
|
// Build the notification payload
|
|
|
|
$payload = '';
|
2012-11-28 02:17:52 +00:00
|
|
|
foreach ( $this->payload as $payloadComponent ) {
|
2013-03-07 03:08:12 +00:00
|
|
|
$payload .= $this->formatPayload( $payloadComponent, $event, $user );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2012-11-28 02:17:52 +00:00
|
|
|
|
2012-11-30 23:58:54 +00:00
|
|
|
if ( $payload !== '' ) {
|
|
|
|
$content .= Xml::tags( 'div', array( 'class' => 'mw-echo-payload' ), $payload ) . "\n";
|
2012-05-17 15:36:18 +00:00
|
|
|
}
|
|
|
|
|
2013-06-12 23:18:26 +00:00
|
|
|
// Add footer (timestamp and secondary link)
|
|
|
|
$content .= $this->formatFooter( $event, $user );
|
|
|
|
|
|
|
|
// Add the primary link (hidden)
|
|
|
|
if ( $this->outputFormat === 'flyout' ) {
|
|
|
|
$content .= $this->getLink( $event, $user, 'primary' );
|
|
|
|
}
|
2013-02-28 23:52:12 +00:00
|
|
|
|
2012-11-30 23:58:54 +00:00
|
|
|
$output .= Xml::tags( 'div', array( 'class' => 'mw-echo-content' ), $content ) . "\n";
|
|
|
|
|
2013-02-13 02:08:36 +00:00
|
|
|
// The state div is used to visually indicate read or unread status. This is
|
|
|
|
// handled in a separate element than the notification element so that things
|
|
|
|
// like the close box won't inherit the greyed out opacity (which can't be reset).
|
|
|
|
$output = Xml::tags( 'div', array( 'class' => 'mw-echo-state' ), $output ) . "\n";
|
|
|
|
|
2012-07-31 00:29:49 +00:00
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
2013-02-28 23:52:12 +00:00
|
|
|
/**
|
|
|
|
* @param $event EchoEvent
|
|
|
|
* @param $user User
|
|
|
|
* @return string
|
|
|
|
*/
|
2012-07-31 00:29:49 +00:00
|
|
|
protected function formatNotificationTitle( $event, $user ) {
|
2013-01-07 22:44:58 +00:00
|
|
|
if ( $this->outputFormat === 'flyout' ) {
|
|
|
|
return $this->formatFragment( $this->flyoutTitle, $event, $user );
|
|
|
|
} else {
|
|
|
|
return $this->formatFragment( $this->title, $event, $user );
|
|
|
|
}
|
2012-07-31 00:29:49 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 23:52:12 +00:00
|
|
|
/**
|
2013-06-24 00:22:08 +00:00
|
|
|
* Create text version and/or html version for email notification
|
|
|
|
*
|
2013-02-28 23:52:12 +00:00
|
|
|
* @param $event EchoEvent
|
|
|
|
* @param $user User
|
2013-11-23 05:31:26 +00:00
|
|
|
* @param $type string deprecated
|
2013-06-17 21:44:46 +00:00
|
|
|
* @return array
|
2013-02-28 23:52:12 +00:00
|
|
|
*/
|
2012-11-28 02:17:52 +00:00
|
|
|
protected function formatEmail( $event, $user, $type ) {
|
2013-08-27 00:55:45 +00:00
|
|
|
// Email should be always sent in user language
|
|
|
|
$this->language = $user->getOption( 'language' );
|
|
|
|
|
2013-07-09 00:41:08 +00:00
|
|
|
// Email digest
|
2013-09-26 23:25:46 +00:00
|
|
|
if ( $this->distributionType === 'emaildigest' ) {
|
2013-07-09 00:41:08 +00:00
|
|
|
return $this->formatEmailDigest( $event, $user );
|
2013-03-06 00:04:48 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 00:22:08 +00:00
|
|
|
// Echo single email
|
|
|
|
$emailSingle = new EchoEmailSingle( $this, $event, $user );
|
|
|
|
$textEmailFormatter = new EchoTextEmailFormatter( $emailSingle );
|
2014-09-11 21:02:28 +00:00
|
|
|
// Update the distribution type to emailsubject when formatting
|
|
|
|
// email subject
|
|
|
|
// @FIXME - Find a better way to do this
|
|
|
|
$distributionType = $this->distributionType;
|
|
|
|
$this->setDistributionType( 'emailsubject' );
|
|
|
|
$subject = $this->formatFragment( $this->email['subject'], $event, $user )->text();
|
|
|
|
$this->setDistributionType( $distributionType );
|
|
|
|
|
2013-06-24 00:22:08 +00:00
|
|
|
$content = array(
|
|
|
|
// Single email subject, there is no need to to escape it for either html
|
|
|
|
// or text email since it's always treated as plain text by mail client
|
2014-09-11 21:02:28 +00:00
|
|
|
'subject' => $subject,
|
2013-06-24 00:22:08 +00:00
|
|
|
// Single email text body
|
|
|
|
'body' => $textEmailFormatter->formatEmail(),
|
|
|
|
);
|
|
|
|
|
|
|
|
$format = MWEchoNotifUser::newFromUser( $user )->getEmailFormat();
|
|
|
|
if ( $format == EchoHooks::EMAIL_FORMAT_HTML ) {
|
|
|
|
$htmlEmailFormatter = new EchoHTMLEmailFormatter( $emailSingle );
|
|
|
|
$outputFormat = $this->outputFormat;
|
|
|
|
$this->setOutputFormat( 'htmlemail' );
|
|
|
|
// Add single email html body if user prefers html format
|
|
|
|
$content['body'] = array (
|
|
|
|
'text' => $content['body'],
|
|
|
|
'html' => $htmlEmailFormatter->formatEmail()
|
|
|
|
);
|
|
|
|
$this->setOutputFormat( $outputFormat );
|
|
|
|
}
|
|
|
|
|
|
|
|
return $content;
|
2012-07-31 00:29:49 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 00:41:08 +00:00
|
|
|
/**
|
|
|
|
* Format text and/or html verion of email digest fragment for this event
|
|
|
|
* @param $event EchoEvent
|
|
|
|
* @param $user User
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
protected function formatEmailDigest( $event, $user ) {
|
|
|
|
if ( $this->bundleData['use-bundle'] && $this->email['batch-bundle-body'] ) {
|
|
|
|
$key = $this->email['batch-bundle-body'];
|
|
|
|
} else {
|
|
|
|
$key = $this->email['batch-body'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Email digest text body
|
|
|
|
$content = array( 'batch-body' => $this->formatFragment( $key, $event, $user )->text() );
|
|
|
|
$format = MWEchoNotifUser::newFromUser( $user )->getEmailFormat();
|
|
|
|
if ( $format == EchoHooks::EMAIL_FORMAT_HTML ) {
|
|
|
|
$outputFormat = $this->outputFormat;
|
|
|
|
$this->setOutputFormat( 'htmlemail' );
|
|
|
|
$content['batch-body-html'] = $this->formatFragment( $key, $event, $user )->parse();
|
|
|
|
$content['icon'] = $this->icon;
|
|
|
|
$this->setOutputFormat( $outputFormat );
|
|
|
|
}
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
2013-08-27 00:55:45 +00:00
|
|
|
/**
|
|
|
|
* Get Message object in the desired language, use this method instead
|
|
|
|
* of wfMessage() if a message would be used in either web or email
|
|
|
|
* @param $msgStr string message string
|
|
|
|
* @return Message
|
|
|
|
*/
|
|
|
|
public function getMessage( $msgStr ) {
|
|
|
|
$message = wfMessage( $msgStr );
|
|
|
|
if ( $this->language ) {
|
|
|
|
$message->inLanguage( $this->language );
|
|
|
|
}
|
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
2012-11-28 02:17:52 +00:00
|
|
|
/**
|
|
|
|
* Creates a notification fragment based on a message and parameters
|
|
|
|
*
|
|
|
|
* @param $details array An i18n message and parameters to pass to the message
|
|
|
|
* @param $event EchoEvent that the notification is for.
|
|
|
|
* @param $user User to format the notification for.
|
2013-10-20 09:32:30 +00:00
|
|
|
* @return Message
|
2012-11-28 02:17:52 +00:00
|
|
|
*/
|
2013-06-24 00:22:08 +00:00
|
|
|
public function formatFragment( $details, $event, $user ) {
|
2013-08-27 00:55:45 +00:00
|
|
|
$message = $this->getMessage( $details['message'] );
|
2012-07-31 00:29:49 +00:00
|
|
|
$this->processParams( $details['params'], $event, $message, $user );
|
|
|
|
|
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
2013-03-07 03:08:12 +00:00
|
|
|
/**
|
|
|
|
* Formats the payload of a notification, child method overwriting this method should
|
|
|
|
* always call this method in default case so they can use the payload defined in this
|
|
|
|
* function as well
|
|
|
|
* @param $payload string
|
|
|
|
* @param $event EchoEvent
|
|
|
|
* @param $user User
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function formatPayload( $payload, $event, $user ) {
|
|
|
|
switch ( $payload ) {
|
|
|
|
case 'summary':
|
2013-08-29 22:10:06 +00:00
|
|
|
$revisionSnippet = $this->getRevisionSnippet( $event, $user );
|
|
|
|
if ( $revisionSnippet ) {
|
|
|
|
return Xml::tags(
|
|
|
|
'div',
|
|
|
|
array( 'class' => 'mw-echo-edit-summary' ),
|
|
|
|
Xml::tags(
|
|
|
|
'span', array( 'class' => 'comment' ),
|
|
|
|
htmlspecialchars( $revisionSnippet )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
2013-03-07 03:08:12 +00:00
|
|
|
break;
|
2013-05-13 22:00:16 +00:00
|
|
|
case 'comment-text':
|
|
|
|
return $this->formatCommentText( $event, $user );
|
|
|
|
break;
|
2013-03-07 03:08:12 +00:00
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 22:00:16 +00:00
|
|
|
/**
|
|
|
|
* Extract the comment left by a user on a talk page from the event.
|
|
|
|
* @param $event EchoEvent The event to format the comment of
|
|
|
|
* @param $user User The user to format content for
|
|
|
|
* @return string Up to the first 200 characters of the comment
|
|
|
|
*/
|
|
|
|
protected function formatCommentText( EchoEvent $event, $user ) {
|
2013-05-08 18:11:44 +00:00
|
|
|
if ( !$event->userCan( Revision::DELETED_TEXT, $user ) ) {
|
2013-08-27 00:55:45 +00:00
|
|
|
return $this->getMessage( 'echo-rev-deleted-text-view' )->text();
|
2013-05-08 18:11:44 +00:00
|
|
|
}
|
2013-05-13 22:00:16 +00:00
|
|
|
$extra = $event->getExtra();
|
|
|
|
if ( !isset( $extra['content'] ) ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$content = EchoDiscussionParser::stripHeader( $extra['content'] );
|
|
|
|
$content = EchoDiscussionParser::stripSignature( $content );
|
|
|
|
$content = EchoDiscussionParser::stripIndents( $content );
|
|
|
|
return EchoDiscussionParser::getTextSnippet( $content, 200 );
|
|
|
|
}
|
|
|
|
|
2013-05-14 22:22:52 +00:00
|
|
|
/**
|
|
|
|
* Extract the subject anchor (linkable portion of the edited page) from
|
|
|
|
* the event.
|
|
|
|
*
|
|
|
|
* @param $event EchoEvent The event to format the subject anchor of
|
|
|
|
* @return string The anchor on page, or an empty string
|
|
|
|
*/
|
|
|
|
protected function formatSubjectAnchor( EchoEvent $event ) {
|
2013-05-08 18:11:44 +00:00
|
|
|
global $wgParser, $wgUser;
|
2013-05-14 22:22:52 +00:00
|
|
|
|
2013-05-08 18:11:44 +00:00
|
|
|
if ( !$event->userCan( Revision::DELETED_TEXT, $wgUser ) ) {
|
2013-08-27 00:55:45 +00:00
|
|
|
return $this->getMessage( 'echo-rev-deleted-text-view' )->text();
|
2013-05-08 18:11:44 +00:00
|
|
|
}
|
2013-05-14 22:22:52 +00:00
|
|
|
$extra = $event->getExtra();
|
|
|
|
if ( empty( $extra['section-title'] ) ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Strip out #, keeping # in the i18n message makes it look more clear
|
|
|
|
return substr( $wgParser->guessLegacySectionNameFromWikiText( $extra['section-title'] ), 1 );
|
|
|
|
}
|
|
|
|
|
2013-06-12 23:18:26 +00:00
|
|
|
/**
|
|
|
|
* Build the footer for the notification (timestamp and secondary link)
|
|
|
|
* @param EchoEvent $event
|
|
|
|
* @param User $user The user to format the notification for.
|
|
|
|
* @return String HTML
|
|
|
|
*/
|
|
|
|
protected function formatFooter( $event, $user ) {
|
|
|
|
global $wgLang;
|
2013-07-12 18:29:01 +00:00
|
|
|
|
|
|
|
// Default footer is timestamp
|
|
|
|
$footer = $this->formatTimestamp( $event->getTimestamp() );
|
|
|
|
$secondaryLink = $this->getLink( $event, $user, 'secondary' );
|
|
|
|
if ( $secondaryLink ) {
|
|
|
|
$footer = $wgLang->pipeList( array( $footer, $secondaryLink ) );
|
2013-06-12 23:18:26 +00:00
|
|
|
}
|
|
|
|
return Xml::tags( 'div', array( 'class' => 'mw-echo-notification-footer' ), $footer ) . "\n";
|
|
|
|
}
|
|
|
|
|
2012-10-28 16:47:41 +00:00
|
|
|
/**
|
|
|
|
* Generate links based on output format and passed properties
|
|
|
|
* $event EchoEvent
|
|
|
|
* $message Message
|
|
|
|
* $props array
|
|
|
|
*/
|
|
|
|
protected function setTitleLink( $event, $message, $props = array() ) {
|
2014-08-16 06:41:39 +00:00
|
|
|
$title = $event->getTitle();
|
|
|
|
if ( !$title ) {
|
2013-08-27 00:55:45 +00:00
|
|
|
$message->params( $this->getMessage( 'echo-no-title' )->text() );
|
2012-10-28 16:47:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-19 12:45:34 +00:00
|
|
|
if ( !isset( $props['fragment'] ) ) {
|
|
|
|
$props['fragment'] = $this->formatSubjectAnchor( $event );
|
|
|
|
}
|
|
|
|
|
2014-08-16 06:41:39 +00:00
|
|
|
$link = $this->buildLinkParam( $title, $props );
|
2013-07-19 12:45:34 +00:00
|
|
|
$message->params( $link );
|
|
|
|
}
|
2012-10-28 16:47:41 +00:00
|
|
|
|
2013-07-19 12:45:34 +00:00
|
|
|
/**
|
|
|
|
* Build a link, to be used as message parameter, based on output format and
|
|
|
|
* passed properties. Return value of this function can be used as parameter
|
|
|
|
* for Message::params()
|
|
|
|
* $title Title
|
|
|
|
* $props array
|
|
|
|
*/
|
|
|
|
protected function buildLinkParam( $title, $props = array() ) {
|
2012-10-28 16:47:41 +00:00
|
|
|
$param = array();
|
|
|
|
if ( isset( $props['param'] ) ) {
|
|
|
|
$param = (array)$props['param'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $props['fragment'] ) ) {
|
2013-05-14 22:22:52 +00:00
|
|
|
$fragment = $props['fragment'];
|
2013-07-19 12:45:34 +00:00
|
|
|
$title->setFragment( "#$fragment" );
|
2012-10-28 16:47:41 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 00:22:08 +00:00
|
|
|
if ( in_array( $this->outputFormat, array( 'html', 'flyout', 'htmlemail' ) ) ) {
|
|
|
|
$attribs = array();
|
|
|
|
if ( isset( $props['attribs'] ) ) {
|
|
|
|
$attribs = (array)$props['attribs'];
|
2012-10-28 16:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $props['linkText'] ) ) {
|
|
|
|
$linkText = $props['linkText'];
|
|
|
|
} else {
|
|
|
|
$linkText = htmlspecialchars( $title->getPrefixedText() );
|
|
|
|
}
|
|
|
|
|
2013-06-24 00:22:08 +00:00
|
|
|
$options = array();
|
|
|
|
if ( $this->outputFormat === 'htmlemail' ) {
|
|
|
|
$options = array( 'https' );
|
2013-05-09 18:40:05 +00:00
|
|
|
}
|
2013-06-24 00:22:08 +00:00
|
|
|
|
2013-07-19 12:45:34 +00:00
|
|
|
return array( Message::rawParam( Linker::link( $title, $linkText, $attribs, $param, $options ) ) );
|
2013-06-24 00:22:08 +00:00
|
|
|
} elseif ( $this->outputFormat === 'email' ) {
|
|
|
|
$url = $title->getFullURL( $param, false, PROTO_HTTPS );
|
2013-07-19 12:45:34 +00:00
|
|
|
return $this->sanitizeEmailLink( $url );
|
2012-10-28 16:47:41 +00:00
|
|
|
} else {
|
2013-07-19 12:45:34 +00:00
|
|
|
return $title->getFullURL( $param );
|
2012-10-28 16:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-24 00:22:08 +00:00
|
|
|
/**
|
|
|
|
* Plain text email in some mail client is misinterpreting the ending
|
|
|
|
* punctuation, this function would encode the last character
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
2013-06-24 00:22:08 +00:00
|
|
|
* @param $url string
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
|
|
|
* @return string
|
2013-06-24 00:22:08 +00:00
|
|
|
*/
|
|
|
|
public function sanitizeEmailLink( $url ) {
|
|
|
|
// $url should contain all ascii characters now, it's safe to use substr()
|
|
|
|
$lastChar = substr( $url, -1 );
|
|
|
|
if ( $lastChar && !ctype_alnum( $lastChar ) ) {
|
|
|
|
$lastChar = str_replace(
|
|
|
|
array( '.', '-', '(', ';', '!', ':', ',' ),
|
|
|
|
array( '%2E', '%2D', '%28', '%3B', '%21', '%3A', '%2C' ),
|
|
|
|
$lastChar
|
|
|
|
);
|
|
|
|
$url = substr( $url, 0, -1 ) . $lastChar;
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
/**
|
|
|
|
* Get raw bundle data for an event so it can be manipulated
|
2014-07-18 03:58:21 +00:00
|
|
|
* @param EchoEvent
|
|
|
|
* @param User
|
|
|
|
* @param string deprecated
|
|
|
|
* @return EchoEvent[]|bool
|
2013-01-15 23:21:39 +00:00
|
|
|
*/
|
2013-03-06 00:04:48 +00:00
|
|
|
protected function getRawBundleData( $event, $user, $type ) {
|
2014-07-18 03:58:21 +00:00
|
|
|
// We should keep bundling for events as long as it has bundle hash
|
|
|
|
// even for events with bundling switched to off, this is mainly for
|
|
|
|
// historical data
|
2013-01-15 23:21:39 +00:00
|
|
|
if ( !$event->getBundleHash() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-14 18:46:26 +00:00
|
|
|
$eventMapper = new EchoEventMapper();
|
2014-07-18 03:58:21 +00:00
|
|
|
$events = $eventMapper->fetchByUserBundleHash(
|
|
|
|
$user, $event->getBundleHash(), $this->distributionType, 'DESC', self::$maxRawBundleData
|
|
|
|
);
|
2013-10-02 22:28:22 +00:00
|
|
|
|
2014-07-18 03:58:21 +00:00
|
|
|
if ( $events ) {
|
|
|
|
$this->bundleData['raw-data-count'] += count( $events );
|
|
|
|
// Distribution types other than web include the base event
|
|
|
|
// in the result already, decrement it by one
|
2013-09-26 23:25:46 +00:00
|
|
|
if ( $this->distributionType !== 'web' ) {
|
2013-10-02 22:28:22 +00:00
|
|
|
$this->bundleData['raw-data-count']--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-18 03:58:21 +00:00
|
|
|
return $events;
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct the bundle data for an event, by default, the group iterator
|
|
|
|
* is agent, eg, by user A and x others. custom formatter can overwrite
|
|
|
|
* this function to use a differnt group iterator such as title, namespace
|
2014-07-18 03:58:21 +00:00
|
|
|
*
|
|
|
|
* @param EchoEvent
|
|
|
|
* @param User
|
|
|
|
* @param string deprecated
|
2013-11-23 05:31:26 +00:00
|
|
|
* @throws MWException
|
2013-01-15 23:21:39 +00:00
|
|
|
*/
|
2013-03-06 00:04:48 +00:00
|
|
|
protected function generateBundleData( $event, $user, $type ) {
|
|
|
|
$data = $this->getRawBundleData( $event, $user, $type );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
2013-09-26 23:25:46 +00:00
|
|
|
// Default the last raw data to false, which means there is no
|
|
|
|
// bundle data other than the base
|
|
|
|
$this->bundleData['last-raw-data'] = false;
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
if ( !$data ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$agents = array();
|
|
|
|
$agent = $event->getAgent();
|
|
|
|
if ( $agent ) {
|
|
|
|
if ( $agent->isAnon() ) {
|
|
|
|
$agents[$agent->getName()] = $agent->getName();
|
|
|
|
} else {
|
|
|
|
$agents[$agent->getId()] = $agent->getId();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new MWException( "Agent is required for bundling notification!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize with 1 for the agent of current event
|
|
|
|
$count = 1;
|
2014-07-18 03:58:21 +00:00
|
|
|
foreach ( $data as $evt ) {
|
|
|
|
if ( $evt->getAgent() ) {
|
|
|
|
if ( $evt->getAgent()->isAnon() ) {
|
|
|
|
$key = $evt->getAgent()->getName();
|
|
|
|
} else {
|
|
|
|
$key = $evt->getAgent()->getId();
|
|
|
|
}
|
|
|
|
if ( !isset( $agents[$key] ) ) {
|
|
|
|
$agents[$key] = $key;
|
|
|
|
$count++;
|
|
|
|
}
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
2014-07-18 03:58:21 +00:00
|
|
|
$this->bundleData['last-raw-data'] = $evt;
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->bundleData['agent-other-count'] = $count - 1;
|
|
|
|
if ( $count > 1 ) {
|
|
|
|
$this->bundleData['use-bundle'] = true;
|
|
|
|
}
|
2013-09-26 23:25:46 +00:00
|
|
|
|
|
|
|
// If there is more raw data than we requested, that means we have not
|
|
|
|
// retrieved the very last raw record, set the key back to null
|
2014-07-18 03:58:21 +00:00
|
|
|
if ( count( $data ) >= self::$maxRawBundleData ) {
|
2013-09-26 23:25:46 +00:00
|
|
|
$this->bundleData['last-raw-data'] = null;
|
|
|
|
}
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getBundleData() {
|
|
|
|
return $this->bundleData;
|
|
|
|
}
|
|
|
|
|
2012-11-28 02:17:52 +00:00
|
|
|
/**
|
|
|
|
* Convert the parameters into real values and pass them into the message
|
|
|
|
*
|
|
|
|
* @param $params array
|
|
|
|
* @param $event EchoEvent
|
|
|
|
* @param $message Message
|
|
|
|
* @param $user User
|
|
|
|
*/
|
2012-07-31 00:29:49 +00:00
|
|
|
protected function processParams( $params, $event, $message, $user ) {
|
2012-08-31 21:50:46 +00:00
|
|
|
foreach ( $params as $param ) {
|
2012-05-17 15:36:18 +00:00
|
|
|
$this->processParam( $event, $param, $message, $user );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-15 22:38:57 +00:00
|
|
|
/**
|
2014-09-11 21:02:28 +00:00
|
|
|
* Process a parameter that should be escaped for display except for use
|
|
|
|
* cases like plain text email and email subject
|
|
|
|
*
|
2013-10-15 22:38:57 +00:00
|
|
|
* @param $message Message
|
|
|
|
* @param $paramContent string
|
|
|
|
*/
|
|
|
|
protected function processParamEscaped( $message, $paramContent ) {
|
2014-09-11 21:02:28 +00:00
|
|
|
// Plain text email and email subject do not need to be escaped
|
|
|
|
if ( $this->outputFormat !== 'email' && $this->distributionType !== 'emailsubject' ) {
|
2013-10-15 22:38:57 +00:00
|
|
|
$paramContent = htmlspecialchars( $paramContent );
|
|
|
|
}
|
|
|
|
|
|
|
|
$message->rawParams( $paramContent );
|
|
|
|
}
|
|
|
|
|
2013-06-12 23:18:26 +00:00
|
|
|
/**
|
|
|
|
* Get the URL for the primary or secondary link for an event
|
|
|
|
*
|
|
|
|
* @param EchoEvent $event
|
|
|
|
* @param User $user The user receiving the notification
|
|
|
|
* @param String $rank 'primary' or 'secondary' (default is 'primary')
|
|
|
|
* @param boolean $local True to return a local (relative) URL, false to
|
|
|
|
* return a full URL (for email for example) (default is true)
|
|
|
|
* @param boolean $urlOnly True to return only the URL without the <a> tag,
|
|
|
|
* false to return a full anchor link (default is false)
|
|
|
|
* @param String $style A style attribute to apply to the anchor, e.g.
|
|
|
|
* 'border: 1px solid green; text-decoration: none;' (optional)
|
|
|
|
* @return String URL for link, or HTML for anchor tag, or empty string
|
|
|
|
*/
|
2013-06-24 00:22:08 +00:00
|
|
|
public function getLink( $event, $user, $rank = 'primary', $local = true, $urlOnly = false, $style = '' ) {
|
2013-06-12 23:18:26 +00:00
|
|
|
$destination = $event->getLinkDestination( $rank );
|
|
|
|
if ( !$destination ) {
|
|
|
|
return '';
|
|
|
|
}
|
2013-06-24 00:22:08 +00:00
|
|
|
|
2013-06-12 23:18:26 +00:00
|
|
|
// Get link parameters based on the destination
|
|
|
|
list( $target, $query ) = $this->getLinkParams( $event, $user, $destination );
|
2013-12-09 22:40:48 +00:00
|
|
|
// Note that $target can be a Title object or a raw url
|
2013-06-12 23:18:26 +00:00
|
|
|
if ( !$target ) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if ( $urlOnly ) {
|
2013-12-09 22:40:48 +00:00
|
|
|
if ( is_string( $target ) ) {
|
|
|
|
// A raw url was passed back
|
|
|
|
return $target;
|
|
|
|
}
|
2013-06-12 23:18:26 +00:00
|
|
|
if ( $local ) {
|
|
|
|
return $target->getLinkURL( $query );
|
|
|
|
} else {
|
2013-06-24 00:22:08 +00:00
|
|
|
return $target->getFullURL( $query, false, PROTO_HTTPS );
|
2013-06-12 23:18:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-08-27 00:55:45 +00:00
|
|
|
$message = $this->getMessage( $event->getLinkMessage( $rank ) )->text();
|
2013-06-12 23:18:26 +00:00
|
|
|
$attribs = array( 'class' => "mw-echo-notification-{$rank}-link" );
|
|
|
|
if ( $style ) {
|
|
|
|
$attribs['style'] = $style;
|
|
|
|
}
|
|
|
|
$options = array();
|
|
|
|
// If local is false, return an absolute url using HTTP protocol
|
|
|
|
if ( !$local ) {
|
2013-06-24 00:22:08 +00:00
|
|
|
$options[] = 'https';
|
2013-06-12 23:18:26 +00:00
|
|
|
}
|
2013-12-09 22:40:48 +00:00
|
|
|
if ( is_string( $target ) ) {
|
|
|
|
$attribs['href'] = wfAppendQuery( $target, $query );
|
|
|
|
return Html::element( 'a', $attribs, $message );
|
|
|
|
} else {
|
|
|
|
return Linker::link( $target, $message, $attribs, $query, $options );
|
|
|
|
}
|
|
|
|
|
2013-06-12 23:18:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for getLink()
|
|
|
|
*
|
|
|
|
* @param EchoEvent $event
|
|
|
|
* @param User $user The user receiving the notification
|
|
|
|
* @param String $destination The destination type for the link, e.g. 'agent'
|
2013-12-09 22:40:48 +00:00
|
|
|
* @return Array including target and query parameters. Note that target can
|
|
|
|
* be either a Title or a full url
|
2013-06-12 23:18:26 +00:00
|
|
|
*/
|
|
|
|
protected function getLinkParams( $event, $user, $destination ) {
|
|
|
|
$target = null;
|
2014-08-16 06:41:39 +00:00
|
|
|
$query = array();
|
|
|
|
$title = $event->getTitle();
|
2013-06-12 23:18:26 +00:00
|
|
|
// Set up link parameters based on the destination
|
|
|
|
switch ( $destination ) {
|
|
|
|
case 'agent':
|
|
|
|
if ( $event->getAgent() ) {
|
|
|
|
$target = $event->getAgent()->getUserPage();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'title':
|
2014-08-16 06:41:39 +00:00
|
|
|
$target = $title;
|
2013-06-12 23:18:26 +00:00
|
|
|
break;
|
|
|
|
case 'section':
|
2014-08-16 06:41:39 +00:00
|
|
|
$target = $title;
|
2013-06-12 23:18:26 +00:00
|
|
|
if ( $target ) {
|
|
|
|
$fragment = $this->formatSubjectAnchor( $event );
|
|
|
|
if ( $fragment ) {
|
|
|
|
$target->setFragment( "#$fragment" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'diff':
|
|
|
|
$eventData = $event->getExtra();
|
2014-08-16 06:41:39 +00:00
|
|
|
if ( isset( $eventData['revid'] ) && $title ) {
|
|
|
|
$target = $title;
|
2013-07-02 21:20:01 +00:00
|
|
|
// Explicitly set fragment to empty string for diff links, $title is
|
|
|
|
// passed around by reference, it may end up using fragment set from
|
|
|
|
// other parameters
|
|
|
|
$target->setFragment( '#' );
|
2013-06-12 23:18:26 +00:00
|
|
|
$query = array(
|
2013-09-26 23:25:46 +00:00
|
|
|
'oldid' => 'prev',
|
|
|
|
'diff' => $eventData['revid'],
|
2013-06-12 23:18:26 +00:00
|
|
|
);
|
2013-09-26 23:25:46 +00:00
|
|
|
|
2014-07-09 19:02:19 +00:00
|
|
|
$data = $this->getBundleLastRawData( $event, $user );
|
|
|
|
if ( $data ) {
|
2014-07-18 03:58:21 +00:00
|
|
|
$extra = $data->getExtra();
|
2014-07-09 19:02:19 +00:00
|
|
|
if ( isset( $extra['revid'] ) ) {
|
|
|
|
$oldId = $target->getPreviousRevisionID( $extra['revid'] );
|
|
|
|
// The diff engine doesn't provide a way to diff against a null revision.
|
|
|
|
// In this case, just fall back old id to the first revision
|
|
|
|
if ( !$oldId ) {
|
|
|
|
$oldId = $extra['revid'];
|
2013-09-26 23:25:46 +00:00
|
|
|
}
|
2014-07-09 19:02:19 +00:00
|
|
|
if ( $oldId < $eventData['revid'] ) {
|
|
|
|
$query['oldid'] = $oldId;
|
2013-09-26 23:25:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-12 23:18:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return array( $target, $query );
|
|
|
|
}
|
|
|
|
|
2014-07-09 19:02:19 +00:00
|
|
|
/**
|
2014-07-18 03:58:21 +00:00
|
|
|
* Get the last echo event in a set of bundling data. When bundling notifications,
|
2014-07-09 19:02:19 +00:00
|
|
|
* we mostly only need the very first notification, which is the bundle base.
|
|
|
|
* In some cases, like talk notification diff, Flow notificaiton first unread post,
|
|
|
|
* we need data from the very last notification.
|
|
|
|
*
|
|
|
|
* @param EchoEvent
|
|
|
|
* @param User
|
2014-07-18 03:58:21 +00:00
|
|
|
* @return EchoEvent|boolean false for none
|
2014-07-09 19:02:19 +00:00
|
|
|
*/
|
2014-07-18 03:58:21 +00:00
|
|
|
protected function getBundleLastRawData( EchoEvent $event, User $user ) {
|
2014-07-09 19:02:19 +00:00
|
|
|
if ( $event->getBundleHash() ) {
|
|
|
|
// First try cache data from preivous query
|
|
|
|
if ( isset( $this->bundleData['last-raw-data'] ) ) {
|
|
|
|
$data = $this->bundleData['last-raw-data'];
|
|
|
|
// Then try to query the storage
|
|
|
|
} else {
|
2014-08-14 18:46:26 +00:00
|
|
|
$eventMapper = new EchoEventMapper();
|
2014-07-18 03:58:21 +00:00
|
|
|
$data = $eventMapper->fetchByUserBundleHash(
|
|
|
|
$user, $event->getBundleHash(), $this->distributionType, 'ASC', 1
|
|
|
|
);
|
2014-07-09 19:02:19 +00:00
|
|
|
if ( $data ) {
|
2014-07-18 03:58:21 +00:00
|
|
|
$data = reset( $data );
|
2014-07-09 19:02:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $data ) {
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-24 00:22:08 +00:00
|
|
|
/**
|
|
|
|
* Get the style for standard links in html email
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHTMLLinkStyle() {
|
|
|
|
return 'text-decoration: none; color: #3A68B0;';
|
|
|
|
}
|
|
|
|
|
2012-09-26 05:09:43 +00:00
|
|
|
/**
|
2012-11-28 02:17:52 +00:00
|
|
|
* Helper function for processParams()
|
|
|
|
*
|
2012-09-26 05:09:43 +00:00
|
|
|
* @param $event EchoEvent
|
2013-06-24 00:22:08 +00:00
|
|
|
* @param $param string
|
2012-09-26 05:09:43 +00:00
|
|
|
* @param $message Message
|
|
|
|
* @param $user User
|
|
|
|
* @throws MWException
|
|
|
|
*/
|
2012-10-23 21:57:22 +00:00
|
|
|
protected function processParam( $event, $param, $message, $user ) {
|
2012-04-27 15:14:24 +00:00
|
|
|
if ( $param === 'agent' ) {
|
2013-06-24 00:22:08 +00:00
|
|
|
$agent = $event->getAgent();
|
|
|
|
if ( !$agent ) {
|
2013-08-27 00:55:45 +00:00
|
|
|
$message->params( $this->getMessage( 'echo-no-agent' )->text() );
|
2013-05-08 18:11:44 +00:00
|
|
|
} elseif ( !$event->userCan( Revision::DELETED_USER, $user ) ) {
|
2013-08-27 00:55:45 +00:00
|
|
|
$message->params( $this->getMessage( 'rev-deleted-user' )->text() );
|
2012-04-27 15:14:24 +00:00
|
|
|
} else {
|
2013-06-24 00:22:08 +00:00
|
|
|
if ( $this->outputFormat === 'htmlemail' ) {
|
|
|
|
$message->rawParams(
|
|
|
|
Linker::link(
|
|
|
|
$agent->getUserPage(),
|
|
|
|
$agent->getName(),
|
|
|
|
array( 'style' => $this->getHTMLLinkStyle() ),
|
|
|
|
array(),
|
|
|
|
array( 'https' )
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$message->params( $agent->getName() );
|
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2013-01-15 23:21:39 +00:00
|
|
|
// example: {7} others, {99+} others
|
2013-12-20 10:53:23 +00:00
|
|
|
} elseif ( $param === 'agent-other-display' ) {
|
2013-01-15 23:21:39 +00:00
|
|
|
global $wgEchoMaxNotificationCount;
|
|
|
|
|
|
|
|
if ( $this->bundleData['agent-other-count'] > $wgEchoMaxNotificationCount ) {
|
|
|
|
$message->params(
|
2013-08-27 00:55:45 +00:00
|
|
|
$this->getMessage( 'echo-notification-count' )
|
2013-12-20 10:53:23 +00:00
|
|
|
->numParams( $wgEchoMaxNotificationCount )
|
2013-01-15 23:21:39 +00:00
|
|
|
->text()
|
|
|
|
);
|
|
|
|
} else {
|
2013-12-20 10:53:23 +00:00
|
|
|
$message->numParams( $this->bundleData['agent-other-count'] );
|
2013-01-15 23:21:39 +00:00
|
|
|
}
|
|
|
|
// the number used for plural support
|
2013-12-20 10:53:23 +00:00
|
|
|
} elseif ( $param === 'agent-other-count' ) {
|
2013-01-15 23:21:39 +00:00
|
|
|
$message->params( $this->bundleData['agent-other-count'] );
|
2012-05-17 15:36:18 +00:00
|
|
|
} elseif ( $param === 'user' ) {
|
|
|
|
$message->params( $user->getName() );
|
2012-04-27 15:14:24 +00:00
|
|
|
} elseif ( $param === 'title' ) {
|
2014-08-16 06:41:39 +00:00
|
|
|
$title = $event->getTitle();
|
|
|
|
if ( !$title ) {
|
2013-08-27 00:55:45 +00:00
|
|
|
$message->params( $this->getMessage( 'echo-no-title' )->text() );
|
2012-04-27 15:14:24 +00:00
|
|
|
} else {
|
2013-06-24 00:22:08 +00:00
|
|
|
if ( $this->outputFormat === 'htmlemail' ) {
|
|
|
|
$props = array (
|
|
|
|
'attribs' => array( 'style' => $this->getHTMLLinkStyle() )
|
|
|
|
);
|
|
|
|
$this->setTitleLink( $event, $message, $props );
|
|
|
|
} else {
|
2014-08-16 06:41:39 +00:00
|
|
|
$message->params( $this->formatTitle( $title ) );
|
2013-06-24 00:22:08 +00:00
|
|
|
}
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
2013-03-27 22:47:54 +00:00
|
|
|
} elseif ( $param === 'titlelink' ) {
|
|
|
|
$this->setTitleLink( $event, $message );
|
2012-10-25 20:39:41 +00:00
|
|
|
} elseif ( $param === 'text-notification' ) {
|
2012-07-31 00:29:49 +00:00
|
|
|
$oldOutputFormat = $this->outputFormat;
|
2012-08-30 16:04:39 +00:00
|
|
|
$this->setOutputFormat( 'text' );
|
2012-07-31 00:29:49 +00:00
|
|
|
// $type is ignored in this class
|
|
|
|
$textNotification = $this->format( $event, $user, '' );
|
|
|
|
$this->setOutputFormat( $oldOutputFormat );
|
|
|
|
|
|
|
|
$message->params( $textNotification );
|
2012-05-17 15:36:18 +00:00
|
|
|
} else {
|
|
|
|
throw new MWException( "Unrecognised parameter $param" );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-24 00:22:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Getter method
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
2013-06-24 00:22:08 +00:00
|
|
|
* @param $key string
|
2014-05-27 18:28:37 +00:00
|
|
|
*
|
|
|
|
* @throws MWException
|
2013-06-24 00:22:08 +00:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function getValue( $key ) {
|
|
|
|
if ( !property_exists( $this, $key ) ) {
|
|
|
|
throw new MWException( "Call to non-existing property $key in " . get_class( $this ) );
|
|
|
|
}
|
|
|
|
return $this->$key;
|
|
|
|
}
|
2013-08-27 00:55:45 +00:00
|
|
|
|
2012-07-26 17:23:18 +00:00
|
|
|
}
|