Make ExtractFormatter not depend on configuration

Change-Id: I4e9a0947bf50d062ea28004bde30d2e8b18788a4
This commit is contained in:
Max Semenik 2019-03-17 13:58:37 -07:00
parent 1017e3ab72
commit 0215eae3aa
3 changed files with 5 additions and 13 deletions

View file

@ -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 );

View file

@ -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();

View file

@ -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 );
}