mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-11-24 00:13:27 +00:00
Merge "ParserFileProcessing: Inject TitleFactory"
This commit is contained in:
commit
6b1bc3347d
|
@ -40,7 +40,7 @@
|
|||
},
|
||||
"parser": {
|
||||
"class": "PageImages\\Hooks\\ParserFileProcessingHookHandlers",
|
||||
"services": [ "RepoGroup", "MainWANObjectCache", "HttpRequestFactory", "DBLoadBalancerFactory" ]
|
||||
"services": [ "RepoGroup", "MainWANObjectCache", "HttpRequestFactory", "DBLoadBalancerFactory", "TitleFactory" ]
|
||||
},
|
||||
"search": {
|
||||
"class": "PageImages\\Hooks\\SearchResultProvideThumbnailHookHandler",
|
||||
|
|
|
@ -17,7 +17,7 @@ use Parser;
|
|||
use ParserOutput;
|
||||
use RepoGroup;
|
||||
use RuntimeException;
|
||||
use Title;
|
||||
use TitleFactory;
|
||||
use WANObjectCache;
|
||||
use Wikimedia\Rdbms\IConnectionProvider;
|
||||
|
||||
|
@ -57,22 +57,28 @@ class ParserFileProcessingHookHandlers implements
|
|||
/** @var IConnectionProvider */
|
||||
private $connectionProvider;
|
||||
|
||||
/** @var TitleFactory */
|
||||
private $titleFactory;
|
||||
|
||||
/**
|
||||
* @param RepoGroup $repoGroup
|
||||
* @param WANObjectCache $mainWANObjectCache
|
||||
* @param HttpRequestFactory $httpRequestFactory
|
||||
* @param IConnectionProvider $connectionProvider
|
||||
* @param TitleFactory $titleFactory
|
||||
*/
|
||||
public function __construct(
|
||||
RepoGroup $repoGroup,
|
||||
WANObjectCache $mainWANObjectCache,
|
||||
HttpRequestFactory $httpRequestFactory,
|
||||
IConnectionProvider $connectionProvider
|
||||
IConnectionProvider $connectionProvider,
|
||||
TitleFactory $titleFactory
|
||||
) {
|
||||
$this->repoGroup = $repoGroup;
|
||||
$this->mainWANObjectCache = $mainWANObjectCache;
|
||||
$this->httpRequestFactory = $httpRequestFactory;
|
||||
$this->connectionProvider = $connectionProvider;
|
||||
$this->titleFactory = $titleFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -457,7 +463,10 @@ class ParserFileProcessingHookHandlers implements
|
|||
* @return string[]
|
||||
*/
|
||||
private function getDbDenylist( $dbName, $page ) {
|
||||
$title = Title::newFromText( $page );
|
||||
$title = $this->titleFactory->newFromText( $page );
|
||||
if ( !$title || !$title->canExist() ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$dbr = $this->connectionProvider->getReplicaDatabase( $dbName );
|
||||
$id = $dbr->newSelectQueryBuilder()
|
||||
|
@ -494,7 +503,7 @@ class ParserFileProcessingHookHandlers implements
|
|||
|
||||
if ( $text && preg_match_all( $regex, $text, $matches ) ) {
|
||||
foreach ( $matches[1] as $s ) {
|
||||
$t = Title::makeTitleSafe( NS_FILE, $s );
|
||||
$t = $this->titleFactory->makeTitleSafe( NS_FILE, $s );
|
||||
|
||||
if ( $t ) {
|
||||
$list[] = $t->getDBkey();
|
||||
|
|
|
@ -12,6 +12,7 @@ use Parser;
|
|||
use ParserOptions;
|
||||
use RepoGroup;
|
||||
use Title;
|
||||
use TitleFactory;
|
||||
use WANObjectCache;
|
||||
use Wikimedia\Rdbms\IConnectionProvider;
|
||||
use Wikimedia\TestingAccessWrapper;
|
||||
|
@ -219,6 +220,7 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
|
|||
$this->createMock( WANObjectCache::class ),
|
||||
$this->createMock( HttpRequestFactory::class ),
|
||||
$this->createMock( IConnectionProvider::class ),
|
||||
$this->createMock( TitleFactory::class ),
|
||||
] )
|
||||
->onlyMethods( [ 'scoreFromTable', 'fetchFileMetadata', 'getRatio', 'getDenylist' ] )
|
||||
->getMock()
|
||||
|
@ -291,7 +293,8 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
|
|||
$this->getRepoGroup(),
|
||||
$this->createMock( WANObjectCache::class ),
|
||||
$this->createMock( HttpRequestFactory::class ),
|
||||
$this->createMock( IConnectionProvider::class )
|
||||
$this->createMock( IConnectionProvider::class ),
|
||||
$this->createMock( TitleFactory::class )
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -356,6 +359,7 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
|
|||
$this->createMock( WANObjectCache::class ),
|
||||
$this->createMock( HttpRequestFactory::class ),
|
||||
$this->createMock( IConnectionProvider::class ),
|
||||
$this->createMock( TitleFactory::class ),
|
||||
] )
|
||||
->onlyMethods( [ 'fetchFileMetadata' ] )
|
||||
->getMock()
|
||||
|
|
Loading…
Reference in a new issue