Stop using deprecated Language methods

Change-Id: I8a4b7c470fdd7aca64667cf5ac93cd5619e7ca06
This commit is contained in:
Daimona Eaytoy 2021-02-27 13:52:34 +00:00
parent 887c192e0f
commit 8755419bfe
2 changed files with 28 additions and 6 deletions

View file

@ -8,6 +8,7 @@ use ApiQueryBase;
use ApiUsageException;
use Config;
use FauxRequest;
use MediaWiki\Languages\LanguageConverterFactory;
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use ParserOptions;
@ -42,6 +43,10 @@ class ApiQueryExtracts extends ApiQueryBase {
* @var WANObjectCache
*/
private $cache;
/**
* @var LanguageConverterFactory
*/
private $langConvFactory;
// TODO: Allow extensions to hook into this to opt-in.
// This is partly for security reasons; see T107170.
@ -55,11 +60,19 @@ class ApiQueryExtracts extends ApiQueryBase {
* @param string $moduleName Name of this query module
* @param Config $conf MediaWiki configuration
* @param WANObjectCache $cache
* @param LanguageConverterFactory $langConvFactory
*/
public function __construct( $query, $moduleName, Config $conf, WANObjectCache $cache ) {
public function __construct(
$query,
$moduleName,
Config $conf,
WANObjectCache $cache,
LanguageConverterFactory $langConvFactory
) {
parent::__construct( $query, $moduleName, self::PREFIX );
$this->config = $conf;
$this->cache = $cache;
$this->langConvFactory = $langConvFactory;
}
/**
@ -178,9 +191,10 @@ class ApiQueryExtracts extends ApiQueryBase {
* @return string
*/
private function cacheKey( WANObjectCache $cache, WikiPage $page, $introOnly ) {
$langConv = $this->langConvFactory->getLanguageConverter( $page->getTitle()->getPageLanguage() );
return $cache->makeKey( 'textextracts', self::CACHE_VERSION,
$page->getId(), $page->getTouched(),
$page->getTitle()->getPageLanguage()->getPreferredVariant(),
$langConv->getPreferredVariant(),
$this->params['plaintext'] ? 'plaintext' : 'html',
$introOnly ? 'intro' : 'full'
);
@ -304,9 +318,11 @@ class ApiQueryExtracts extends ApiQueryBase {
* @return ApiQueryExtracts
*/
public static function factory( $query, $name ) {
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
$cache = MediaWikiServices::getInstance()->getMainWANObjectCache();
return new self( $query, $name, $config, $cache );
$services = MediaWikiServices::getInstance();
$config = $services->getConfigFactory()->makeConfig( 'textextracts' );
$cache = $services->getMainWANObjectCache();
$langConvFactory = $services->getLanguageConverterFactory();
return new self( $query, $name, $config, $cache, $langConvFactory );
}
/**

View file

@ -2,6 +2,8 @@
namespace TextExtracts\Test;
use ILanguageConverter;
use MediaWiki\Languages\LanguageConverterFactory;
use MediaWikiCoversValidator;
use TextExtracts\ApiQueryExtracts;
use Wikimedia\TestingAccessWrapper;
@ -36,7 +38,11 @@ class ApiQueryExtractsTest extends \MediaWikiTestCase {
->method( 'getMain' )
->willReturn( $main );
return new ApiQueryExtracts( $query, '', $config, $cache );
$langConvFactory = $this->createMock( LanguageConverterFactory::class );
$langConvFactory->method( 'getLanguageConverter' )
->willReturn( $this->createMock( ILanguageConverter::class ) );
return new ApiQueryExtracts( $query, '', $config, $cache, $langConvFactory );
}
public function testMemCacheHelpers() {