diff --git a/includes/VariableGenerator/VariableGenerator.php b/includes/VariableGenerator/VariableGenerator.php index c16ed8543..d91a912ef 100644 --- a/includes/VariableGenerator/VariableGenerator.php +++ b/includes/VariableGenerator/VariableGenerator.php @@ -173,10 +173,10 @@ class VariableGenerator { /** * @param WikiPage $page - * @param User $user The current user + * @param UserIdentity $userIdentity The current user * @return $this For chaining */ - public function addEditVars( WikiPage $page, User $user ): self { + public function addEditVars( WikiPage $page, UserIdentity $userIdentity ): self { $this->vars->setLazyLoadVar( 'edit_diff', 'diff', [ 'oldtext-var' => 'old_wikitext', 'newtext-var' => 'new_wikitext' ] ); $this->vars->setLazyLoadVar( 'edit_diff_pst', 'diff', @@ -206,26 +206,26 @@ class VariableGenerator { [ 'text-var' => 'new_wikitext', 'article' => $page, - 'contextUser' => $user + 'contextUserIdentity' => $userIdentity ] ); $this->vars->setLazyLoadVar( 'old_links', 'links-from-wikitext-or-database', [ 'article' => $page, 'text-var' => 'old_wikitext', - 'contextUser' => $user + 'contextUserIdentity' => $userIdentity ] ); $this->vars->setLazyLoadVar( 'new_pst', 'parse-wikitext', [ 'wikitext-var' => 'new_wikitext', 'article' => $page, 'pst' => true, - 'contextUser' => $user + 'contextUserIdentity' => $userIdentity ] ); $this->vars->setLazyLoadVar( 'new_html', 'parse-wikitext', [ 'wikitext-var' => 'new_wikitext', 'article' => $page, - 'contextUser' => $user + 'contextUserIdentity' => $userIdentity ] ); return $this; diff --git a/includes/Variables/LazyVariableComputer.php b/includes/Variables/LazyVariableComputer.php index 86ebde80c..54ab76532 100644 --- a/includes/Variables/LazyVariableComputer.php +++ b/includes/Variables/LazyVariableComputer.php @@ -199,7 +199,7 @@ class LazyVariableComputer { $editInfo = $article->prepareContentForEdit( $content, null, - $parameters['contextUser'] + $parameters['contextUserIdentity'] ); $result = array_keys( $editInfo->output->getExternalLinks() ); self::$profilingExtraTime += ( microtime( true ) - $startTime ); @@ -225,7 +225,7 @@ class LazyVariableComputer { $editInfo = $this->parseNonEditWikitext( $wikitext, $article, - $parameters['contextUser'] + $parameters['contextUserIdentity'] ); $links = array_keys( $editInfo->output->getExternalLinks() ); } else { @@ -267,7 +267,7 @@ class LazyVariableComputer { $editInfo = $article->prepareContentForEdit( $content, null, - $parameters['contextUser'] + $parameters['contextUserIdentity'] ); if ( isset( $parameters['pst'] ) && $parameters['pst'] ) { $result = $editInfo->pstContent->serialize( $editInfo->format ); @@ -477,17 +477,17 @@ class LazyVariableComputer { * * @param string $wikitext * @param WikiPage $article - * @param User $user Context user + * @param UserIdentity $userIdentity Context user * * @return stdClass */ - private function parseNonEditWikitext( $wikitext, WikiPage $article, User $user ) { + private function parseNonEditWikitext( $wikitext, WikiPage $article, UserIdentity $userIdentity ) { static $cache = []; $cacheKey = md5( $wikitext ) . ':' . $article->getTitle()->getPrefixedText(); if ( !isset( $cache[$cacheKey] ) ) { - $options = ParserOptions::newFromUser( $user ); + $options = ParserOptions::newFromUser( $userIdentity ); $cache[$cacheKey] = (object)[ 'output' => $this->parser->parse( $wikitext, $article->getTitle(), $options ) ]; diff --git a/tests/phpunit/unit/VariableGenerator/VariableGeneratorTest.php b/tests/phpunit/unit/VariableGenerator/VariableGeneratorTest.php index 18529f232..91719ec9a 100644 --- a/tests/phpunit/unit/VariableGenerator/VariableGeneratorTest.php +++ b/tests/phpunit/unit/VariableGenerator/VariableGeneratorTest.php @@ -8,6 +8,7 @@ use MediaWiki\Extension\AbuseFilter\Parser\AFPData; use MediaWiki\Extension\AbuseFilter\VariableGenerator\VariableGenerator; use MediaWiki\Extension\AbuseFilter\Variables\LazyLoadedVariable; use MediaWiki\Extension\AbuseFilter\Variables\VariableHolder; +use MediaWiki\User\UserIdentity; use MediaWikiUnitTestCase; use Title; use User; @@ -175,7 +176,7 @@ class VariableGeneratorTest extends MediaWikiUnitTestCase { $generator = new VariableGenerator( $this->createMock( AbuseFilterHookRunner::class ) ); $actualVars = $generator->addEditVars( $this->createMock( WikiPage::class ), - $this->createMock( User::class ) + $this->createMock( UserIdentity::class ) )->getVariableHolder()->getVars(); $this->assertArrayEquals( $expectedKeys, array_keys( $actualVars ) ); $this->assertContainsOnlyInstancesOf( LazyLoadedVariable::class, $actualVars, 'lazy-loaded vars' );