mediawiki-extensions-TextEx.../includes/Hooks.php
Brad Jorsch 90a025b839 Remove pre-1.25 API compatibility code
Since this extension uses extension.json, it already requires 1.25+ so
no need to keep the old code around.

Change-Id: Id9e8fb026b26bb4db34fb22bd631205ce6f7072b
2016-09-20 15:23:35 -04:00

48 lines
1.2 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();
$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;
}
}
return true;
}
}