mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Thanks
synced 2024-11-23 14:36:47 +00:00
Hooks#onLogEventsListLineEnding: Don't add link for temp users
Why: * Temp accounts cannot thank other users, so do not add the "thank" link in log entries. What: * Change condition to check if a user is not named, rather than if they are anonymous * Add an integration test to verify the behavior for anon, temp, and named users Bug: T375209 Change-Id: Idb772a3072a6dc8a9d052cebb306b558f49caf31
This commit is contained in:
parent
8f75c66cb0
commit
f2220b151e
|
@ -435,9 +435,9 @@ class Hooks implements
|
|||
) {
|
||||
$user = $page->getUser();
|
||||
|
||||
// Don't thank if anonymous or blocked or if user is deleted from the log entry
|
||||
// Don't provide thanks link if not named, blocked or if user is deleted from the log entry
|
||||
if (
|
||||
$user->isAnon()
|
||||
!$user->isNamed()
|
||||
|| $entry->isDeleted( LogPage::DELETED_USER )
|
||||
|| $this->isUserBlockedFromTitle( $user, $entry->getTarget() )
|
||||
|| self::isUserBlockedFromThanks( $user )
|
||||
|
|
53
tests/phpunit/integration/ThanksSpecialLogTest.php
Normal file
53
tests/phpunit/integration/ThanksSpecialLogTest.php
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Thanks\Tests\Integration;
|
||||
|
||||
use MediaWiki\Request\FauxRequest;
|
||||
use MediaWiki\Specials\SpecialLog;
|
||||
use SpecialPageTestBase;
|
||||
|
||||
/**
|
||||
* @covers \MediaWiki\Extension\Thanks\Hooks
|
||||
* @group Database
|
||||
*/
|
||||
class ThanksSpecialLogTest extends SpecialPageTestBase {
|
||||
|
||||
public function testDoNotShowThanksLinkToTempUsersOnSpecialLog() {
|
||||
// Create a logged event that can be thanked.
|
||||
$this->editPage( 'Test', 'Foo', '', NS_MAIN, $this->getMutableTestUser()->getUser() );
|
||||
$tempUser = $this->getServiceContainer()->getTempUserCreator()->create(
|
||||
'~2024-1', new FauxRequest()
|
||||
)->getUser();
|
||||
// Load Special:Log as a temp user, check that the thanks link doesn't appear.
|
||||
[ $html ] = $this->executeSpecialPage(
|
||||
'',
|
||||
new FauxRequest(),
|
||||
null,
|
||||
$tempUser
|
||||
);
|
||||
$this->assertStringNotContainsString( 'mw-thanks-thank-link', $html );
|
||||
// Load Special:Log as an anon user, check that the thanks link doesn't appear.
|
||||
[ $html ] = $this->executeSpecialPage();
|
||||
$this->assertStringNotContainsString( 'mw-thanks-thank-link', $html );
|
||||
// Load Special:Log as a named user, check that the thanks link does appear.
|
||||
[ $html ] = $this->executeSpecialPage(
|
||||
'',
|
||||
new FauxRequest(),
|
||||
null,
|
||||
$this->getMutableTestUser()->getUser()
|
||||
);
|
||||
$this->assertStringContainsString( 'mw-thanks-thank-link', $html );
|
||||
}
|
||||
|
||||
protected function newSpecialPage() {
|
||||
$services = $this->getServiceContainer();
|
||||
return new SpecialLog(
|
||||
$services->getLinkBatchFactory(),
|
||||
$services->getConnectionProvider(),
|
||||
$services->getActorNormalization(),
|
||||
$services->getUserIdentityLookup(),
|
||||
$services->getUserNameUtils(),
|
||||
$services->getLogFormatterFactory()
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue