From 3758ed5510be02d6cea0ec1dd69dceb3ca3f8679 Mon Sep 17 00:00:00 2001 From: Amir Sarabadani Date: Fri, 24 Dec 2021 02:13:01 +0100 Subject: [PATCH] Use PreparedUpdate to avoid double parse It is now possible to do after Id5ba40a21cc45 Bug: T288639 Change-Id: Icaf5d15928c500dacde3f5574c71b3702702bb88 --- includes/SpamBlacklistHooks.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/includes/SpamBlacklistHooks.php b/includes/SpamBlacklistHooks.php index b828c133..4d51e2c2 100644 --- a/includes/SpamBlacklistHooks.php +++ b/includes/SpamBlacklistHooks.php @@ -4,6 +4,7 @@ use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RevisionRecord; use MediaWiki\Storage\EditResult; use MediaWiki\User\UserIdentity; +use Wikimedia\Assert\PreconditionException; /** * Hooks for the spam blacklist extension @@ -45,14 +46,28 @@ class SpamBlacklistHooks implements $user ); if ( $stashedEdit ) { + // Try getting the value from edit stash /** @var ParserOutput $output */ $pout = $stashedEdit->output; } else { - $contentRenderer = $services->getContentRenderer(); - $pout = $contentRenderer->getParserOutput( $content, $title, null, null, false ); + try { + // Try getting the update directly + $updater = $context->getWikiPage()->getCurrentUpdate(); + $pout = $updater->getParserOutputForMetaData(); + } catch ( PreconditionException $exception ) { + // Last resort, parse the page. + $contentRenderer = $services->getContentRenderer(); + $pout = $contentRenderer->getParserOutput( + $content, + $title, + null, + null, + false + ); + } + } $links = array_keys( $pout->getExternalLinks() ); - // HACK: treat the edit summary as a link if it contains anything // that looks like it could be a URL or e-mail address. if ( preg_match( '/\S(\.[^\s\d]{2,}|[\/@]\S)/', $summary ) ) {