mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TextExtracts
synced 2024-11-15 03:35:20 +00:00
Reorg: move hooks to a separate class, introduce namespaces
Change-Id: Ic784010e79b1168f0e112cf912f463036255eb64
This commit is contained in:
parent
c689444302
commit
fbd8e93a8b
|
@ -34,27 +34,28 @@ $wgExtensionMessagesFiles['TextExtracts'] = "$dir/TextExtracts.i18n.php";
|
|||
|
||||
|
||||
$wgConfigRegistry['textextracts'] = 'GlobalVarConfig::newInstance';
|
||||
$wgAutoloadClasses['ExtractFormatter'] = "$dir/ExtractFormatter.php";
|
||||
$wgAutoloadClasses['ApiQueryExtracts'] = "$dir/ApiQueryExtracts.php";
|
||||
$wgAutoloadClasses['TextExtracts\ApiQueryExtracts'] = "$dir/includes/ApiQueryExtracts.php";
|
||||
$wgAutoloadClasses['TextExtracts\ExtractFormatter'] = "$dir/includes/ExtractFormatter.php";
|
||||
$wgAutoloadClasses['TextExtracts\Hooks'] = "$dir/includes/Hooks.php";
|
||||
$wgAPIPropModules['extracts'] = array(
|
||||
'class' => 'ApiQueryExtracts',
|
||||
'class' => 'TextExtracts\ApiQueryExtracts',
|
||||
'factory' => 'wfNewApiQueryExtracts'
|
||||
);
|
||||
|
||||
/**
|
||||
* @param ApiQuery $query
|
||||
* @param string $action
|
||||
* @return ApiQueryExtracts
|
||||
* @return TextExtracts\ApiQueryExtracts
|
||||
*/
|
||||
function wfNewApiQueryExtracts( $query, $action ) {
|
||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'textextracts' );
|
||||
return new ApiQueryExtracts( $query, $action, $config );
|
||||
return new TextExtracts\ApiQueryExtracts( $query, $action, $config );
|
||||
}
|
||||
|
||||
$wgHooks['OpenSearchXml'][] = 'ApiQueryExtracts::onApiOpenSearchSuggest';
|
||||
$wgHooks['ApiOpenSearchSuggest'][] = 'ApiQueryExtracts::onApiOpenSearchSuggest';
|
||||
$wgHooks['OpenSearchXml'][] = 'TextExtracts\Hooks::onApiOpenSearchSuggest';
|
||||
$wgHooks['ApiOpenSearchSuggest'][] = 'TextExtracts\Hooks::onApiOpenSearchSuggest';
|
||||
$wgHooks['UnitTestsList'][] = function( &$files ) {
|
||||
$files[] = __DIR__ . '/ExtractFormatterTest.php';
|
||||
$files[] = __DIR__ . '/tests/ExtractFormatterTest.php';
|
||||
return true;
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,21 @@
|
|||
* http://www.gnu.org/copyleft/gpl.html
|
||||
*/
|
||||
|
||||
namespace TextExtracts;
|
||||
|
||||
use ApiBase;
|
||||
use ApiMain;
|
||||
use ApiQueryBase;
|
||||
use Config;
|
||||
use FauxRequest;
|
||||
use MWTidy;
|
||||
use ParserCache;
|
||||
use ParserOptions;
|
||||
use Title;
|
||||
use UsageException;
|
||||
use User;
|
||||
use WikiPage;
|
||||
|
||||
class ApiQueryExtracts extends ApiQueryBase {
|
||||
/**
|
||||
* @var ParserOptions
|
||||
|
@ -86,38 +101,6 @@ class ApiQueryExtracts extends ApiQueryBase {
|
|||
return 'public';
|
||||
}
|
||||
|
||||
/**
|
||||
* ApiOpenSearchSuggest hook handler
|
||||
* @param array $results
|
||||
* @return bool
|
||||
*/
|
||||
public static function onApiOpenSearchSuggest( &$results ) {
|
||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'textextracts' );
|
||||
if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || !count( $results ) ) {
|
||||
return true;
|
||||
}
|
||||
$pageIds = array_keys( $results );
|
||||
$api = new ApiMain( new FauxRequest(
|
||||
array(
|
||||
'action' => 'query',
|
||||
'prop' => 'extracts',
|
||||
'explaintext' => true,
|
||||
'exintro' => true,
|
||||
'exlimit' => count( $results ),
|
||||
'pageids' => implode( '|', $pageIds ),
|
||||
) )
|
||||
);
|
||||
$api->execute();
|
||||
$data = $api->getResultData();
|
||||
foreach ( $pageIds as $id ) {
|
||||
if ( isset( $data['query']['pages'][$id]['extract']['*'] ) ) {
|
||||
$results[$id]['extract'] = $data['query']['pages'][$id]['extract']['*'];
|
||||
$results[$id]['extract trimmed'] = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a processed, but not trimmed extract
|
||||
* @param Title $title
|
|
@ -1,5 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace TextExtracts;
|
||||
use Config;
|
||||
use HtmlFormatter;
|
||||
use MWException;
|
||||
|
||||
/**
|
||||
* Provides text-only or limited-HTML extracts of page HTML
|
||||
*
|
42
includes/Hooks.php
Normal file
42
includes/Hooks.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace TextExtracts;
|
||||
|
||||
|
||||
use ApiMain;
|
||||
use ConfigFactory;
|
||||
use FauxRequest;
|
||||
|
||||
class Hooks {
|
||||
/**
|
||||
* ApiOpenSearchSuggest hook handler
|
||||
* @param array $results
|
||||
* @return bool
|
||||
*/
|
||||
public static function onApiOpenSearchSuggest( &$results ) {
|
||||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'textextracts' );
|
||||
if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || !count( $results ) ) {
|
||||
return true;
|
||||
}
|
||||
$pageIds = array_keys( $results );
|
||||
$api = new ApiMain( new FauxRequest(
|
||||
array(
|
||||
'action' => 'query',
|
||||
'prop' => 'extracts',
|
||||
'explaintext' => true,
|
||||
'exintro' => true,
|
||||
'exlimit' => count( $results ),
|
||||
'pageids' => implode( '|', $pageIds ),
|
||||
) )
|
||||
);
|
||||
$api->execute();
|
||||
$data = $api->getResultData();
|
||||
foreach ( $pageIds as $id ) {
|
||||
if ( isset( $data['query']['pages'][$id]['extract']['*'] ) ) {
|
||||
$results[$id]['extract'] = $data['query']['pages'][$id]['extract']['*'];
|
||||
$results[$id]['extract trimmed'] = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
use TextExtracts\ExtractFormatter;
|
||||
|
||||
/**
|
||||
* @group TextExtracts
|
Loading…
Reference in a new issue