mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TextExtracts
synced 2024-11-23 15:56:52 +00:00
ApiQueryExtracts: remove unneeded factory method
All services can be injected by bumping minimum version of mediawiki (1.34 would be enough, but since that is no longer supported require 1.35) Change-Id: I8bb1573a02932ef5f2871606e94a41afe073fd00
This commit is contained in:
parent
40da2c16b9
commit
d7f93f5c17
|
@ -4,7 +4,7 @@
|
|||
"Max Semenik"
|
||||
],
|
||||
"requires": {
|
||||
"MediaWiki": ">= 1.31.0"
|
||||
"MediaWiki": ">= 1.35.0"
|
||||
},
|
||||
"url": "https://www.mediawiki.org/wiki/Extension:TextExtracts",
|
||||
"descriptionmsg": "textextracts-desc",
|
||||
|
@ -16,7 +16,11 @@
|
|||
"APIPropModules": {
|
||||
"extracts": {
|
||||
"class": "TextExtracts\\ApiQueryExtracts",
|
||||
"factory": "TextExtracts\\ApiQueryExtracts::factory"
|
||||
"services": [
|
||||
"ConfigFactory",
|
||||
"MainWANObjectCache",
|
||||
"LanguageConverterFactory"
|
||||
]
|
||||
}
|
||||
},
|
||||
"MessagesDirs": {
|
||||
|
|
|
@ -7,6 +7,7 @@ use ApiMain;
|
|||
use ApiQueryBase;
|
||||
use ApiUsageException;
|
||||
use Config;
|
||||
use ConfigFactory;
|
||||
use FauxRequest;
|
||||
use MediaWiki\Languages\LanguageConverterFactory;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
|
@ -58,19 +59,19 @@ class ApiQueryExtracts extends ApiQueryBase {
|
|||
/**
|
||||
* @param \ApiQuery $query API query module object
|
||||
* @param string $moduleName Name of this query module
|
||||
* @param Config $conf MediaWiki configuration
|
||||
* @param ConfigFactory $configFactory
|
||||
* @param WANObjectCache $cache
|
||||
* @param LanguageConverterFactory $langConvFactory
|
||||
*/
|
||||
public function __construct(
|
||||
$query,
|
||||
$moduleName,
|
||||
Config $conf,
|
||||
ConfigFactory $configFactory,
|
||||
WANObjectCache $cache,
|
||||
LanguageConverterFactory $langConvFactory
|
||||
) {
|
||||
parent::__construct( $query, $moduleName, self::PREFIX );
|
||||
$this->config = $conf;
|
||||
$this->config = $configFactory->makeConfig( 'textextracts' );
|
||||
$this->cache = $cache;
|
||||
$this->langConvFactory = $langConvFactory;
|
||||
}
|
||||
|
@ -252,6 +253,7 @@ class ApiQueryExtracts extends ApiQueryBase {
|
|||
|
||||
// first try finding full page in parser cache
|
||||
if ( $page->shouldCheckParserCache( $parserOptions, 0 ) ) {
|
||||
// TODO inject ParserCache
|
||||
$pout = MediaWikiServices::getInstance()->getParserCache()->get( $page, $parserOptions );
|
||||
if ( $pout ) {
|
||||
$text = $pout->getText( [ 'unwrap' => true ] );
|
||||
|
@ -312,19 +314,6 @@ class ApiQueryExtracts extends ApiQueryBase {
|
|||
return $data['parse']['text']['*'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ApiQuery $query API query module
|
||||
* @param string $name Name of this query module
|
||||
* @return ApiQueryExtracts
|
||||
*/
|
||||
public static function factory( $query, $name ) {
|
||||
$services = MediaWikiServices::getInstance();
|
||||
$config = $services->getConfigFactory()->makeConfig( 'textextracts' );
|
||||
$cache = $services->getMainWANObjectCache();
|
||||
$langConvFactory = $services->getLanguageConverterFactory();
|
||||
return new self( $query, $name, $config, $cache, $langConvFactory );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts page HTML into an extract
|
||||
* @param string $text
|
||||
|
|
|
@ -22,6 +22,11 @@ class ApiQueryExtractsTest extends \MediaWikiTestCase {
|
|||
'ParserCacheExpireTime' => \IExpiringStore::TTL_INDEFINITE,
|
||||
] );
|
||||
|
||||
$configFactory = $this->createMock( \ConfigFactory::class );
|
||||
$configFactory->method( 'makeConfig' )
|
||||
->with( 'textextracts' )
|
||||
->willReturn( $config );
|
||||
|
||||
$cache = new \WANObjectCache( [ 'cache' => new \HashBagOStuff() ] );
|
||||
|
||||
$context = $this->createMock( \IContextSource::class );
|
||||
|
@ -48,7 +53,7 @@ class ApiQueryExtractsTest extends \MediaWikiTestCase {
|
|||
$langConvFactory->method( 'getLanguageConverter' )
|
||||
->willReturn( $this->createMock( ILanguageConverter::class ) );
|
||||
|
||||
return new ApiQueryExtracts( $query, '', $config, $cache, $langConvFactory );
|
||||
return new ApiQueryExtracts( $query, '', $configFactory, $cache, $langConvFactory );
|
||||
}
|
||||
|
||||
public function testMemCacheHelpers() {
|
||||
|
|
Loading…
Reference in a new issue