Move SearchResultProvideThumbnail hook to 'search'

This will no longer be a thing exclusive to REST API,
but will be used more widely for search.

This also introduced the (optional) $size param, for
which implementations (PageImages only) have already
been updated.

Depends-On: Ia30afcc43a0ecec772cd0a82dd9661e61f31a651
Change-Id: Ic9110345b4db69d268685b80ec8e4e33da95a050
Bug: T306883
This commit is contained in:
Matthias Mullie 2022-08-23 14:21:44 +02:00
parent d6f1692b16
commit 955e4bbf6e
4 changed files with 39 additions and 22 deletions

View file

@ -91,6 +91,9 @@ For notes on 1.38.x and older releases, see HISTORY.
* …
=== New developer features in 1.39 ===
* Added optional $size param to SearchResultProvideThumbnail hook.
* SearchResultProvideThumbnail hook interface moved from MediaWiki\Rest\Hook
namespace to MediaWiki\Search\Hook.
* JsonValidateSaveHook has been added to allow extensions to set additional
pre-save validations for specific JSON pages (T313254)
* Added 'PermissionErrorAudit' hook, enabling extensions to audit permission

View file

@ -487,7 +487,6 @@ class HookRunner implements
\MediaWiki\ResourceLoader\Hook\ResourceLoaderGetConfigVarsHook,
\MediaWiki\ResourceLoader\Hook\ResourceLoaderJqueryMsgModuleMagicWordsHook,
\MediaWiki\Rest\Hook\SearchResultProvideDescriptionHook,
\MediaWiki\Rest\Hook\SearchResultProvideThumbnailHook,
\MediaWiki\Revision\Hook\ContentHandlerDefaultModelForHook,
\MediaWiki\Revision\Hook\RevisionRecordInsertedHook,
\MediaWiki\Search\Hook\PrefixSearchBackendHook,
@ -499,6 +498,7 @@ class HookRunner implements
\MediaWiki\Search\Hook\SearchGetNearMatchHook,
\MediaWiki\Search\Hook\SearchIndexFieldsHook,
\MediaWiki\Search\Hook\SearchResultInitFromTitleHook,
\MediaWiki\Search\Hook\SearchResultProvideThumbnailHook,
\MediaWiki\Search\Hook\SearchResultsAugmentHook,
\MediaWiki\Search\Hook\ShowSearchHitHook,
\MediaWiki\Search\Hook\ShowSearchHitTitleHook,
@ -3313,10 +3313,10 @@ class HookRunner implements
);
}
public function onSearchResultProvideThumbnail( array $pageIdentities, &$thumbnails ) {
public function onSearchResultProvideThumbnail( array $pageIdentities, &$thumbnails, int $size = null ) {
return $this->container->run(
'SearchResultProvideThumbnail',
[ $pageIdentities, &$thumbnails ]
[ $pageIdentities, &$thumbnails, $size ]
);
}

View file

@ -2,27 +2,13 @@
namespace MediaWiki\Rest\Hook;
use MediaWiki\Search\Hook\SearchResultProvideThumbnailHook as SearchHook;
/**
* This is a hook handler interface, see docs/Hooks.md.
* Use the hook name "SearchResultProvideThumbnail" to register handlers implementing this interface.
*
* Called by REST SearchHandler in order to allow extensions to fill the 'thumbnail'
* field in rest search results. Warning: this hook, as well as SearchResultPageIdentity
* interface, is under development and still unstable.
*
* @unstable
* @ingroup Hooks
* @deprecated This interface will be removed as soon as all classes implementing it
* have been updated to implement MediaWiki\Search\Hook\SearchResultProvideThumbnailHook
*/
interface SearchResultProvideThumbnailHook {
/**
* This hook is called when generating search results in order to fill the 'thumbnail'
* field in an extension.
*
* @since 1.35
*
* @param array $pageIdentities Array (string=>SearchResultPageIdentity) where key is pageId
* @param array &$thumbnails Output array (string=>SearchResultThumbnail|null) where key
* is pageId and value is either a valid SearchResultThumbnail for given page or null
*/
public function onSearchResultProvideThumbnail( array $pageIdentities, &$thumbnails );
interface SearchResultProvideThumbnailHook extends SearchHook {
}

View file

@ -0,0 +1,28 @@
<?php
namespace MediaWiki\Search\Hook;
/**
* This is a hook handler interface, see docs/Hooks.md.
* Use the hook name "SearchResultProvideThumbnail" to register handlers implementing this interface.
*
* Called in order to allow extensions to fill the 'thumbnail' field in search results.
* Warning: this hook is under development and still unstable.
*
* @unstable
* @ingroup Hooks
*/
interface SearchResultProvideThumbnailHook {
/**
* This hook is called when generating search results in order to fill the 'thumbnail'
* field in an extension.
*
* @since 1.35
*
* @param array $pageIdentities Array (string=>PageIdentity) where key is pageId
* @param array &$thumbnails Output array (string=>SearchResultThumbnail|null) where key
* is pageId and value is either a valid SearchResultThumbnail for given page or null
* @param int|null $size size of thumbnail height and width in points
*/
public function onSearchResultProvideThumbnail( array $pageIdentities, &$thumbnails, int $size = null );
}