mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TextExtracts
synced 2024-11-24 00:04:35 +00:00
23dcce746a
Change-Id: If111014ef2d7aea5c72bdcf4600a9067e2e21e00
43 lines
1,010 B
PHP
43 lines
1,010 B
PHP
<?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;
|
|
}
|
|
}
|