Use core's externallinks lookup

Depends-On: I8ae9ef388957b0c04efa281f3bc3b5796bec17fe
Bug: T326251
Change-Id: Ibb0f01bdb7a7286389732d45ed0177ca4dfbf2a5
This commit is contained in:
Amir Sarabadani 2023-04-24 15:15:52 +02:00
parent fe523cce95
commit 70a398c036
2 changed files with 9 additions and 22 deletions

View file

@ -20,6 +20,7 @@ use MediaWiki\Extension\ConfirmEdit\Auth\CaptchaAuthenticationRequest;
use MediaWiki\Extension\ConfirmEdit\CaptchaTriggers; use MediaWiki\Extension\ConfirmEdit\CaptchaTriggers;
use MediaWiki\Extension\ConfirmEdit\Hooks\HookRunner; use MediaWiki\Extension\ConfirmEdit\Hooks\HookRunner;
use MediaWiki\Extension\ConfirmEdit\Store\CaptchaStore; use MediaWiki\Extension\ConfirmEdit\Store\CaptchaStore;
use MediaWiki\ExternalLinks\ExternalLinksLookup;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\RevisionAccessException; use MediaWiki\Revision\RevisionAccessException;
use MediaWiki\Revision\RevisionLookup; use MediaWiki\Revision\RevisionLookup;
@ -663,7 +664,11 @@ class SimpleCaptcha {
// Only check edits that add URLs // Only check edits that add URLs
if ( $content instanceof Content ) { if ( $content instanceof Content ) {
// Get links from the database // Get links from the database
$oldLinks = $this->getLinksFromTracker( $title ); $oldLinks = ExternalLinksLookup::getExternalLinksForPage(
$title->getArticleID(),
wfGetDB( DB_REPLICA ),
__METHOD__
);
// Share a parse operation with Article::doEdit() // Share a parse operation with Article::doEdit()
$editInfo = $page->prepareContentForEdit( $content, null, $user ); $editInfo = $page->prepareContentForEdit( $content, null, $user );
if ( $editInfo->output ) { if ( $editInfo->output ) {
@ -837,24 +842,6 @@ class SimpleCaptcha {
} }
} }
/**
* Load external links from the externallinks table
* @param Title $title
* @return array
*/
private function getLinksFromTracker( $title ) {
$dbr = wfGetDB( DB_REPLICA );
// should be zero queries
$id = $title->getArticleID();
$res = $dbr->select( 'externallinks', [ 'el_to' ],
[ 'el_from' => $id ], __METHOD__ );
$links = [];
foreach ( $res as $row ) {
$links[] = $row->el_to;
}
return $links;
}
/** /**
* Backend function for confirmEditMerged() * Backend function for confirmEditMerged()
* @param WikiPage $page * @param WikiPage $page
@ -1026,7 +1013,7 @@ class SimpleCaptcha {
* @return bool * @return bool
*/ */
public function passCaptchaLimitedFromRequest( WebRequest $request, User $user ) { public function passCaptchaLimitedFromRequest( WebRequest $request, User $user ) {
list( $index, $word ) = $this->getCaptchaParamsFromRequest( $request ); [ $index, $word ] = $this->getCaptchaParamsFromRequest( $request );
return $this->passCaptchaLimited( $index, $word, $user ); return $this->passCaptchaLimited( $index, $word, $user );
} }
@ -1075,7 +1062,7 @@ class SimpleCaptcha {
* @return bool if passed, false if failed or new session * @return bool if passed, false if failed or new session
*/ */
public function passCaptchaFromRequest( WebRequest $request, User $user ) { public function passCaptchaFromRequest( WebRequest $request, User $user ) {
list( $index, $word ) = $this->getCaptchaParamsFromRequest( $request ); [ $index, $word ] = $this->getCaptchaParamsFromRequest( $request );
return $this->passCaptcha( $index, $word ); return $this->passCaptcha( $index, $word );
} }

View file

@ -13,7 +13,7 @@
"license-name": "GPL-2.0-or-later", "license-name": "GPL-2.0-or-later",
"type": "antispam", "type": "antispam",
"requires": { "requires": {
"MediaWiki": ">= 1.38.0" "MediaWiki": ">= 1.41.0"
}, },
"GroupPermissions": { "GroupPermissions": {
"*": { "*": {