2013-03-18 19:56:12 +00:00
|
|
|
<?php
|
2016-06-16 16:12:38 +00:00
|
|
|
|
2023-09-28 21:14:29 +00:00
|
|
|
// phpcs:disable MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
|
|
|
|
|
2021-03-14 03:43:32 +00:00
|
|
|
namespace MediaWiki\Extension\Thanks;
|
|
|
|
|
|
|
|
use ApiModuleManager;
|
|
|
|
use Article;
|
|
|
|
use DatabaseLogEntry;
|
|
|
|
use DifferenceEngine;
|
|
|
|
use ExtensionRegistry;
|
2023-11-07 21:55:06 +00:00
|
|
|
use GenderCache;
|
2023-09-28 21:14:29 +00:00
|
|
|
use IContextSource;
|
2021-03-14 03:43:32 +00:00
|
|
|
use LogEventsList;
|
|
|
|
use LogPage;
|
2023-09-28 21:14:29 +00:00
|
|
|
use MediaWiki\Api\Hook\ApiMain__moduleManagerHook;
|
|
|
|
use MediaWiki\Auth\Hook\LocalUserCreatedHook;
|
|
|
|
use MediaWiki\Block\Hook\GetAllBlockActionsHook;
|
2023-11-07 21:55:06 +00:00
|
|
|
use MediaWiki\Config\Config;
|
2024-01-04 21:22:56 +00:00
|
|
|
use MediaWiki\Config\ConfigException;
|
2023-09-28 21:14:29 +00:00
|
|
|
use MediaWiki\Diff\Hook\DifferenceEngineViewHeaderHook;
|
|
|
|
use MediaWiki\Diff\Hook\DiffToolsHook;
|
2023-05-19 11:38:58 +00:00
|
|
|
use MediaWiki\Extension\Thanks\Api\ApiFlowThank;
|
2023-09-28 21:14:29 +00:00
|
|
|
use MediaWiki\Hook\BeforePageDisplayHook;
|
|
|
|
use MediaWiki\Hook\GetLogTypesOnUserHook;
|
|
|
|
use MediaWiki\Hook\HistoryToolsHook;
|
|
|
|
use MediaWiki\Hook\LogEventsListLineEndingHook;
|
|
|
|
use MediaWiki\Hook\PageHistoryBeforeListHook;
|
2024-01-04 21:22:56 +00:00
|
|
|
use MediaWiki\Html\Html;
|
2020-05-04 22:48:20 +00:00
|
|
|
use MediaWiki\Linker\LinkTarget;
|
2024-01-04 21:22:56 +00:00
|
|
|
use MediaWiki\Output\OutputPage;
|
2023-11-07 21:55:06 +00:00
|
|
|
use MediaWiki\Permissions\PermissionManager;
|
|
|
|
use MediaWiki\Revision\RevisionLookup;
|
2020-05-04 22:48:20 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
2024-01-04 21:22:56 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2023-08-19 04:19:52 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-11-07 21:55:06 +00:00
|
|
|
use MediaWiki\User\Options\UserOptionsManager;
|
2024-01-04 21:22:56 +00:00
|
|
|
use MediaWiki\User\User;
|
2023-11-07 21:55:06 +00:00
|
|
|
use MediaWiki\User\UserFactory;
|
2020-06-15 21:35:45 +00:00
|
|
|
use MediaWiki\User\UserIdentity;
|
2023-09-18 22:34:23 +00:00
|
|
|
use RequestContext;
|
2021-03-14 03:43:32 +00:00
|
|
|
use Skin;
|
2018-02-06 17:01:25 +00:00
|
|
|
|
2013-03-18 19:56:12 +00:00
|
|
|
/**
|
|
|
|
* Hooks for Thanks extension
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @ingroup Extensions
|
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
class Hooks implements
|
|
|
|
ApiMain__moduleManagerHook,
|
|
|
|
BeforePageDisplayHook,
|
|
|
|
DiffToolsHook,
|
|
|
|
DifferenceEngineViewHeaderHook,
|
|
|
|
GetAllBlockActionsHook,
|
|
|
|
GetLogTypesOnUserHook,
|
|
|
|
HistoryToolsHook,
|
|
|
|
LocalUserCreatedHook,
|
|
|
|
LogEventsListLineEndingHook,
|
|
|
|
PageHistoryBeforeListHook
|
|
|
|
{
|
2023-11-07 21:55:06 +00:00
|
|
|
private Config $config;
|
|
|
|
private GenderCache $genderCache;
|
|
|
|
private PermissionManager $permissionManager;
|
|
|
|
private RevisionLookup $revisionLookup;
|
|
|
|
private UserFactory $userFactory;
|
|
|
|
private UserOptionsManager $userOptionsManager;
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
Config $config,
|
|
|
|
GenderCache $genderCache,
|
|
|
|
PermissionManager $permissionManager,
|
|
|
|
RevisionLookup $revisionLookup,
|
|
|
|
UserFactory $userFactory,
|
|
|
|
UserOptionsManager $userOptionsManager
|
|
|
|
) {
|
|
|
|
$this->config = $config;
|
|
|
|
$this->genderCache = $genderCache;
|
|
|
|
$this->permissionManager = $permissionManager;
|
|
|
|
$this->revisionLookup = $revisionLookup;
|
|
|
|
$this->userFactory = $userFactory;
|
|
|
|
$this->userOptionsManager = $userOptionsManager;
|
|
|
|
}
|
2018-02-09 07:09:43 +00:00
|
|
|
|
2013-03-18 19:56:12 +00:00
|
|
|
/**
|
2021-06-29 02:23:36 +00:00
|
|
|
* Handler for the HistoryTools hook
|
2019-08-30 01:05:07 +00:00
|
|
|
*
|
2021-06-29 02:23:36 +00:00
|
|
|
* @param RevisionRecord $revisionRecord
|
|
|
|
* @param array &$links
|
|
|
|
* @param RevisionRecord|null $oldRevisionRecord
|
|
|
|
* @param UserIdentity $userIdentity
|
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onHistoryTools(
|
|
|
|
$revisionRecord,
|
|
|
|
&$links,
|
|
|
|
$oldRevisionRecord,
|
|
|
|
$userIdentity
|
2021-06-29 02:23:36 +00:00
|
|
|
) {
|
2023-11-07 21:55:06 +00:00
|
|
|
$this->insertThankLink( $revisionRecord,
|
2021-06-29 02:23:36 +00:00
|
|
|
$links, $userIdentity );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for the DiffTools hook
|
|
|
|
*
|
|
|
|
* @param RevisionRecord $revisionRecord
|
|
|
|
* @param array &$links
|
|
|
|
* @param RevisionRecord|null $oldRevisionRecord
|
|
|
|
* @param UserIdentity $userIdentity
|
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onDiffTools(
|
|
|
|
$revisionRecord,
|
|
|
|
&$links,
|
|
|
|
$oldRevisionRecord,
|
|
|
|
$userIdentity
|
2021-06-29 02:23:36 +00:00
|
|
|
) {
|
|
|
|
// Don't allow thanking for a diff that includes multiple revisions
|
|
|
|
// This does a query that is too expensive for history rows (T284274)
|
2023-11-07 21:55:06 +00:00
|
|
|
$previous = $this->revisionLookup->getPreviousRevision( $revisionRecord );
|
2021-06-29 02:23:36 +00:00
|
|
|
if ( $oldRevisionRecord && $previous &&
|
|
|
|
$previous->getId() !== $oldRevisionRecord->getId()
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-07 21:55:06 +00:00
|
|
|
$this->insertThankLink( $revisionRecord,
|
2023-09-18 22:34:23 +00:00
|
|
|
$links, $userIdentity, true );
|
2021-06-29 02:23:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-30 01:05:07 +00:00
|
|
|
* Insert a 'thank' link into revision interface, if the user is allowed to thank.
|
|
|
|
*
|
2020-06-15 21:35:45 +00:00
|
|
|
* @param RevisionRecord $revisionRecord RevisionRecord object to add the thank link for
|
2017-09-24 19:54:35 +00:00
|
|
|
* @param array &$links Links to add to the revision interface
|
2020-06-15 21:35:45 +00:00
|
|
|
* @param UserIdentity $userIdentity The user performing the thanks.
|
2023-09-18 22:34:23 +00:00
|
|
|
* @param bool $isPrimaryButton whether the link/button should be progressive
|
2013-03-18 19:56:12 +00:00
|
|
|
*/
|
2023-11-07 21:55:06 +00:00
|
|
|
private function insertThankLink(
|
2020-06-15 21:35:45 +00:00
|
|
|
RevisionRecord $revisionRecord,
|
|
|
|
array &$links,
|
2023-09-18 22:34:23 +00:00
|
|
|
UserIdentity $userIdentity,
|
|
|
|
bool $isPrimaryButton = false
|
2020-06-15 21:35:45 +00:00
|
|
|
) {
|
2020-05-04 22:48:20 +00:00
|
|
|
$recipient = $revisionRecord->getUser();
|
|
|
|
if ( $recipient === null ) {
|
|
|
|
// Cannot see the user
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-07 21:55:06 +00:00
|
|
|
$user = $this->userFactory->newFromUserIdentity( $userIdentity );
|
2020-06-15 21:35:45 +00:00
|
|
|
|
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.
|
2023-09-13 21:07:52 +00:00
|
|
|
// Exclude temp users (T345679)
|
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.
|
2021-06-29 02:23:36 +00:00
|
|
|
// Don't allow thanking for a diff that includes multiple revisions
|
2022-12-22 01:38:48 +00:00
|
|
|
// Check whether we have a revision id to link to
|
2023-09-13 21:07:52 +00:00
|
|
|
if ( $user->isNamed()
|
2021-12-19 00:44:44 +00:00
|
|
|
&& !$userIdentity->equals( $recipient )
|
2023-11-07 21:55:06 +00:00
|
|
|
&& !$this->isUserBlockedFromTitle( $user, $revisionRecord->getPageAsLinkTarget() )
|
2021-04-20 15:41:21 +00:00
|
|
|
&& !self::isUserBlockedFromThanks( $user )
|
2023-11-07 21:55:06 +00:00
|
|
|
&& self::canReceiveThanks( $this->config, $this->userFactory, $recipient )
|
2020-05-04 22:48:20 +00:00
|
|
|
&& !$revisionRecord->isDeleted( RevisionRecord::DELETED_TEXT )
|
2022-12-21 16:10:22 +00:00
|
|
|
&& $revisionRecord->getId() !== 0
|
2013-03-18 19:56:12 +00:00
|
|
|
) {
|
2023-11-07 21:55:06 +00:00
|
|
|
$links[] = $this->generateThankElement(
|
2020-05-04 22:48:20 +00:00
|
|
|
$revisionRecord->getId(),
|
|
|
|
$user,
|
2023-09-18 22:34:23 +00:00
|
|
|
$recipient,
|
|
|
|
'revision',
|
|
|
|
$isPrimaryButton
|
2020-05-04 22:48:20 +00:00
|
|
|
);
|
2015-11-24 17:27:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-26 16:12:19 +00:00
|
|
|
/**
|
|
|
|
* Check whether the user is blocked from the title associated with the revision.
|
|
|
|
*
|
2019-08-30 01:05:07 +00:00
|
|
|
* This queries the replicas for a block; if 'no block' is incorrectly reported, it
|
2021-04-20 15:41:21 +00:00
|
|
|
* will be caught by ApiThank::dieOnUserBlockedFromTitle when the user attempts to thank.
|
2019-08-30 01:05:07 +00:00
|
|
|
*
|
2019-04-26 16:12:19 +00:00
|
|
|
* @param User $user
|
2020-05-04 22:48:20 +00:00
|
|
|
* @param LinkTarget $title
|
2019-04-26 16:12:19 +00:00
|
|
|
* @return bool
|
|
|
|
*/
|
2023-11-07 21:55:06 +00:00
|
|
|
private function isUserBlockedFromTitle( User $user, LinkTarget $title ) {
|
|
|
|
return $this->permissionManager->isBlockedFrom( $user, $title, true );
|
2019-04-26 16:12:19 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 15:41:21 +00:00
|
|
|
/**
|
|
|
|
* Check whether the user is blocked from giving thanks.
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
private static function isUserBlockedFromThanks( User $user ) {
|
|
|
|
$block = $user->getBlock();
|
|
|
|
return $block && ( $block->isSitewide() || $block->appliesToRight( 'thanks' ) );
|
|
|
|
}
|
|
|
|
|
2015-11-24 17:27:25 +00:00
|
|
|
/**
|
|
|
|
* Check whether a user is allowed to receive thanks or not
|
|
|
|
*
|
2023-11-07 21:55:06 +00:00
|
|
|
* @param Config $config
|
|
|
|
* @param UserFactory $userFactory
|
2021-12-19 00:44:44 +00:00
|
|
|
* @param UserIdentity $user Recipient
|
2015-11-24 17:27:25 +00:00
|
|
|
* @return bool true if allowed, false if not
|
|
|
|
*/
|
2023-11-07 21:55:06 +00:00
|
|
|
public static function canReceiveThanks(
|
|
|
|
Config $config,
|
|
|
|
UserFactory $userFactory,
|
|
|
|
UserIdentity $user
|
|
|
|
) {
|
|
|
|
$legacyUser = $userFactory->newFromUserIdentity( $user );
|
2021-12-19 00:44:44 +00:00
|
|
|
if ( !$user->isRegistered() || $legacyUser->isSystemUser() ) {
|
2015-11-24 17:27:25 +00:00
|
|
|
return false;
|
2013-03-18 19:56:12 +00:00
|
|
|
}
|
2015-11-24 17:27:25 +00:00
|
|
|
|
2023-11-07 21:55:06 +00:00
|
|
|
if ( !$config->get( 'ThanksSendToBots' ) &&
|
2023-11-07 20:42:57 +00:00
|
|
|
$legacyUser->isBot()
|
|
|
|
) {
|
2015-11-24 17:27:25 +00:00
|
|
|
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.
|
2019-08-06 12:11:26 +00:00
|
|
|
* @param User $sender User who sends thanks notification.
|
2021-12-19 00:44:44 +00:00
|
|
|
* @param UserIdentity $recipient User who receives thanks notification.
|
2018-03-29 04:41:58 +00:00
|
|
|
* @param string $type Either 'revision' or 'log'.
|
2023-09-18 22:34:23 +00:00
|
|
|
* @param bool $isPrimaryButton whether the link/button should be progressive
|
2013-10-07 20:38:51 +00:00
|
|
|
* @return string
|
2013-04-25 20:43:00 +00:00
|
|
|
*/
|
2023-11-07 21:55:06 +00:00
|
|
|
protected function generateThankElement(
|
2023-09-18 22:34:23 +00:00
|
|
|
$id, User $sender, UserIdentity $recipient, $type = 'revision',
|
|
|
|
bool $isPrimaryButton = false
|
2019-08-06 12:11:26 +00:00
|
|
|
) {
|
2023-09-18 22:34:23 +00:00
|
|
|
$useCodex = RequestContext::getMain()->getSkin()->getSkinName() === 'minerva';
|
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;
|
2023-09-18 22:34:23 +00:00
|
|
|
$class = $useCodex ? 'cdx-button cdx-button--fake-button cdx-button--fake-button--enabled' : '';
|
|
|
|
if ( $isPrimaryButton && $useCodex ) {
|
|
|
|
$class .= ' cdx-button--weight-primary cdx-button--action-progressive';
|
|
|
|
}
|
2019-08-06 12:11:26 +00:00
|
|
|
if ( $sender->getRequest()->getSessionData( "thanks-thanked-$sessionKey" ) ) {
|
2023-09-18 22:34:23 +00:00
|
|
|
$class .= ' mw-thanks-thanked';
|
|
|
|
|
2013-04-25 20:43:00 +00:00
|
|
|
return Html::element(
|
|
|
|
'span',
|
2023-09-18 22:34:23 +00:00
|
|
|
[ 'class' => $class ],
|
2019-08-06 12:11:26 +00:00
|
|
|
wfMessage( 'thanks-thanked', $sender->getName(), $recipient->getName() )->text()
|
2013-04-25 20:43:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add 'thank' link
|
2013-08-20 23:23:37 +00:00
|
|
|
$tooltip = wfMessage( 'thanks-thank-tooltip' )
|
2019-08-06 12:11:26 +00:00
|
|
|
->params( $sender->getName(), $recipient->getName() )
|
|
|
|
->text();
|
2013-04-25 20:43:00 +00:00
|
|
|
|
2023-09-18 22:34:23 +00:00
|
|
|
$class .= ' mw-thanks-thank-link';
|
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
|
|
|
[
|
2023-09-18 22:34:23 +00:00
|
|
|
'class' => $class,
|
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,
|
2023-11-07 21:55:06 +00:00
|
|
|
'data-recipient-gender' => $this->genderCache->getGenderOf( $recipient->getName(), __METHOD__ ),
|
2016-04-22 20:13:56 +00:00
|
|
|
],
|
2019-08-06 12:11:26 +00:00
|
|
|
wfMessage( 'thanks-thank', $sender->getName(), $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.
|
|
|
|
*/
|
2023-11-07 21:55:06 +00:00
|
|
|
protected function addThanksModule( OutputPage $outputPage ) {
|
|
|
|
$confirmationRequired = $this->config->get( 'ThanksConfirmationRequired' );
|
2018-03-02 05:37:16 +00:00
|
|
|
$outputPage->addModules( [ 'ext.thanks.corethank' ] );
|
|
|
|
$outputPage->addJsConfigVars( 'thanks-confirmation-required', $confirmationRequired );
|
|
|
|
}
|
|
|
|
|
2013-03-18 19:56:12 +00:00
|
|
|
/**
|
|
|
|
* Handler for PageHistoryBeforeList hook.
|
2018-10-30 16:50:28 +00:00
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/PageHistoryBeforeList
|
2020-02-18 12:56:47 +00:00
|
|
|
*
|
2023-09-28 21:14:29 +00:00
|
|
|
* @param Article $page Not used
|
|
|
|
* @param IContextSource $context RequestContext object
|
2013-03-18 19:56:12 +00:00
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onPageHistoryBeforeList( $page, $context ) {
|
2020-12-18 02:24:11 +00:00
|
|
|
if ( $context->getUser()->isRegistered() ) {
|
2023-11-07 21:55:06 +00:00
|
|
|
$this->addThanksModule( $context->getOutput() );
|
2013-03-18 19:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-24 00:41:11 +00:00
|
|
|
* Handler for DifferenceEngineViewHeader hook.
|
|
|
|
* @see https://www.mediawiki.org/wiki/Manual:Hooks/DifferenceEngineViewHeader
|
2018-02-09 07:09:43 +00:00
|
|
|
* @param DifferenceEngine $diff DifferenceEngine object that's calling.
|
2013-03-18 19:56:12 +00:00
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onDifferenceEngineViewHeader( $diff ) {
|
2020-12-18 02:24:11 +00:00
|
|
|
if ( $diff->getUser()->isRegistered() ) {
|
2023-11-07 21:55:06 +00:00
|
|
|
$this->addThanksModule( $diff->getOutput() );
|
2013-03-18 19:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-26 23:36:24 +00:00
|
|
|
/**
|
2016-05-25 18:42:20 +00:00
|
|
|
* Handler for LocalUserCreated hook
|
2018-10-30 16:50:28 +00:00
|
|
|
* @see https://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
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onLocalUserCreated( $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.
|
2023-06-01 08:53:54 +00:00
|
|
|
if ( !$user->isTemp() && !$autocreated ) {
|
2023-11-07 21:55:06 +00:00
|
|
|
$this->userOptionsManager->setOption( $user, 'echo-subscriptions-email-edit-thank', true );
|
2016-05-25 18:42:20 +00:00
|
|
|
}
|
2013-04-26 23:36:24 +00:00
|
|
|
}
|
2013-09-26 01:16:56 +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
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onGetLogTypesOnUser( &$types ) {
|
2013-11-13 02:46:18 +00:00
|
|
|
$types[] = 'thanks';
|
|
|
|
}
|
2014-02-26 02:12:47 +00:00
|
|
|
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onGetAllBlockActions( &$actions ) {
|
2021-04-20 15:41:21 +00:00
|
|
|
$actions[ 'thanks' ] = 100;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onBeforePageDisplay( $out, $skin ): void {
|
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
|
|
|
}
|
2022-12-16 00:37:46 +00:00
|
|
|
// Add to special pages where thank links appear
|
|
|
|
if (
|
|
|
|
$title->isSpecial( 'Log' ) ||
|
|
|
|
$title->isSpecial( 'Contributions' ) ||
|
|
|
|
$title->isSpecial( 'DeletedContributions' ) ||
|
|
|
|
$title->isSpecial( 'Recentchanges' ) ||
|
|
|
|
$title->isSpecial( 'Recentchangeslinked' ) ||
|
|
|
|
$title->isSpecial( 'Watchlist' )
|
|
|
|
) {
|
2023-11-07 21:55:06 +00:00
|
|
|
$this->addThanksModule( $out );
|
2018-03-02 05:37:16 +00:00
|
|
|
}
|
2014-02-26 02:12:47 +00:00
|
|
|
}
|
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
|
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onApiMain__moduleManager( $moduleManager ) {
|
2018-07-06 16:02:10 +00:00
|
|
|
if ( ExtensionRegistry::getInstance()->isLoaded( 'Flow' ) ) {
|
2015-06-25 21:25:27 +00:00
|
|
|
$moduleManager->addModule(
|
|
|
|
'flowthank',
|
|
|
|
'action',
|
2023-05-19 11:38:58 +00:00
|
|
|
[
|
|
|
|
"class" => ApiFlowThank::class,
|
|
|
|
"services" => [
|
|
|
|
"PermissionManager",
|
2023-05-26 13:02:42 +00:00
|
|
|
"ThanksLogStore"
|
2023-05-19 11:38:58 +00:00
|
|
|
]
|
|
|
|
]
|
2015-06-25 21:25:27 +00:00
|
|
|
);
|
|
|
|
}
|
2016-06-16 16:12:38 +00:00
|
|
|
}
|
2018-03-02 05:37:16 +00:00
|
|
|
|
|
|
|
/**
|
2019-08-30 01:05:07 +00:00
|
|
|
* Insert a 'thank' link into the log interface, if the user is allowed to thank.
|
|
|
|
*
|
2018-03-02 05:37:16 +00:00
|
|
|
* @link https://www.mediawiki.org/wiki/Manual:Hooks/LogEventsListLineEnding
|
|
|
|
* @param LogEventsList $page The log events list.
|
2021-03-14 03:43:32 +00:00
|
|
|
* @param string &$ret The line ending HTML, to modify.
|
2018-03-02 05:37:16 +00:00
|
|
|
* @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
|
|
|
|
*/
|
2023-09-28 21:14:29 +00:00
|
|
|
public function onLogEventsListLineEnding(
|
|
|
|
$page, &$ret, $entry, &$classes, &$attribs
|
2018-03-02 05:37:16 +00:00
|
|
|
) {
|
2019-08-06 12:11:26 +00:00
|
|
|
$user = $page->getUser();
|
2018-03-02 05:37:16 +00:00
|
|
|
|
2019-07-11 09:26:22 +00:00
|
|
|
// Don't thank if anonymous or blocked or if user is deleted from the log entry
|
2019-04-26 16:12:19 +00:00
|
|
|
if (
|
2019-08-06 12:11:26 +00:00
|
|
|
$user->isAnon()
|
2019-07-11 09:26:22 +00:00
|
|
|
|| $entry->isDeleted( LogPage::DELETED_USER )
|
2023-11-07 21:55:06 +00:00
|
|
|
|| $this->isUserBlockedFromTitle( $user, $entry->getTarget() )
|
2021-04-20 15:41:21 +00:00
|
|
|
|| self::isUserBlockedFromThanks( $user )
|
2019-04-26 16:12:19 +00:00
|
|
|
) {
|
2018-03-02 05:37:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-20 04:43:13 +00:00
|
|
|
// Make sure this log type is allowed.
|
2023-11-07 21:55:06 +00:00
|
|
|
$allowedLogTypes = $this->config->get( 'ThanksAllowedLogTypes' );
|
2021-03-20 04:43:13 +00:00
|
|
|
if ( !in_array( $entry->getType(), $allowedLogTypes )
|
|
|
|
&& !in_array( $entry->getType() . '/' . $entry->getSubtype(), $allowedLogTypes ) ) {
|
2018-03-02 05:37:16 +00:00
|
|
|
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).
|
2021-02-23 15:02:15 +00:00
|
|
|
|
2021-12-19 00:44:44 +00:00
|
|
|
$recipient = $entry->getPerformerIdentity();
|
2023-11-07 21:55:06 +00:00
|
|
|
if ( $recipient->getId() === $user->getId() ||
|
|
|
|
!self::canReceiveThanks( $this->config, $this->userFactory, $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';
|
2019-03-11 03:39:42 +00:00
|
|
|
$id = $entry->getAssociatedRevId() ?: $entry->getId();
|
2023-11-07 21:55:06 +00:00
|
|
|
$thankLink = $this->generateThankElement( $id, $user, $recipient, $type );
|
2018-03-29 04:41:58 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|