MediaWiki REL1_34
Hooks.php
Go to the documentation of this file.
1<?php
2
3namespace TextExtracts;
4
5use ApiBase;
6use ApiMain;
7use ApiResult;
10
14class Hooks {
15
20 public static function onApiOpenSearchSuggest( &$results ) {
21 $config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
22 if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || $results === [] ) {
23 return;
24 }
25
26 foreach ( array_chunk( array_keys( $results ), ApiBase::LIMIT_SML1 ) as $pageIds ) {
27 $api = new ApiMain( new FauxRequest(
28 [
29 'action' => 'query',
30 'prop' => 'extracts',
31 'explaintext' => true,
32 'exintro' => true,
33 'exlimit' => count( $pageIds ),
34 'pageids' => implode( '|', $pageIds ),
35 ] )
36 );
37 $api->execute();
38 $data = $api->getResult()->getResultData( [ 'query', 'pages' ] );
39 foreach ( $pageIds as $id ) {
40 $contentKey = $data[$id]['extract'][ApiResult::META_CONTENT] ?? '*';
41 if ( isset( $data[$id]['extract'][$contentKey] ) ) {
42 $results[$id]['extract'] = $data[$id]['extract'][$contentKey];
43 $results[$id]['extract trimmed'] = false;
44 }
45 }
46 }
47 }
48}
This abstract class implements many basic API functions, and is the base of all API classes.
Definition ApiBase.php:42
This is the main API class, used for both external and internal processing.
Definition ApiMain.php:41
This class represents the result of the API operations.
Definition ApiResult.php:35
WebRequest clone which takes values from a provided array.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static onApiOpenSearchSuggest(&$results)
ApiOpenSearchSuggest hook handler.
Definition Hooks.php:20