ApiQueryExtracts: inject WikiPageFactory

Bug: T297688
Change-Id: I8faa8a14efcd6cb6b247301aa4da0c1abac7c97b
This commit is contained in:
Alexander Vorwerk 2021-12-14 22:58:51 +01:00
parent b7cb0703d9
commit abcb71cabb
3 changed files with 20 additions and 4 deletions

View file

@ -19,7 +19,8 @@
"services": [ "services": [
"ConfigFactory", "ConfigFactory",
"MainWANObjectCache", "MainWANObjectCache",
"LanguageConverterFactory" "LanguageConverterFactory",
"WikiPageFactory"
] ]
} }
}, },

View file

@ -12,6 +12,7 @@ use FauxRequest;
use MediaWiki\Languages\LanguageConverterFactory; use MediaWiki\Languages\LanguageConverterFactory;
use MediaWiki\Logger\LoggerFactory; use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MediaWiki\Page\WikiPageFactory;
use ParserOptions; use ParserOptions;
use Title; use Title;
use User; use User;
@ -48,6 +49,10 @@ class ApiQueryExtracts extends ApiQueryBase {
* @var LanguageConverterFactory * @var LanguageConverterFactory
*/ */
private $langConvFactory; private $langConvFactory;
/**
* @var WikiPageFactory
*/
private $wikiPageFactory;
// TODO: Allow extensions to hook into this to opt-in. // TODO: Allow extensions to hook into this to opt-in.
// This is partly for security reasons; see T107170. // This is partly for security reasons; see T107170.
@ -62,18 +67,21 @@ class ApiQueryExtracts extends ApiQueryBase {
* @param ConfigFactory $configFactory * @param ConfigFactory $configFactory
* @param WANObjectCache $cache * @param WANObjectCache $cache
* @param LanguageConverterFactory $langConvFactory * @param LanguageConverterFactory $langConvFactory
* @param WikiPageFactory $wikiPageFactory
*/ */
public function __construct( public function __construct(
$query, $query,
$moduleName, $moduleName,
ConfigFactory $configFactory, ConfigFactory $configFactory,
WANObjectCache $cache, WANObjectCache $cache,
LanguageConverterFactory $langConvFactory LanguageConverterFactory $langConvFactory,
WikiPageFactory $wikiPageFactory
) { ) {
parent::__construct( $query, $moduleName, self::PREFIX ); parent::__construct( $query, $moduleName, self::PREFIX );
$this->config = $configFactory->makeConfig( 'textextracts' ); $this->config = $configFactory->makeConfig( 'textextracts' );
$this->cache = $cache; $this->cache = $cache;
$this->langConvFactory = $langConvFactory; $this->langConvFactory = $langConvFactory;
$this->wikiPageFactory = $wikiPageFactory;
} }
/** /**
@ -166,7 +174,7 @@ class ApiQueryExtracts extends ApiQueryBase {
return ''; return '';
} }
$page = WikiPage::factory( $title ); $page = $this->wikiPageFactory->newFromTitle( $title );
$introOnly = $this->params['intro']; $introOnly = $this->params['intro'];
$text = $this->getFromCache( $page, $introOnly ); $text = $this->getFromCache( $page, $introOnly );

View file

@ -53,7 +53,14 @@ class ApiQueryExtractsTest extends \MediaWikiIntegrationTestCase {
$langConvFactory->method( 'getLanguageConverter' ) $langConvFactory->method( 'getLanguageConverter' )
->willReturn( $this->createMock( ILanguageConverter::class ) ); ->willReturn( $this->createMock( ILanguageConverter::class ) );
return new ApiQueryExtracts( $query, '', $configFactory, $cache, $langConvFactory ); return new ApiQueryExtracts(
$query,
'',
$configFactory,
$cache,
$langConvFactory,
$this->getServiceContainer()->getWikiPageFactory()
);
} }
public function testMemCacheHelpers() { public function testMemCacheHelpers() {