mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/SpamBlacklist
synced 2024-11-27 16:40:04 +00:00
Merge "Use PreparedUpdate to avoid double parse"
This commit is contained in:
commit
1d1c3dd1c9
|
@ -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 ) ) {
|
||||||
|
|
Loading…
Reference in a new issue