mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-09-23 18:31:09 +00:00
Replace deprecated Http::get
Bug: T305813 Change-Id: Icd3e64fc13e291761b287c4059315df39cd88d1e
This commit is contained in:
parent
7a83acf385
commit
de7bf883d2
|
@ -40,7 +40,7 @@
|
|||
},
|
||||
"parser": {
|
||||
"class": "PageImages\\Hooks\\ParserFileProcessingHookHandlers",
|
||||
"services": [ "RepoGroup", "MainWANObjectCache" ]
|
||||
"services": [ "RepoGroup", "MainWANObjectCache", "HttpRequestFactory" ]
|
||||
},
|
||||
"search": {
|
||||
"class": "PageImages\\Hooks\\SearchResultProvideThumbnailHookHandler",
|
||||
|
|
|
@ -6,10 +6,10 @@ use DerivativeContext;
|
|||
use Exception;
|
||||
use File;
|
||||
use FormatMetadata;
|
||||
use Http;
|
||||
use MediaWiki\Hook\ParserAfterTidyHook;
|
||||
use MediaWiki\Hook\ParserModifyImageHTML;
|
||||
use MediaWiki\Hook\ParserTestGlobalsHook;
|
||||
use MediaWiki\Http\HttpRequestFactory;
|
||||
use PageImages\PageImageCandidate;
|
||||
use PageImages\PageImages;
|
||||
use Parser;
|
||||
|
@ -49,16 +49,22 @@ class ParserFileProcessingHookHandlers implements
|
|||
/** @var WANObjectCache */
|
||||
private $mainWANObjectCache;
|
||||
|
||||
/** @var HttpRequestFactory */
|
||||
private $httpRequestFactory;
|
||||
|
||||
/**
|
||||
* @param RepoGroup $repoGroup
|
||||
* @param WANObjectCache $mainWANObjectCache
|
||||
* @param HttpRequestFactory $httpRequestFactory
|
||||
*/
|
||||
public function __construct(
|
||||
RepoGroup $repoGroup,
|
||||
WANObjectCache $mainWANObjectCache
|
||||
WANObjectCache $mainWANObjectCache,
|
||||
HttpRequestFactory $httpRequestFactory
|
||||
) {
|
||||
$this->repoGroup = $repoGroup;
|
||||
$this->mainWANObjectCache = $mainWANObjectCache;
|
||||
$this->httpRequestFactory = $httpRequestFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -480,7 +486,7 @@ class ParserFileProcessingHookHandlers implements
|
|||
global $wgFileExtensions;
|
||||
|
||||
$list = [];
|
||||
$text = Http::get( $url, [ 'timeout' => 3 ], __METHOD__ );
|
||||
$text = $this->httpRequestFactory->get( $url, [ 'timeout' => 3 ], __METHOD__ );
|
||||
$regex = '/\[\[:([^|\#]*?\.(?:' . implode( '|', $wgFileExtensions ) . '))/i';
|
||||
|
||||
if ( $text && preg_match_all( $regex, $text, $matches ) ) {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace PageImages\Tests\Hooks;
|
||||
|
||||
use File;
|
||||
use MediaWiki\Http\HttpRequestFactory;
|
||||
use MediaWikiIntegrationTestCase;
|
||||
use PageImages\Hooks\ParserFileProcessingHookHandlers;
|
||||
use PageImages\PageImageCandidate;
|
||||
|
@ -212,7 +213,11 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
|
|||
public function testGetScore( $image, $scoreFromTable, $position, $expected ) {
|
||||
$mock = TestingAccessWrapper::newFromObject(
|
||||
$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' ] )
|
||||
->getMock()
|
||||
);
|
||||
|
@ -280,7 +285,11 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
|
|||
public function testScoreFromTable( array $scores, $value, $expected ) {
|
||||
/** @var ParserFileProcessingHookHandlers $handlerWrapper */
|
||||
$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 );
|
||||
|
@ -339,7 +348,11 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
|
|||
public function testIsFreeImage( $fileName, $metadata, $expected ) {
|
||||
$mock = TestingAccessWrapper::newFromObject(
|
||||
$this->getMockBuilder( ParserFileProcessingHookHandlers::class )
|
||||
->setConstructorArgs( [ $this->getRepoGroup(), $this->createMock( WANObjectCache::class ) ] )
|
||||
->setConstructorArgs( [
|
||||
$this->getRepoGroup(),
|
||||
$this->createMock( WANObjectCache::class ),
|
||||
$this->createMock( HttpRequestFactory::class ),
|
||||
] )
|
||||
->onlyMethods( [ 'fetchFileMetadata' ] )
|
||||
->getMock()
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue