mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TextExtracts
synced 2024-11-24 00:04:35 +00:00
Minor fixes
* Annotations * Deprecated functions * Namespace tests Change-Id: I521f6af6074a454cec5322ab4cd46db08350c2c3
This commit is contained in:
parent
754c9e4f19
commit
264f65215b
|
@ -22,8 +22,8 @@ use ApiBase;
|
||||||
use ApiMain;
|
use ApiMain;
|
||||||
use ApiQueryBase;
|
use ApiQueryBase;
|
||||||
use Config;
|
use Config;
|
||||||
use ConfigFactory;
|
|
||||||
use FauxRequest;
|
use FauxRequest;
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
use MWTidy;
|
use MWTidy;
|
||||||
use ParserCache;
|
use ParserCache;
|
||||||
use ParserOptions;
|
use ParserOptions;
|
||||||
|
@ -131,7 +131,7 @@ class ApiQueryExtracts extends ApiQueryBase {
|
||||||
}
|
}
|
||||||
if ( $text === false ) {
|
if ( $text === false ) {
|
||||||
$text = $this->parse( $page );
|
$text = $this->parse( $page );
|
||||||
$text = $this->convertText( $text, $title, $this->params['plaintext'] );
|
$text = $this->convertText( $text );
|
||||||
$this->setCache( $page, $text );
|
$this->setCache( $page, $text );
|
||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
|
@ -238,7 +238,7 @@ class ApiQueryExtracts extends ApiQueryBase {
|
||||||
* @return ApiQueryExtracts
|
* @return ApiQueryExtracts
|
||||||
*/
|
*/
|
||||||
public static function factory( $query, $action ) {
|
public static function factory( $query, $action ) {
|
||||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'textextracts' );
|
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
|
||||||
return new self( $query, $action, $config );
|
return new self( $query, $action, $config );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace TextExtracts;
|
namespace TextExtracts;
|
||||||
|
|
||||||
use Config;
|
use Config;
|
||||||
|
use DOMElement;
|
||||||
use HtmlFormatter\HtmlFormatter;
|
use HtmlFormatter\HtmlFormatter;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
|
@ -136,6 +137,7 @@ class ExtractFormatter extends HtmlFormatter {
|
||||||
$doc = $this->getDoc();
|
$doc = $this->getDoc();
|
||||||
$spans = $doc->getElementsByTagName( 'span' );
|
$spans = $doc->getElementsByTagName( 'span' );
|
||||||
|
|
||||||
|
/** @var DOMElement $span */
|
||||||
foreach ( $spans as $span ) {
|
foreach ( $spans as $span ) {
|
||||||
$span->removeAttribute( 'class' );
|
$span->removeAttribute( 'class' );
|
||||||
$span->removeAttribute( 'style' );
|
$span->removeAttribute( 'style' );
|
||||||
|
|
|
@ -4,8 +4,8 @@ namespace TextExtracts;
|
||||||
|
|
||||||
use ApiMain;
|
use ApiMain;
|
||||||
use ApiResult;
|
use ApiResult;
|
||||||
use ConfigFactory;
|
|
||||||
use FauxRequest;
|
use FauxRequest;
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
|
||||||
class Hooks {
|
class Hooks {
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class Hooks {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function onApiOpenSearchSuggest( &$results ) {
|
public static function onApiOpenSearchSuggest( &$results ) {
|
||||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'textextracts' );
|
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
|
||||||
if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || !count( $results ) ) {
|
if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || !count( $results ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace TextExtracts\Test;
|
||||||
|
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
use MediaWikiTestCase;
|
||||||
|
use ParserOptions;
|
||||||
use TextExtracts\ExtractFormatter;
|
use TextExtracts\ExtractFormatter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,10 +15,9 @@ class ExtractFormatterTest extends MediaWikiTestCase {
|
||||||
* @dataProvider provideExtracts
|
* @dataProvider provideExtracts
|
||||||
*/
|
*/
|
||||||
public function testExtracts( $expected, $text, $plainText ) {
|
public function testExtracts( $expected, $text, $plainText ) {
|
||||||
$title = Title::newFromText( 'Test' );
|
|
||||||
$po = new ParserOptions();
|
$po = new ParserOptions();
|
||||||
$po->setEditSection( true );
|
$po->setEditSection( true );
|
||||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'textextracts' );
|
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
|
||||||
$fmt = new ExtractFormatter( $text, $plainText, $config );
|
$fmt = new ExtractFormatter( $text, $plainText, $config );
|
||||||
$fmt->remove( '.metadata' ); // Will be added via $wgExtractsRemoveClasses on WMF
|
$fmt->remove( '.metadata' ); // Will be added via $wgExtractsRemoveClasses on WMF
|
||||||
$text = trim( $fmt->getText() );
|
$text = trim( $fmt->getText() );
|
||||||
|
|
Loading…
Reference in a new issue