Replace deprecated Http::get

Bug: T305813
Change-Id: Icd3e64fc13e291761b287c4059315df39cd88d1e
This commit is contained in:
Umherirrender 2022-12-11 14:00:11 +01:00
parent 7a83acf385
commit de7bf883d2
3 changed files with 26 additions and 7 deletions

View file

@ -40,7 +40,7 @@
}, },
"parser": { "parser": {
"class": "PageImages\\Hooks\\ParserFileProcessingHookHandlers", "class": "PageImages\\Hooks\\ParserFileProcessingHookHandlers",
"services": [ "RepoGroup", "MainWANObjectCache" ] "services": [ "RepoGroup", "MainWANObjectCache", "HttpRequestFactory" ]
}, },
"search": { "search": {
"class": "PageImages\\Hooks\\SearchResultProvideThumbnailHookHandler", "class": "PageImages\\Hooks\\SearchResultProvideThumbnailHookHandler",

View file

@ -6,10 +6,10 @@ use DerivativeContext;
use Exception; use Exception;
use File; use File;
use FormatMetadata; use FormatMetadata;
use Http;
use MediaWiki\Hook\ParserAfterTidyHook; use MediaWiki\Hook\ParserAfterTidyHook;
use MediaWiki\Hook\ParserModifyImageHTML; use MediaWiki\Hook\ParserModifyImageHTML;
use MediaWiki\Hook\ParserTestGlobalsHook; use MediaWiki\Hook\ParserTestGlobalsHook;
use MediaWiki\Http\HttpRequestFactory;
use PageImages\PageImageCandidate; use PageImages\PageImageCandidate;
use PageImages\PageImages; use PageImages\PageImages;
use Parser; use Parser;
@ -49,16 +49,22 @@ class ParserFileProcessingHookHandlers implements
/** @var WANObjectCache */ /** @var WANObjectCache */
private $mainWANObjectCache; private $mainWANObjectCache;
/** @var HttpRequestFactory */
private $httpRequestFactory;
/** /**
* @param RepoGroup $repoGroup * @param RepoGroup $repoGroup
* @param WANObjectCache $mainWANObjectCache * @param WANObjectCache $mainWANObjectCache
* @param HttpRequestFactory $httpRequestFactory
*/ */
public function __construct( public function __construct(
RepoGroup $repoGroup, RepoGroup $repoGroup,
WANObjectCache $mainWANObjectCache WANObjectCache $mainWANObjectCache,
HttpRequestFactory $httpRequestFactory
) { ) {
$this->repoGroup = $repoGroup; $this->repoGroup = $repoGroup;
$this->mainWANObjectCache = $mainWANObjectCache; $this->mainWANObjectCache = $mainWANObjectCache;
$this->httpRequestFactory = $httpRequestFactory;
} }
/** /**
@ -480,7 +486,7 @@ class ParserFileProcessingHookHandlers implements
global $wgFileExtensions; global $wgFileExtensions;
$list = []; $list = [];
$text = Http::get( $url, [ 'timeout' => 3 ], __METHOD__ ); $text = $this->httpRequestFactory->get( $url, [ 'timeout' => 3 ], __METHOD__ );
$regex = '/\[\[:([^|\#]*?\.(?:' . implode( '|', $wgFileExtensions ) . '))/i'; $regex = '/\[\[:([^|\#]*?\.(?:' . implode( '|', $wgFileExtensions ) . '))/i';
if ( $text && preg_match_all( $regex, $text, $matches ) ) { if ( $text && preg_match_all( $regex, $text, $matches ) ) {

View file

@ -3,6 +3,7 @@
namespace PageImages\Tests\Hooks; namespace PageImages\Tests\Hooks;
use File; use File;
use MediaWiki\Http\HttpRequestFactory;
use MediaWikiIntegrationTestCase; use MediaWikiIntegrationTestCase;
use PageImages\Hooks\ParserFileProcessingHookHandlers; use PageImages\Hooks\ParserFileProcessingHookHandlers;
use PageImages\PageImageCandidate; use PageImages\PageImageCandidate;
@ -212,7 +213,11 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
public function testGetScore( $image, $scoreFromTable, $position, $expected ) { public function testGetScore( $image, $scoreFromTable, $position, $expected ) {
$mock = TestingAccessWrapper::newFromObject( $mock = TestingAccessWrapper::newFromObject(
$this->getMockBuilder( ParserFileProcessingHookHandlers::class ) $this->getMockBuilder( ParserFileProcessingHookHandlers::class )
->setConstructorArgs( [ $this->getRepoGroup(), $this->createMock( WANObjectCache::class ) ] ) ->setConstructorArgs( [
$this->getRepoGroup(),
$this->createMock( WANObjectCache::class ),
$this->createMock( HttpRequestFactory::class ),
] )
->onlyMethods( [ 'scoreFromTable', 'fetchFileMetadata', 'getRatio', 'getDenylist' ] ) ->onlyMethods( [ 'scoreFromTable', 'fetchFileMetadata', 'getRatio', 'getDenylist' ] )
->getMock() ->getMock()
); );
@ -280,7 +285,11 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
public function testScoreFromTable( array $scores, $value, $expected ) { public function testScoreFromTable( array $scores, $value, $expected ) {
/** @var ParserFileProcessingHookHandlers $handlerWrapper */ /** @var ParserFileProcessingHookHandlers $handlerWrapper */
$handlerWrapper = TestingAccessWrapper::newFromObject( $handlerWrapper = TestingAccessWrapper::newFromObject(
new ParserFileProcessingHookHandlers( $this->getRepoGroup(), $this->createMock( WANObjectCache::class ) ) new ParserFileProcessingHookHandlers(
$this->getRepoGroup(),
$this->createMock( WANObjectCache::class ),
$this->createMock( HttpRequestFactory::class )
)
); );
$score = $handlerWrapper->scoreFromTable( $value, $scores ); $score = $handlerWrapper->scoreFromTable( $value, $scores );
@ -339,7 +348,11 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
public function testIsFreeImage( $fileName, $metadata, $expected ) { public function testIsFreeImage( $fileName, $metadata, $expected ) {
$mock = TestingAccessWrapper::newFromObject( $mock = TestingAccessWrapper::newFromObject(
$this->getMockBuilder( ParserFileProcessingHookHandlers::class ) $this->getMockBuilder( ParserFileProcessingHookHandlers::class )
->setConstructorArgs( [ $this->getRepoGroup(), $this->createMock( WANObjectCache::class ) ] ) ->setConstructorArgs( [
$this->getRepoGroup(),
$this->createMock( WANObjectCache::class ),
$this->createMock( HttpRequestFactory::class ),
] )
->onlyMethods( [ 'fetchFileMetadata' ] ) ->onlyMethods( [ 'fetchFileMetadata' ] )
->getMock() ->getMock()
); );