2013-01-15 23:21:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom formatter for 'page-link' notifications
|
|
|
|
*/
|
|
|
|
class EchoPageLinkFormatter extends EchoBasicFormatter {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method overwrite parent method and construct the bundle iterator
|
|
|
|
* based on link from, it will be used in a message like this: Page A was
|
|
|
|
* link from Page B and X other pages
|
|
|
|
* @param $event EchoEvent
|
|
|
|
* @param $user User
|
2013-03-06 00:04:48 +00:00
|
|
|
* @param $type string Notification disytribution type
|
2013-01-15 23:21:39 +00:00
|
|
|
*/
|
2013-03-06 00:04:48 +00:00
|
|
|
protected function generateBundleData( $event, $user, $type ) {
|
2013-01-15 23:21:39 +00:00
|
|
|
global $wgEchoMaxNotificationCount;
|
|
|
|
|
2013-03-06 00:04:48 +00:00
|
|
|
$data = $this->getRawBundleData( $event, $user, $type );
|
2013-01-15 23:21:39 +00:00
|
|
|
|
|
|
|
if ( !$data ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$extra = $event->getExtra();
|
|
|
|
|
|
|
|
$linkFrom = array();
|
|
|
|
|
|
|
|
if ( $this->isTitleSet( $extra ) ) {
|
|
|
|
$linkFrom[$this->getTitleHash( $extra )] = true;
|
|
|
|
} else {
|
|
|
|
throw new MWException( "Link from title is required for bundling notification!" );
|
|
|
|
}
|
|
|
|
|
|
|
|
$count = 1;
|
|
|
|
foreach ( $data as $row ) {
|
2013-04-12 18:56:32 +00:00
|
|
|
$extra = $row->event_extra ? unserialize( $row->event_extra ) : null;
|
|
|
|
if ( !$extra ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-15 23:21:39 +00:00
|
|
|
if ( $this->isTitleSet( $extra ) ) {
|
|
|
|
$key = $this->getTitleHash( $extra );
|
|
|
|
|
|
|
|
if ( !isset( $linkFrom[$key] ) ) {
|
|
|
|
$linkFrom[$key] = true;
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( $count > $wgEchoMaxNotificationCount + 1 ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->bundleData['link-from-page-other-count'] = $count - 1;
|
|
|
|
if ( $count > 1 ) {
|
|
|
|
$this->bundleData['use-bundle'] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal function to check if link from namespace and title keys are set
|
|
|
|
* @param $extra array
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private function isTitleSet( $extra ) {
|
|
|
|
if ( isset( $extra['link-from-namespace'], $extra['link-from-title'] ) ) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal function to generate a unique md5 of namespace and title
|
|
|
|
* @param $extra array
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getTitleHash( $extra ) {
|
|
|
|
return md5( $extra['link-from-namespace'] . '-' . $extra['link-from-title'] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $event EchoEvent
|
|
|
|
* @param $param string
|
|
|
|
* @param $message Message
|
|
|
|
* @param $user User
|
|
|
|
*/
|
|
|
|
protected function processParam( $event, $param, $message, $user ) {
|
|
|
|
$extra = $event->getExtra();
|
|
|
|
switch ( $param ) {
|
|
|
|
// 'A' part in this message: link from page A and X others
|
|
|
|
case 'link-from-page':
|
|
|
|
if ( $this->isTitleSet( $extra ) ) {
|
|
|
|
$message->params(
|
|
|
|
Title::makeTitle(
|
|
|
|
$extra['link-from-namespace'],
|
|
|
|
$extra['link-from-title']
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$message->params( '' );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// example: {7} other page, {99+} other pages
|
|
|
|
case 'link-from-page-other-display':
|
|
|
|
global $wgEchoMaxNotificationCount;
|
|
|
|
|
|
|
|
if ( $this->bundleData['link-from-page-other-count'] > $wgEchoMaxNotificationCount ) {
|
|
|
|
$message->params(
|
|
|
|
wfMessage( 'echo-notification-count' )
|
|
|
|
->inLanguage( $user->getOption( 'language' ) )
|
|
|
|
->params( $wgEchoMaxNotificationCount )
|
|
|
|
->text()
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$message->params( $this->bundleData['link-from-page-other-count'] );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// the number used for plural support
|
|
|
|
case 'link-from-page-other-count':
|
|
|
|
$message->params( $this->bundleData['link-from-page-other-count'] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
parent::processParam( $event, $param, $message, $user );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|