diff --git a/includes/ProtectedVarsAccessLogger.php b/includes/ProtectedVarsAccessLogger.php index 744e6bcc7..dfd2604e8 100644 --- a/includes/ProtectedVarsAccessLogger.php +++ b/includes/ProtectedVarsAccessLogger.php @@ -3,10 +3,12 @@ namespace MediaWiki\Extension\AbuseFilter; use ManualLogEntry; +use MediaWiki\Deferred\DeferredUpdates; use MediaWiki\MediaWikiServices; use MediaWiki\Title\Title; use MediaWiki\User\ActorStore; use MediaWiki\User\UserIdentity; +use Profiler; use Psr\Log\LoggerInterface; use Wikimedia\Assert\Assert; use Wikimedia\Rdbms\DBError; @@ -104,13 +106,21 @@ class ProtectedVarsAccessLogger { if ( !$timestamp ) { $timestamp = (int)wfTimestamp(); } - $this->log( - $performer, - $target, - self::ACTION_VIEW_PROTECTED_VARIABLE_VALUE, - true, - $timestamp - ); + // Create the log on POSTSEND, as this can be called in a context of a GET request through the + // QueryAbuseLog API (T379083). + DeferredUpdates::addCallableUpdate( function () use ( $performer, $target, $timestamp ) { + // We need to create a log entry and PostSend-GET expects no writes are performed, so we need to + // silence the warnings created by this. + $trxProfiler = Profiler::instance()->getTransactionProfiler(); + $scope = $trxProfiler->silenceForScope( $trxProfiler::EXPECTATION_REPLICAS_ONLY ); + $this->log( + $performer, + $target, + self::ACTION_VIEW_PROTECTED_VARIABLE_VALUE, + true, + $timestamp + ); + } ); } /** diff --git a/tests/phpunit/integration/ProtectedVarsAccessLoggerTest.php b/tests/phpunit/integration/ProtectedVarsAccessLoggerTest.php index f5de778cc..a88e8bc6e 100644 --- a/tests/phpunit/integration/ProtectedVarsAccessLoggerTest.php +++ b/tests/phpunit/integration/ProtectedVarsAccessLoggerTest.php @@ -4,6 +4,7 @@ namespace MediaWiki\Extension\AbuseFilter\Tests\Integration; use Generator; use MediaWiki\CheckUser\Logging\TemporaryAccountLogger; +use MediaWiki\Deferred\DeferredUpdates; use MediaWiki\Extension\AbuseFilter\AbuseFilterServices; use MediaWiki\Extension\AbuseFilter\ProtectedVarsAccessLogger; use MediaWiki\Registration\ExtensionRegistry; @@ -131,6 +132,7 @@ class ProtectedVarsAccessLoggerTest extends MediaWikiIntegrationTestCase { AbuseFilterServices::getAbuseLoggerFactory() ->getProtectedVarsAccessLogger() ->logViewProtectedVariableValue( $performer->getUserIdentity(), '~2024-01', (int)wfTimestamp() ); + DeferredUpdates::doUpdates(); // Assert that the action wasn't inserted into CheckUsers' temp account logging table $this->assertSame( @@ -171,6 +173,7 @@ class ProtectedVarsAccessLoggerTest extends MediaWikiIntegrationTestCase { AbuseFilterServices::getAbuseLoggerFactory() ->getProtectedVarsAccessLogger() ->logViewProtectedVariableValue( $performer->getUserIdentity(), '~2024-01', (int)wfTimestamp() ); + DeferredUpdates::doUpdates(); // Assert that the action only inserted once into CheckUsers' temp account logging table $this->assertSame(