X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fsearch%2FSearchResult.php;h=2f20d9d52d8f3763183f5254141216f8d5fd2c06;hb=c4568ad41b7a1d6ba6669812529cddfe2b1e455a;hp=21effbbc988f9e675ed93d861599e8120d4776a0;hpb=500889f19005b4aed93c5b6eaafd35689fce7dcd;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/search/SearchResult.php b/includes/search/SearchResult.php index 21effbbc98..2f20d9d52d 100644 --- a/includes/search/SearchResult.php +++ b/includes/search/SearchResult.php @@ -56,15 +56,25 @@ class SearchResult { */ protected $searchEngine; + /** + * A function returning a set of extension data. + * @var Closure|null + */ + protected $extensionData; + /** * Return a new SearchResult and initializes it with a title. * * @param Title $title + * @param SearchResultSet $parentSet * @return SearchResult */ - public static function newFromTitle( $title ) { + public static function newFromTitle( $title, SearchResultSet $parentSet = null ) { $result = new static(); $result->initFromTitle( $title ); + if ( $parentSet ) { + $parentSet->augmentResult( $result ); + } return $result; } @@ -250,4 +260,41 @@ class SearchResult { function isFileMatch() { return false; } + + /** + * Get the extension data as: + * augmentor name => data + * @return array[] + */ + public function getExtensionData() { + if ( $this->extensionData ) { + return call_user_func( $this->extensionData ); + } else { + return []; + } + } + + /** + * Set extension data for this result. + * The data is: + * augmentor name => data + * @param Closure|array $extensionData Takes no arguments, returns + * either array of extension data or null. + */ + public function setExtensionData( $extensionData ) { + if ( $extensionData instanceof Closure ) { + $this->extensionData = $extensionData; + } elseif ( is_array( $extensionData ) ) { + wfDeprecated( __METHOD__ . ' with array argument', 1.32 ); + $this->extensionData = function () use ( $extensionData ) { + return $extensionData; + }; + } else { + $type = is_object( $extensionData ) + ? get_class( $extensionData ) + : gettype( $extensionData ); + throw new \InvalidArgumentException( + __METHOD__ . " must be called with Closure|array, but received $type" ); + } + } }