Merge "Use PreparedUpdate to avoid double parse"

This commit is contained in:
jenkins-bot 2022-01-07 17:18:02 +00:00 committed by Gerrit Code Review
commit 1d1c3dd1c9

View file

@ -4,6 +4,7 @@ use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionRecord; use MediaWiki\Revision\RevisionRecord;
use MediaWiki\Storage\EditResult; use MediaWiki\Storage\EditResult;
use MediaWiki\User\UserIdentity; use MediaWiki\User\UserIdentity;
use Wikimedia\Assert\PreconditionException;
/** /**
* Hooks for the spam blacklist extension * Hooks for the spam blacklist extension
@ -45,14 +46,28 @@ class SpamBlacklistHooks implements
$user $user
); );
if ( $stashedEdit ) { if ( $stashedEdit ) {
// Try getting the value from edit stash
/** @var ParserOutput $output */ /** @var ParserOutput $output */
$pout = $stashedEdit->output; $pout = $stashedEdit->output;
} else { } else {
$contentRenderer = $services->getContentRenderer(); try {
$pout = $contentRenderer->getParserOutput( $content, $title, null, null, false ); // 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() ); $links = array_keys( $pout->getExternalLinks() );
// HACK: treat the edit summary as a link if it contains anything // HACK: treat the edit summary as a link if it contains anything
// that looks like it could be a URL or e-mail address. // that looks like it could be a URL or e-mail address.
if ( preg_match( '/\S(\.[^\s\d]{2,}|[\/@]\S)/', $summary ) ) { if ( preg_match( '/\S(\.[^\s\d]{2,}|[\/@]\S)/', $summary ) ) {