Merge "ParserFileProcessing: Inject TitleFactory"

This commit is contained in:
jenkins-bot 2023-06-24 10:40:19 +00:00 committed by Gerrit Code Review
commit 6b1bc3347d
3 changed files with 19 additions and 6 deletions

View file

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

View file

@ -17,7 +17,7 @@ use Parser;
use ParserOutput; use ParserOutput;
use RepoGroup; use RepoGroup;
use RuntimeException; use RuntimeException;
use Title; use TitleFactory;
use WANObjectCache; use WANObjectCache;
use Wikimedia\Rdbms\IConnectionProvider; use Wikimedia\Rdbms\IConnectionProvider;
@ -57,22 +57,28 @@ class ParserFileProcessingHookHandlers implements
/** @var IConnectionProvider */ /** @var IConnectionProvider */
private $connectionProvider; private $connectionProvider;
/** @var TitleFactory */
private $titleFactory;
/** /**
* @param RepoGroup $repoGroup * @param RepoGroup $repoGroup
* @param WANObjectCache $mainWANObjectCache * @param WANObjectCache $mainWANObjectCache
* @param HttpRequestFactory $httpRequestFactory * @param HttpRequestFactory $httpRequestFactory
* @param IConnectionProvider $connectionProvider * @param IConnectionProvider $connectionProvider
* @param TitleFactory $titleFactory
*/ */
public function __construct( public function __construct(
RepoGroup $repoGroup, RepoGroup $repoGroup,
WANObjectCache $mainWANObjectCache, WANObjectCache $mainWANObjectCache,
HttpRequestFactory $httpRequestFactory, HttpRequestFactory $httpRequestFactory,
IConnectionProvider $connectionProvider IConnectionProvider $connectionProvider,
TitleFactory $titleFactory
) { ) {
$this->repoGroup = $repoGroup; $this->repoGroup = $repoGroup;
$this->mainWANObjectCache = $mainWANObjectCache; $this->mainWANObjectCache = $mainWANObjectCache;
$this->httpRequestFactory = $httpRequestFactory; $this->httpRequestFactory = $httpRequestFactory;
$this->connectionProvider = $connectionProvider; $this->connectionProvider = $connectionProvider;
$this->titleFactory = $titleFactory;
} }
/** /**
@ -457,7 +463,10 @@ class ParserFileProcessingHookHandlers implements
* @return string[] * @return string[]
*/ */
private function getDbDenylist( $dbName, $page ) { private function getDbDenylist( $dbName, $page ) {
$title = Title::newFromText( $page ); $title = $this->titleFactory->newFromText( $page );
if ( !$title || !$title->canExist() ) {
return [];
}
$dbr = $this->connectionProvider->getReplicaDatabase( $dbName ); $dbr = $this->connectionProvider->getReplicaDatabase( $dbName );
$id = $dbr->newSelectQueryBuilder() $id = $dbr->newSelectQueryBuilder()
@ -494,7 +503,7 @@ class ParserFileProcessingHookHandlers implements
if ( $text && preg_match_all( $regex, $text, $matches ) ) { if ( $text && preg_match_all( $regex, $text, $matches ) ) {
foreach ( $matches[1] as $s ) { foreach ( $matches[1] as $s ) {
$t = Title::makeTitleSafe( NS_FILE, $s ); $t = $this->titleFactory->makeTitleSafe( NS_FILE, $s );
if ( $t ) { if ( $t ) {
$list[] = $t->getDBkey(); $list[] = $t->getDBkey();

View file

@ -12,6 +12,7 @@ use Parser;
use ParserOptions; use ParserOptions;
use RepoGroup; use RepoGroup;
use Title; use Title;
use TitleFactory;
use WANObjectCache; use WANObjectCache;
use Wikimedia\Rdbms\IConnectionProvider; use Wikimedia\Rdbms\IConnectionProvider;
use Wikimedia\TestingAccessWrapper; use Wikimedia\TestingAccessWrapper;
@ -219,6 +220,7 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
$this->createMock( WANObjectCache::class ), $this->createMock( WANObjectCache::class ),
$this->createMock( HttpRequestFactory::class ), $this->createMock( HttpRequestFactory::class ),
$this->createMock( IConnectionProvider::class ), $this->createMock( IConnectionProvider::class ),
$this->createMock( TitleFactory::class ),
] ) ] )
->onlyMethods( [ 'scoreFromTable', 'fetchFileMetadata', 'getRatio', 'getDenylist' ] ) ->onlyMethods( [ 'scoreFromTable', 'fetchFileMetadata', 'getRatio', 'getDenylist' ] )
->getMock() ->getMock()
@ -291,7 +293,8 @@ class ParserFileProcessingHookHandlersTest extends MediaWikiIntegrationTestCase
$this->getRepoGroup(), $this->getRepoGroup(),
$this->createMock( WANObjectCache::class ), $this->createMock( WANObjectCache::class ),
$this->createMock( HttpRequestFactory::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( WANObjectCache::class ),
$this->createMock( HttpRequestFactory::class ), $this->createMock( HttpRequestFactory::class ),
$this->createMock( IConnectionProvider::class ), $this->createMock( IConnectionProvider::class ),
$this->createMock( TitleFactory::class ),
] ) ] )
->onlyMethods( [ 'fetchFileMetadata' ] ) ->onlyMethods( [ 'fetchFileMetadata' ] )
->getMock() ->getMock()