-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchThumbs.php
61 lines (57 loc) · 1.37 KB
/
SearchThumbs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
use MediaWiki\MediaWikiServices;
class SearchThumbs {
/**
* @param OutputPage &$out
* @param Skin &$skin
*/
public static function onBeforePageDisplay( OutputPage &$out, Skin &$skin ) {
$out->addModuleStyles( 'ext.SearchThumbs' );
}
/**
* @param SpecialSearch $searchPage
* @param SearchResult $result
* @param string[] $terms
* @param string &$link
* @param string &$redirect
* @param string &$section
* @param string &$extract
* @param string $score
* @param string &$size
* @param string &$date
* @param string &$related
* @param string &$html
*/
public static function onShowSearchHit(
$searchPage,
$result,
$terms,
&$link,
&$redirect,
&$section,
&$extract,
$score,
&$size,
&$date,
&$related,
&$html
) {
$id = $result->getTitle()->getArticleID();
$services = MediaWikiServices::getInstance();
$provider = $services->getConnectionProvider();
$dbr = $provider->getReplicaDatabase();
$image = $dbr->newSelectQueryBuilder()
->select( 'pp_value' )
->from( 'page_props' )
->where( [ 'pp_propname' => 'page_image_free', 'pp_page' => $id ] )
->fetchField();
if ( $image ) {
$file = $services->getRepoGroup()->findFile( $image );
if ( $file ) {
$thumb = $file->createThumb( 120 );
$img = '<img class="mw-search-result-thumb" src="' . $thumb . '" />';
$link = $img . $link;
}
}
}
}