mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-09-23 10:26:47 +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": {
|
"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",
|
||||||
|
|
|
@ -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 ) ) {
|
||||||
|
|
|
@ -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()
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue