2012-04-27 15:14:24 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class EchoHooks {
|
2012-05-17 00:29:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $updater DatabaseUpdater object
|
|
|
|
* @return true in all cases
|
|
|
|
*/
|
|
|
|
public static function getSchemaUpdates( $updater ) {
|
2012-04-27 15:14:24 +00:00
|
|
|
$dir = dirname(__FILE__);
|
|
|
|
$baseSQLFile = "$dir/echo.sql";
|
|
|
|
$updater->addExtensionTable( 'echo_subscription', $baseSQLFile );
|
|
|
|
$updater->addExtensionTable( 'echo_event', $baseSQLFile );
|
|
|
|
$updater->addExtensionTable( 'echo_notification', $baseSQLFile );
|
|
|
|
|
|
|
|
$updater->modifyField( 'echo_event', 'event_agent',
|
|
|
|
"$dir/db_patches/patch-event_agent-split.sql", true );
|
2012-05-18 01:07:30 +00:00
|
|
|
$updater->modifyField( 'echo_event', 'event_variant',
|
|
|
|
"$dir/db_patches/patch-event_variant_nullability.sql", true );
|
2012-07-27 22:16:19 +00:00
|
|
|
$updater->modifyField( 'echo_event', 'event_extra',
|
|
|
|
"$dir/db_patches/patch-event_extra-size.sql", true );
|
2012-04-27 15:14:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for EchoGetDefaultNotifiedUsers hook.
|
|
|
|
* @param $event The EchoEvent to get implicitly subscribed users for
|
|
|
|
* @param &$users Array to append implicitly subscribed users to.
|
|
|
|
* @return true in all cases
|
|
|
|
*/
|
|
|
|
public static function getDefaultNotifiedUsers( $event, &$users ) {
|
2012-04-27 15:14:24 +00:00
|
|
|
switch( $event->getType() ) {
|
|
|
|
case 'edit-user-talk':
|
|
|
|
if ( !$event->getTitle() || !$event->getTitle()->getNamespace() == NS_USER_TALK ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$username = $event->getTitle()->getText();
|
|
|
|
$user = User::newFromName( $username );
|
|
|
|
if ($user->getId()) {
|
|
|
|
$user = User::newFromName($username);
|
|
|
|
$users[$user->getId()] = $user;
|
|
|
|
}
|
|
|
|
break;
|
2012-07-27 22:16:19 +00:00
|
|
|
case 'add-comment':
|
|
|
|
case 'add-talkpage-topic':
|
|
|
|
$extraData = $event->getExtra();
|
|
|
|
|
|
|
|
if ( !isset( $extraData['revid'] ) || !$extraData['revid'] ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
$revision = Revision::newFromId( $extraData['revid'] );
|
|
|
|
|
|
|
|
$users = array_merge(
|
|
|
|
$users,
|
|
|
|
EchoDiscussionParser::getNotifiedUsersForComment($revision)
|
|
|
|
);
|
|
|
|
break;
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-08 05:27:59 +00:00
|
|
|
public static function getNotificationTypes( $subscription, $event, &$notifyTypes ) {
|
|
|
|
$type = $event->getType();
|
|
|
|
$user = $subscription->getUser();
|
|
|
|
|
|
|
|
// Figure out when to disallow email notifications
|
|
|
|
if ( $type == 'edit' ) {
|
|
|
|
if ( ! $user->getOption('enotifwatchlistpages') ) {
|
2012-07-17 00:04:27 +00:00
|
|
|
$notifyTypes = array_diff( $notifyTypes, array('email') );
|
2012-06-08 05:27:59 +00:00
|
|
|
}
|
|
|
|
} elseif ( $type == 'edit-user-talk' ) {
|
|
|
|
if ( ! $user->getOption('enotifusertalkpages') ) {
|
2012-07-17 00:04:27 +00:00
|
|
|
$notifyTypes = array_diff( $notifyTypes, array('email') );
|
2012-06-08 05:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! $user->getOption('enotifminoredits') ) {
|
|
|
|
$extra = $event->getExtra();
|
2012-07-31 00:29:49 +00:00
|
|
|
if ( !empty($extra['revid']) ) {
|
2012-06-08 05:27:59 +00:00
|
|
|
$rev = Revision::newFromID($extra['revid']);
|
|
|
|
|
|
|
|
if ( $rev->isMinor() ) {
|
2012-07-17 00:04:27 +00:00
|
|
|
$notifyTypes = array_diff( $notifyTypes, array('email') );
|
2012-06-08 05:27:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for GetPreferences hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/GetPreferences
|
|
|
|
* @param $user User to get preferences for
|
|
|
|
* @param &$preferences Preferences array
|
|
|
|
* @return true in all cases
|
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public static function getPreferences( $user, &$preferences ) {
|
|
|
|
$preferences['echo-notify-watchlist'] = array(
|
|
|
|
'type' => 'toggle',
|
|
|
|
'label-message' => 'echo-pref-notify-watchlist',
|
|
|
|
'section' => 'echo',
|
|
|
|
);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for WatchArticleComplete hook
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/WatchArticleComplete
|
|
|
|
* @param $user User who watched the Article
|
|
|
|
* @param $article Article that was watched.
|
|
|
|
* @return true in all cases
|
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public static function onWatch( $user, $article ) {
|
|
|
|
if ( ! $user->getOption('echo-notify-watchlist') ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$subscription = new EchoSubscription( $user, 'edit', $article->getTitle() );
|
|
|
|
$subscription->enableNotification('notify');
|
|
|
|
$subscription->save();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for UnwatchArticleComplete hook
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/UnwatchArticleComplete
|
|
|
|
* @param $user User who unwatched the Article
|
|
|
|
* @param $article Article that was unwatched.
|
|
|
|
* @return true in all cases
|
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public static function onUnwatch( $user, $article ) {
|
|
|
|
$subscription = new EchoSubscription( $user, 'edit', $article->getTitle() );
|
|
|
|
$subscription->disableNotification('notify');
|
|
|
|
$subscription->save();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for ArticleSaveComplete hook
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/ArticleSaveComplete
|
|
|
|
* @param $article Article edited
|
|
|
|
* @param $user User who edited
|
|
|
|
* @param $text New article text
|
|
|
|
* @param $summary Edit summary
|
|
|
|
* @param $minoredit Minor edit or not
|
|
|
|
* @param $watchthis Watch this article?
|
|
|
|
* @param $sectionanchor Section that was edited
|
|
|
|
* @param $flags Edit flags
|
|
|
|
* @param $revision Revision that was created
|
|
|
|
* @param $status Status
|
|
|
|
* @return true in all cases
|
|
|
|
*/
|
2012-04-27 15:14:24 +00:00
|
|
|
public static function onArticleSaved( &$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status ) {
|
2012-07-27 22:16:19 +00:00
|
|
|
if ( !$revision ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$event = EchoEvent::create( array(
|
|
|
|
'type' => 'edit',
|
|
|
|
'title' => $article->getTitle(),
|
|
|
|
'extra' => array('revid' => $revision->getID()),
|
|
|
|
'agent' => $user,
|
|
|
|
) );
|
|
|
|
|
|
|
|
|
|
|
|
if ( $article->getTitle()->isTalkPage() ) {
|
|
|
|
EchoDiscussionParser::generateEventsForRevision( $revision );
|
2012-04-27 15:14:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-01 10:57:09 +00:00
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for BeforePageDisplay hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
|
|
|
|
* @param $out OutputPage object
|
|
|
|
* @param $skin Skin being used.
|
|
|
|
* @return true in all cases
|
|
|
|
*/
|
2012-06-01 10:57:09 +00:00
|
|
|
static function beforePageDisplay( $out, $skin ) {
|
|
|
|
global $wgUser;
|
|
|
|
if ( !$wgUser->isAnon() ) {
|
|
|
|
$out->addModules( array('ext.echo.overlay') );
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for PersonalUrls hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/PersonalUrls
|
|
|
|
* @param &$personal_urls Array of URLs to append to.
|
|
|
|
* @param &$title Title of page being visited.
|
|
|
|
* @return true in all cases
|
|
|
|
*/
|
2012-06-01 10:57:09 +00:00
|
|
|
static function onPersonalUrls( &$personal_urls, &$title ) {
|
|
|
|
global $wgUser, $wgLang, $wgOut;
|
|
|
|
|
|
|
|
if ( $wgUser->isAnon() ) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$notificationCount = EchoNotificationController::getNotificationCount( $wgUser );
|
|
|
|
|
2012-07-31 23:29:30 +00:00
|
|
|
$msg = wfMessage( $notificationCount == 0 ? 'echo-link' : 'echo-link-new' );
|
2012-06-01 10:57:09 +00:00
|
|
|
$url = SpecialPage::getTitleFor( 'Notifications' )->getLocalURL();
|
|
|
|
|
|
|
|
$notificationsLink = array(
|
|
|
|
'href' => $url,
|
|
|
|
'text' => $msg->params($wgLang->formatNum( $notificationCount ) )->text(),
|
|
|
|
'active' => $notificationCount > 0,
|
|
|
|
);
|
|
|
|
|
|
|
|
$insertUrls = array( 'notifications' => $notificationsLink );
|
|
|
|
$personal_urls = wfArrayInsertAfter( $personal_urls, $insertUrls, 'watchlist' );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-17 22:19:32 +00:00
|
|
|
|
2012-05-17 00:29:37 +00:00
|
|
|
/**
|
|
|
|
* Handler for AbortEmailNotification hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/AbortEmailNotification
|
|
|
|
* @return true in all cases
|
|
|
|
*/
|
2012-07-17 22:19:32 +00:00
|
|
|
static function abortEmailNotification() {
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-31 21:18:16 +00:00
|
|
|
|
|
|
|
public static function makeGlobalVariablesScript( &$vars, $outputPage ) {
|
|
|
|
$user = $outputPage->getUser();
|
|
|
|
|
|
|
|
if ( ! $user->isAnon() ) {
|
|
|
|
$vars['wgEchoOverlayConfiguration'] = array(
|
|
|
|
'timestamp' => wfTimestamp( TS_UNIX, wfTimestampNow() ),
|
|
|
|
'notification-count' => EchoNotificationController::getNotificationCount( $user ),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-31 00:29:49 +00:00
|
|
|
|
|
|
|
static function getUnitTests( &$files ) {
|
|
|
|
$dir = dirname( __FILE__ ) . '/tests';
|
|
|
|
$files[] = "$dir/DiscussionParserTest.php";
|
|
|
|
}
|
2012-07-31 20:44:43 +00:00
|
|
|
|
|
|
|
static function abortNewtalkNotification( $article ) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-18 16:28:41 +00:00
|
|
|
}
|