2013-03-18 19:56:12 +00:00
|
|
|
<?php
|
2016-06-16 16:12:38 +00:00
|
|
|
|
2018-02-06 17:01:25 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
|
2013-03-18 19:56:12 +00:00
|
|
|
/**
|
|
|
|
* Hooks for Thanks extension
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
|
|
|
class ThanksHooks {
|
2018-02-09 07:09:43 +00:00
|
|
|
|
2015-01-15 00:14:12 +00:00
|
|
|
/**
|
|
|
|
* ResourceLoaderTestModules hook handler
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
|
|
|
|
*
|
2018-02-09 07:09:43 +00:00
|
|
|
* @param array &$testModules The modules array to add to.
|
|
|
|
* @param ResourceLoader &$resourceLoader The resource loader.
|
2015-01-15 00:14:12 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onResourceLoaderTestModules( array &$testModules,
|
|
|
|
ResourceLoader &$resourceLoader
|
|
|
|
) {
|
|
|
|
if ( class_exists( 'SpecialMobileDiff' ) ) {
|
2016-04-22 20:13:56 +00:00
|
|
|
$testModules['qunit']['tests.ext.thanks.mobilediff'] = [
|
2018-01-30 02:21:53 +00:00
|
|
|
'localBasePath' => dirname( __DIR__ ),
|
2015-01-15 00:14:12 +00:00
|
|
|
'remoteExtPath' => 'Thanks',
|
2016-04-22 20:13:56 +00:00
|
|
|
'dependencies' => [ 'ext.thanks.mobilediff' ],
|
|
|
|
'scripts' => [
|
2015-01-15 00:14:12 +00:00
|
|
|
'tests/qunit/test_ext.thanks.mobilediff.js',
|
2016-04-22 20:13:56 +00:00
|
|
|
],
|
|
|
|
'targets' => [ 'desktop', 'mobile' ],
|
|
|
|
];
|
2015-01-15 00:14:12 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:56:12 +00:00
|
|
|
/**
|
|
|
|
* Handler for HistoryRevisionTools and DiffRevisionTools hooks.
|
|
|
|
* Inserts 'thank' link into revision interface
|
2017-09-24 19:54:35 +00:00
|
|
|
* @param Revision $rev Revision object to add the thank link for
|
|
|
|
* @param array &$links Links to add to the revision interface
|
2018-04-05 10:45:23 +00:00
|
|
|
* @param Revision|null $oldRev Revision object of the "old" revision when viewing a diff
|
2018-02-09 07:09:43 +00:00
|
|
|
* @param User $user The user performing the thanks.
|
2013-03-18 19:56:12 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2018-04-05 10:45:23 +00:00
|
|
|
public static function insertThankLink( $rev, &$links, $oldRev, User $user ) {
|
2015-11-24 17:27:25 +00:00
|
|
|
$recipientId = $rev->getUser();
|
|
|
|
$recipient = User::newFromId( $recipientId );
|
2013-03-18 19:56:12 +00:00
|
|
|
// Don't let users thank themselves.
|
2015-11-24 17:27:25 +00:00
|
|
|
// Exclude anonymous users.
|
2013-03-18 19:56:12 +00:00
|
|
|
// Exclude users who are blocked.
|
2015-11-24 17:27:25 +00:00
|
|
|
// Check whether bots are allowed to receive thanks.
|
2018-04-11 08:00:30 +00:00
|
|
|
if ( !$user->isAnon()
|
2015-12-21 10:54:08 +00:00
|
|
|
&& $recipientId !== $user->getId()
|
|
|
|
&& !$user->isBlocked()
|
2018-07-12 13:51:00 +00:00
|
|
|
&& !$user->isBlockedGlobally()
|
2015-11-24 17:27:25 +00:00
|
|
|
&& self::canReceiveThanks( $recipient )
|
2014-02-26 23:03:11 +00:00
|
|
|
&& !$rev->isDeleted( Revision::DELETED_TEXT )
|
|
|
|
&& ( !$oldRev || $rev->getParentId() == $oldRev->getId() )
|
2013-03-18 19:56:12 +00:00
|
|
|
) {
|
2018-03-02 05:37:16 +00:00
|
|
|
$links[] = self::generateThankElement( $rev->getId(), $recipient );
|
2015-11-24 17:27:25 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether a user is allowed to receive thanks or not
|
|
|
|
*
|
|
|
|
* @param User $user Recipient
|
|
|
|
* @return bool true if allowed, false if not
|
|
|
|
*/
|
|
|
|
protected static function canReceiveThanks( User $user ) {
|
|
|
|
global $wgThanksSendToBots;
|
|
|
|
|
|
|
|
if ( $user->isAnon() ) {
|
|
|
|
return false;
|
2013-03-18 19:56:12 +00:00
|
|
|
}
|
2015-11-24 17:27:25 +00:00
|
|
|
|
|
|
|
if ( !$wgThanksSendToBots && in_array( 'bot', $user->getGroups() ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:56:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-25 20:43:00 +00:00
|
|
|
/**
|
|
|
|
* Helper for self::insertThankLink
|
|
|
|
* Creates either a thank link or thanked span based on users session
|
2018-03-29 04:41:58 +00:00
|
|
|
* @param int $id Revision or log ID to generate the thank element for.
|
|
|
|
* @param User $recipient User who receives thanks notification.
|
|
|
|
* @param string $type Either 'revision' or 'log'.
|
2013-10-07 20:38:51 +00:00
|
|
|
* @return string
|
2013-04-25 20:43:00 +00:00
|
|
|
*/
|
2018-03-29 04:41:58 +00:00
|
|
|
protected static function generateThankElement( $id, $recipient, $type = 'revision' ) {
|
2013-04-25 20:43:00 +00:00
|
|
|
global $wgUser;
|
2018-03-29 04:41:58 +00:00
|
|
|
// Check if the user has already thanked for this revision or log entry.
|
|
|
|
// Session keys are backwards-compatible, and are also used in the ApiCoreThank class.
|
|
|
|
$sessionKey = ( $type === 'revision' ) ? $id : $type . $id;
|
|
|
|
if ( $wgUser->getRequest()->getSessionData( "thanks-thanked-$sessionKey" ) ) {
|
2013-04-25 20:43:00 +00:00
|
|
|
return Html::element(
|
|
|
|
'span',
|
2016-04-22 20:13:56 +00:00
|
|
|
[ 'class' => 'mw-thanks-thanked' ],
|
2015-04-22 23:21:27 +00:00
|
|
|
wfMessage( 'thanks-thanked', $wgUser, $recipient->getName() )->text()
|
2013-04-25 20:43:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-01-24 04:44:16 +00:00
|
|
|
$genderCache = MediaWikiServices::getInstance()->getGenderCache();
|
2013-04-25 20:43:00 +00:00
|
|
|
// Add 'thank' link
|
2013-08-20 23:23:37 +00:00
|
|
|
$tooltip = wfMessage( 'thanks-thank-tooltip' )
|
|
|
|
->params( $wgUser->getName(), $recipient->getName() )
|
|
|
|
->text();
|
2013-04-25 20:43:00 +00:00
|
|
|
|
2018-03-29 04:41:58 +00:00
|
|
|
$subpage = ( $type === 'revision' ) ? '' : 'Log/';
|
2013-04-25 20:43:00 +00:00
|
|
|
return Html::element(
|
|
|
|
'a',
|
2016-04-22 20:13:56 +00:00
|
|
|
[
|
2013-04-25 20:43:00 +00:00
|
|
|
'class' => 'mw-thanks-thank-link',
|
2018-03-29 04:41:58 +00:00
|
|
|
'href' => SpecialPage::getTitleFor( 'Thanks', $subpage . $id )->getFullURL(),
|
2013-04-25 20:43:00 +00:00
|
|
|
'title' => $tooltip,
|
2018-03-29 04:41:58 +00:00
|
|
|
'data-' . $type . '-id' => $id,
|
2018-01-24 04:44:16 +00:00
|
|
|
'data-recipient-gender' => $genderCache->getGenderOf( $recipient->getName(), __METHOD__ ),
|
2016-04-22 20:13:56 +00:00
|
|
|
],
|
2015-05-05 04:35:20 +00:00
|
|
|
wfMessage( 'thanks-thank', $wgUser, $recipient->getName() )->text()
|
2013-04-25 20:43:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-03-02 05:37:16 +00:00
|
|
|
/**
|
|
|
|
* @param OutputPage $outputPage The OutputPage to add the module to.
|
|
|
|
*/
|
|
|
|
protected static function addThanksModule( OutputPage $outputPage ) {
|
|
|
|
$confirmationRequired = MediaWikiServices::getInstance()
|
|
|
|
->getMainConfig()
|
|
|
|
->get( 'ThanksConfirmationRequired' );
|
|
|
|
$outputPage->addModules( [ 'ext.thanks.corethank' ] );
|
|
|
|
$outputPage->addJsConfigVars( 'thanks-confirmation-required', $confirmationRequired );
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:56:12 +00:00
|
|
|
/**
|
|
|
|
* Handler for PageHistoryBeforeList hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/PageHistoryBeforeList
|
2017-09-24 19:54:35 +00:00
|
|
|
* @param WikiPage|Article|ImagePage|CategoryPage|Page &$page The page for which the history
|
2016-04-22 20:13:56 +00:00
|
|
|
* is loading.
|
2017-09-24 19:54:35 +00:00
|
|
|
* @param RequestContext $context RequestContext object
|
2013-03-18 19:56:12 +00:00
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
|
|
|
public static function onPageHistoryBeforeList( &$page, $context ) {
|
2018-04-11 08:00:30 +00:00
|
|
|
if ( $context->getUser()->isLoggedIn() ) {
|
2018-03-02 05:37:16 +00:00
|
|
|
static::addThanksModule( $context->getOutput() );
|
2013-03-18 19:56:12 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for DiffViewHeader hook.
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/DiffViewHeader
|
2018-02-09 07:09:43 +00:00
|
|
|
* @param DifferenceEngine $diff DifferenceEngine object that's calling.
|
2017-09-24 19:54:35 +00:00
|
|
|
* @param Revision $oldRev Revision object of the "old" revision (may be null/invalid)
|
|
|
|
* @param Revision $newRev Revision object of the "new" revision
|
2013-03-18 19:56:12 +00:00
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
|
|
|
public static function onDiffViewHeader( $diff, $oldRev, $newRev ) {
|
2018-04-11 08:00:30 +00:00
|
|
|
if ( $diff->getUser()->isLoggedIn() ) {
|
2018-03-02 05:37:16 +00:00
|
|
|
static::addThanksModule( $diff->getOutput() );
|
2013-03-18 19:56:12 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-04-29 04:53:49 +00:00
|
|
|
* Add Thanks events to Echo
|
|
|
|
*
|
2017-09-24 19:54:35 +00:00
|
|
|
* @param array &$notifications array of Echo notifications
|
|
|
|
* @param array &$notificationCategories array of Echo notification categories
|
|
|
|
* @param array &$icons array of icon details
|
2013-10-07 20:38:51 +00:00
|
|
|
* @return bool
|
2013-03-18 19:56:12 +00:00
|
|
|
*/
|
2016-04-22 20:13:56 +00:00
|
|
|
public static function onBeforeCreateEchoEvent(
|
|
|
|
&$notifications, &$notificationCategories, &$icons
|
|
|
|
) {
|
|
|
|
$notificationCategories['edit-thank'] = [
|
2013-03-18 19:56:12 +00:00
|
|
|
'priority' => 3,
|
2013-05-30 20:52:39 +00:00
|
|
|
'tooltip' => 'echo-pref-tooltip-edit-thank',
|
2016-04-22 20:13:56 +00:00
|
|
|
];
|
2013-03-18 19:56:12 +00:00
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
$notifications['edit-thank'] = [
|
2013-03-18 19:56:12 +00:00
|
|
|
'category' => 'edit-thank',
|
2013-04-30 22:31:40 +00:00
|
|
|
'group' => 'positive',
|
2016-06-10 12:53:03 +00:00
|
|
|
'section' => 'message',
|
2018-02-21 03:46:30 +00:00
|
|
|
'presentation-model' => 'EchoCoreThanksPresentationModel',
|
2016-06-16 16:12:38 +00:00
|
|
|
'bundle' => [
|
|
|
|
'web' => true,
|
|
|
|
'expandable' => true,
|
|
|
|
],
|
2016-04-22 20:13:56 +00:00
|
|
|
];
|
2013-06-28 20:44:17 +00:00
|
|
|
|
2016-11-04 01:20:11 +00:00
|
|
|
if ( class_exists( Flow\FlowPresentationModel::class ) ) {
|
|
|
|
$notifications['flow-thank'] = [
|
|
|
|
'category' => 'edit-thank',
|
|
|
|
'group' => 'positive',
|
|
|
|
'section' => 'message',
|
|
|
|
'presentation-model' => 'EchoFlowThanksPresentationModel',
|
|
|
|
'bundle' => [
|
|
|
|
'web' => true,
|
|
|
|
'expandable' => true,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
2014-02-26 02:12:47 +00:00
|
|
|
|
2016-04-22 20:13:56 +00:00
|
|
|
$icons['thanks'] = [
|
2016-11-11 01:32:27 +00:00
|
|
|
'path' => [
|
2018-04-13 17:08:59 +00:00
|
|
|
'ltr' => 'Thanks/userTalk-constructive-ltr.svg',
|
|
|
|
'rtl' => 'Thanks/userTalk-constructive-rtl.svg'
|
2016-11-11 01:32:27 +00:00
|
|
|
]
|
2016-04-22 20:13:56 +00:00
|
|
|
];
|
2013-03-18 19:56:12 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add user to be notified on echo event
|
2018-02-09 07:09:43 +00:00
|
|
|
* @param EchoEvent $event The event.
|
|
|
|
* @param User[] &$users The user list to add to.
|
2013-03-27 10:45:25 +00:00
|
|
|
* @return bool
|
2013-03-18 19:56:12 +00:00
|
|
|
*/
|
|
|
|
public static function onEchoGetDefaultNotifiedUsers( $event, &$users ) {
|
|
|
|
switch ( $event->getType() ) {
|
|
|
|
case 'edit-thank':
|
2014-02-26 02:12:47 +00:00
|
|
|
case 'flow-thank':
|
2013-03-18 19:56:12 +00:00
|
|
|
$extra = $event->getExtra();
|
|
|
|
if ( !$extra || !isset( $extra['thanked-user-id'] ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$recipientId = $extra['thanked-user-id'];
|
|
|
|
$recipient = User::newFromId( $recipientId );
|
|
|
|
$users[$recipientId] = $recipient;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-04-26 23:36:24 +00:00
|
|
|
|
|
|
|
/**
|
2016-05-25 18:42:20 +00:00
|
|
|
* Handler for LocalUserCreated hook
|
|
|
|
* @see http://www.mediawiki.org/wiki/Manual:Hooks/LocalUserCreated
|
2017-09-24 19:54:35 +00:00
|
|
|
* @param User $user User object that was created.
|
|
|
|
* @param bool $autocreated True when account was auto-created
|
2013-04-26 23:36:24 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2016-05-25 18:42:20 +00:00
|
|
|
public static function onAccountCreated( $user, $autocreated ) {
|
2013-04-26 23:36:24 +00:00
|
|
|
// New users get echo preferences set that are not the default settings for existing users.
|
|
|
|
// Specifically, new users are opted into email notifications for thanks.
|
2016-05-25 18:42:20 +00:00
|
|
|
if ( !$autocreated ) {
|
|
|
|
$user->setOption( 'echo-subscriptions-email-edit-thank', true );
|
|
|
|
$user->saveSettings();
|
|
|
|
}
|
2013-04-26 23:36:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-09-26 01:16:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add thanks button to SpecialMobileDiff page
|
2017-09-24 19:54:35 +00:00
|
|
|
* @param OutputPage &$output OutputPage object
|
|
|
|
* @param MobileContext $ctx MobileContext object
|
|
|
|
* @param array $revisions Array of the two revisions that are being compared in the diff
|
2013-09-26 01:16:56 +00:00
|
|
|
* @return bool true in all cases
|
|
|
|
*/
|
2014-01-15 20:07:17 +00:00
|
|
|
public static function onBeforeSpecialMobileDiffDisplay( &$output, $ctx, $revisions ) {
|
2015-11-24 17:27:25 +00:00
|
|
|
$rev = $revisions[1];
|
|
|
|
|
2018-04-11 08:00:30 +00:00
|
|
|
// If the MobileFrontend extension is installed and the user is
|
2015-11-24 17:27:25 +00:00
|
|
|
// logged in or recipient is not a bot if bots cannot receive thanks, show a 'Thank' link.
|
|
|
|
if ( $rev
|
2013-09-26 01:16:56 +00:00
|
|
|
&& class_exists( 'SpecialMobileDiff' )
|
2015-11-24 17:27:25 +00:00
|
|
|
&& self::canReceiveThanks( User::newFromId( $rev->getUser() ) )
|
2013-09-26 01:16:56 +00:00
|
|
|
&& $output->getUser()->isLoggedIn()
|
|
|
|
) {
|
2016-04-22 20:13:56 +00:00
|
|
|
$output->addModules( [ 'ext.thanks.mobilediff' ] );
|
2015-11-24 17:27:25 +00:00
|
|
|
|
|
|
|
if ( $output->getRequest()->getSessionData( 'thanks-thanked-' . $rev->getId() ) ) {
|
|
|
|
// User already sent thanks for this revision
|
|
|
|
$output->addJsConfigVars( 'wgThanksAlreadySent', true );
|
2014-01-15 20:07:17 +00:00
|
|
|
}
|
2015-11-24 17:27:25 +00:00
|
|
|
|
2013-09-26 01:16:56 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-11-02 13:36:44 +00:00
|
|
|
|
2013-11-13 02:46:18 +00:00
|
|
|
/**
|
2018-02-09 07:09:43 +00:00
|
|
|
* Handler for GetLogTypesOnUser.
|
|
|
|
* So users can just type in a username for target and it'll work.
|
|
|
|
* @link https://www.mediawiki.org/wiki/Manual:Hooks/GetLogTypesOnUser
|
|
|
|
* @param string[] &$types The list of log types, to add to.
|
2013-11-13 02:46:18 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onGetLogTypesOnUser( array &$types ) {
|
|
|
|
$types[] = 'thanks';
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-26 02:12:47 +00:00
|
|
|
|
|
|
|
/**
|
2015-06-22 21:14:19 +00:00
|
|
|
* Handler for BeforePageDisplay. Inserts javascript to enhance thank
|
2014-07-14 19:08:43 +00:00
|
|
|
* links from static urls to in-page dialogs along with reloading
|
|
|
|
* the previously thanked state.
|
2018-02-09 07:09:43 +00:00
|
|
|
* @link https://www.mediawiki.org/wiki/Manual:Hooks/BeforePageDisplay
|
2014-02-26 02:12:47 +00:00
|
|
|
* @param OutputPage $out OutputPage object
|
2018-02-09 07:09:43 +00:00
|
|
|
* @param Skin $skin The skin in use.
|
2014-02-26 02:12:47 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2014-07-14 19:08:43 +00:00
|
|
|
public static function onBeforePageDisplay( OutputPage $out, $skin ) {
|
2015-07-30 11:11:13 +00:00
|
|
|
$title = $out->getTitle();
|
2018-03-02 05:37:16 +00:00
|
|
|
// Add to Flow boards.
|
2015-07-30 11:11:13 +00:00
|
|
|
if ( $title instanceof Title && $title->hasContentModel( 'flow-board' ) ) {
|
2014-07-14 19:08:43 +00:00
|
|
|
$out->addModules( 'ext.thanks.flowthank' );
|
2014-02-26 02:12:47 +00:00
|
|
|
}
|
2018-03-02 05:37:16 +00:00
|
|
|
// Add to Special:Log.
|
|
|
|
if ( $title->isSpecial( 'Log' ) ) {
|
|
|
|
static::addThanksModule( $out );
|
|
|
|
}
|
2014-02-26 02:12:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
2015-06-25 21:25:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Conditionally load API module 'flowthank' depending on whether or not
|
|
|
|
* Flow is installed.
|
|
|
|
*
|
|
|
|
* @param ApiModuleManager $moduleManager Module manager instance
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public static function onApiMainModuleManager( ApiModuleManager $moduleManager ) {
|
|
|
|
if ( class_exists( 'FlowHooks' ) ) {
|
|
|
|
$moduleManager->addModule(
|
|
|
|
'flowthank',
|
|
|
|
'action',
|
|
|
|
'ApiFlowThank'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-16 16:12:38 +00:00
|
|
|
|
|
|
|
/**
|
2018-02-09 07:09:43 +00:00
|
|
|
* Handler for EchoGetBundleRule hook, which defines the bundle rules for each notification.
|
2016-06-16 16:12:38 +00:00
|
|
|
*
|
2018-02-09 07:09:43 +00:00
|
|
|
* @param EchoEvent $event The event being notified.
|
|
|
|
* @param string &$bundleString Determines how the notification should be bundled.
|
2017-07-23 07:39:44 +00:00
|
|
|
* @return bool True for success
|
2016-06-16 16:12:38 +00:00
|
|
|
*/
|
|
|
|
public static function onEchoGetBundleRules( $event, &$bundleString ) {
|
|
|
|
switch ( $event->getType() ) {
|
|
|
|
case 'edit-thank':
|
2016-06-30 15:38:51 +00:00
|
|
|
$bundleString = 'edit-thank';
|
2018-05-11 14:39:11 +00:00
|
|
|
// Try to get either the revid or logid parameter.
|
|
|
|
$revOrLogId = $event->getExtraParam( 'logid' );
|
|
|
|
if ( $revOrLogId ) {
|
|
|
|
// avoid collision with revision ids
|
|
|
|
$revOrLogId = 'log' . $revOrLogId;
|
|
|
|
} else {
|
|
|
|
$revOrLogId = $event->getExtraParam( 'revid' );
|
2018-03-03 04:00:40 +00:00
|
|
|
}
|
|
|
|
if ( $revOrLogId ) {
|
|
|
|
$bundleString .= $revOrLogId;
|
2016-06-16 16:12:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'flow-thank':
|
2016-06-30 15:38:51 +00:00
|
|
|
$bundleString = 'flow-thank';
|
2016-06-16 16:12:38 +00:00
|
|
|
$postId = $event->getExtraParam( 'post-id' );
|
|
|
|
if ( $postId ) {
|
2016-06-30 15:38:51 +00:00
|
|
|
$bundleString .= $postId;
|
2016-06-16 16:12:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-03-02 05:37:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @link https://www.mediawiki.org/wiki/Manual:Hooks/LogEventsListLineEnding
|
|
|
|
* @param LogEventsList $page The log events list.
|
|
|
|
* @param string &$ret The lineending HTML, to modify.
|
|
|
|
* @param DatabaseLogEntry $entry The log entry.
|
|
|
|
* @param string[] &$classes CSS classes to add to the line.
|
|
|
|
* @param string[] &$attribs HTML attributes to add to the line.
|
|
|
|
* @throws ConfigException
|
|
|
|
*/
|
|
|
|
public static function onLogEventsListLineEnding(
|
|
|
|
LogEventsList $page, &$ret, DatabaseLogEntry $entry, &$classes, &$attribs
|
|
|
|
) {
|
|
|
|
global $wgUser;
|
|
|
|
|
2018-04-11 08:00:30 +00:00
|
|
|
// Don't thank if anonymous or blocked
|
2018-07-12 13:51:00 +00:00
|
|
|
if ( $wgUser->isAnon() || $wgUser->isBlocked() || $wgUser->isBlockedGlobally() ) {
|
2018-03-02 05:37:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure this log type is whitelisted.
|
|
|
|
$logTypeWhitelist = MediaWikiServices::getInstance()
|
|
|
|
->getMainConfig()
|
|
|
|
->get( 'ThanksLogTypeWhitelist' );
|
|
|
|
if ( !in_array( $entry->getType(), $logTypeWhitelist ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-29 04:41:58 +00:00
|
|
|
// Don't thank if no recipient,
|
|
|
|
// or if recipient is the current user or unable to receive thanks.
|
|
|
|
// Don't check for deleted revision (this avoids extraneous queries from Special:Log).
|
|
|
|
$recipient = $entry->getPerformer();
|
|
|
|
if ( !$recipient
|
|
|
|
|| $recipient->getId() === $wgUser->getId()
|
|
|
|
|| !self::canReceiveThanks( $recipient )
|
|
|
|
) {
|
2018-03-02 05:37:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-03-29 04:41:58 +00:00
|
|
|
|
|
|
|
// Create thank link either for the revision (if there is an associated revision ID)
|
|
|
|
// or the log entry.
|
|
|
|
$type = $entry->getAssociatedRevId() ? 'revision' : 'log';
|
|
|
|
$id = $entry->getAssociatedRevId() ? $entry->getAssociatedRevId() : $entry->getId();
|
|
|
|
$thankLink = self::generateThankElement( $id, $recipient, $type );
|
|
|
|
|
|
|
|
// Add parentheses to match what's done with Thanks in revision lists and diff displays.
|
|
|
|
$ret .= ' ' . wfMessage( 'parentheses' )->rawParams( $thankLink )->escaped();
|
2018-03-02 05:37:16 +00:00
|
|
|
}
|
2013-03-18 19:56:12 +00:00
|
|
|
}
|