mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TextExtracts
synced 2024-11-24 00:04:35 +00:00
8d3ff14a93
Note how only two files mentioned the license before. For consistency it should be either all or none. Both solutions would be possible. Even *not* mentioning the license anywhere in these files would be fine from a legal perspective, as long as the relevant file COPYING is still there in the root folder of this extension. The overly long "deed" text does not serve much of a purpose. It's not a complete, legally relevant license text. It's hard to read as the fact this is "GPL2+" is surprisingly hard to find. The @license tag solves these problems, and is recognized by documentation generators. Change-Id: I7844be0c5f4f3d7562156cd9f34fe466552a9c9d
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace TextExtracts;
|
|
|
|
use ApiBase;
|
|
use ApiMain;
|
|
use ApiResult;
|
|
use FauxRequest;
|
|
use MediaWiki\MediaWikiServices;
|
|
|
|
/**
|
|
* @license GPL-2.0-or-later
|
|
*/
|
|
class Hooks {
|
|
|
|
/**
|
|
* ApiOpenSearchSuggest hook handler
|
|
* @param array &$results Array of search results
|
|
*/
|
|
public static function onApiOpenSearchSuggest( &$results ) {
|
|
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'textextracts' );
|
|
if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || $results === [] ) {
|
|
return;
|
|
}
|
|
|
|
foreach ( array_chunk( array_keys( $results ), ApiBase::LIMIT_SML1 ) as $pageIds ) {
|
|
$api = new ApiMain( new FauxRequest(
|
|
[
|
|
'action' => 'query',
|
|
'prop' => 'extracts',
|
|
'explaintext' => true,
|
|
'exintro' => true,
|
|
'exlimit' => count( $pageIds ),
|
|
'pageids' => implode( '|', $pageIds ),
|
|
] )
|
|
);
|
|
$api->execute();
|
|
$data = $api->getResult()->getResultData( [ 'query', 'pages' ] );
|
|
foreach ( $pageIds as $id ) {
|
|
$contentKey = $data[$id]['extract'][ApiResult::META_CONTENT] ?? '*';
|
|
if ( isset( $data[$id]['extract'][$contentKey] ) ) {
|
|
$results[$id]['extract'] = $data[$id]['extract'][$contentKey];
|
|
$results[$id]['extract trimmed'] = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|