mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TextExtracts
synced 2024-11-15 03:35:20 +00:00
Make ExtractFormatter not depend on configuration
Change-Id: I4e9a0947bf50d062ea28004bde30d2e8b18788a4
This commit is contained in:
parent
1017e3ab72
commit
0215eae3aa
|
@ -306,11 +306,8 @@ class ApiQueryExtracts extends ApiQueryBase {
|
|||
* @return string
|
||||
*/
|
||||
private function convertText( $text ) {
|
||||
$fmt = new ExtractFormatter(
|
||||
$text,
|
||||
$this->params['plaintext'],
|
||||
$this->config
|
||||
);
|
||||
$fmt = new ExtractFormatter( $text, $this->params['plaintext'] );
|
||||
$fmt->remove( $this->config->get( 'ExtractsRemoveClasses' ) );
|
||||
$text = $fmt->getText();
|
||||
|
||||
return trim( $text );
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace TextExtracts;
|
||||
|
||||
use Config;
|
||||
use DOMElement;
|
||||
use HtmlFormatter\HtmlFormatter;
|
||||
|
||||
|
@ -33,14 +32,12 @@ class ExtractFormatter extends HtmlFormatter {
|
|||
/**
|
||||
* @param string $text Text to convert
|
||||
* @param bool $plainText Whether extract should be plaintext
|
||||
* @param Config $config Configuration object
|
||||
*/
|
||||
public function __construct( $text, $plainText, Config $config ) {
|
||||
public function __construct( $text, $plainText ) {
|
||||
parent::__construct( HtmlFormatter::wrapHTML( $text ) );
|
||||
$this->plainText = $plainText;
|
||||
|
||||
$this->setRemoveMedia( true );
|
||||
$this->remove( $config->get( 'ExtractsRemoveClasses' ) );
|
||||
|
||||
if ( $plainText ) {
|
||||
$this->flattenAllTags();
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace TextExtracts\Test;
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWikiTestCase;
|
||||
use TextExtracts\ExtractFormatter;
|
||||
|
||||
|
@ -15,10 +14,9 @@ class ExtractFormatterTest extends MediaWikiTestCase {
|
|||
* @dataProvider provideExtracts
|
||||
*/
|
||||
public function testExtracts( $expected, $text, $plainText ) {
|
||||
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
|
||||
$fmt = new ExtractFormatter( $text, $plainText, $config );
|
||||
$fmt = new ExtractFormatter( $text, $plainText );
|
||||
// .metadata class will be added via $wgExtractsRemoveClasses on WMF
|
||||
$fmt->remove( '.metadata' );
|
||||
$fmt->remove( [ 'div', '.metadata' ] );
|
||||
$text = trim( $fmt->getText() );
|
||||
$this->assertEquals( $expected, $text );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue