mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TextExtracts
synced 2024-11-24 00:04:35 +00:00
c3eb02a9a6
Change I7b37295e for mediawiki/core deprecates several methods, and more importantly changes the format of the data returned from ApiResult::getData(). This change should handle these differences in a backwards-compatible manner. Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678e
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace TextExtracts;
|
|
|
|
|
|
use ApiMain;
|
|
use ApiResult;
|
|
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();
|
|
if ( defined( 'ApiResult::META_CONTENT' ) ) {
|
|
$data = $api->getResult()->getResultData( array( 'query', 'pages' ) );
|
|
foreach ( $pageIds as $id ) {
|
|
$contentKey = isset( $data[$id]['extract'][ApiResult::META_CONTENT] )
|
|
? $data[$id]['extract'][ApiResult::META_CONTENT]
|
|
: '*';
|
|
if ( isset( $data[$id]['extract'][$contentKey] ) ) {
|
|
$results[$id]['extract'] = $data[$id]['extract'][$contentKey];
|
|
$results[$id]['extract trimmed'] = false;
|
|
}
|
|
}
|
|
} else {
|
|
$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;
|
|
}
|
|
}
|