Allow SearchResults to specify that they matched file content
authorChad Horohoe <chadh@wikimedia.org>
Fri, 3 Jan 2014 19:00:22 +0000 (11:00 -0800)
committerNik Everett <neverett@wikimedia.org>
Fri, 17 Jan 2014 15:50:08 +0000 (10:50 -0500)
Change-Id: I214406250d10b971dcca025da508272d9805567b

includes/search/SearchEngine.php
includes/specials/SpecialSearch.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 9ebe5e7..e3a10ab 100644 (file)
@@ -988,6 +988,13 @@ class SearchResult {
        function getInterwikiPrefix() {
                return '';
        }
+
+       /**
+        * Did this match file contents (eg: PDF/DJVU)?
+        */
+       function isFileMatch() {
+               return false;
+       }
 }
 /**
  * A SearchResultSet wrapper for SearchEngine::getNearMatch
index 802efeb..18e777a 100644 (file)
@@ -687,10 +687,15 @@ class SpecialSearch extends SpecialPage {
                        );
                }
 
+               $fileMatch = '';
                // Include a thumbnail for media files...
                if ( $t->getNamespace() == NS_FILE ) {
                        $img = $result->getFile();
                        $img = $img ?: wfFindFile( $t );
+                       if ( $result->isFileMatch() ) {
+                               $fileMatch = "<span class='searchalttitle'>" .
+                                       $this->msg( 'search-file-match' )->escaped() . "</span>";
+                       }
                        if ( $img ) {
                                $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
                                if ( $thumb ) {
@@ -706,7 +711,7 @@ class SpecialSearch extends SpecialPage {
                                                $thumb->toHtml( array( 'desc-link' => true ) ) .
                                                '</td>' .
                                                '<td style="vertical-align: top;">' .
-                                               $link .
+                                               "{$link} {$fileMatch}" .
                                                $extract .
                                                "<div class='mw-search-result-data'>{$score}{$desc} - {$date}{$related}</div>" .
                                                '</td>' .
@@ -725,7 +730,7 @@ class SpecialSearch extends SpecialPage {
                        &$score, &$size, &$date, &$related,
                        &$html
                ) ) ) {
-                       $html = "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section}</div> {$extract}\n" .
+                       $html = "<li><div class='mw-search-result-heading'>{$link} {$redirect} {$section} {$fileMatch}</div> {$extract}\n" .
                                "<div class='mw-search-result-data'>{$score}{$size} - {$date}{$related}</div>" .
                                "</li>\n";
                }
index 41a38e4..d7b300c 100644 (file)
@@ -1839,6 +1839,7 @@ Details can be found in the [{{fullurl:{{#Special:Log}}/delete|page={{FULLPAGENA
 'search-result-score'              => 'Relevance: $1%',
 'search-redirect'                  => '(redirect $1)',
 'search-section'                   => '(section $1)',
+'search-file-match'                => '(matches file content)',
 'search-suggest'                   => 'Did you mean: $1',
 'search-interwiki-caption'         => 'Sister projects',
 'search-interwiki-default'         => '$1 results:',
index 80c2d6a..64214d2 100644 (file)
@@ -2914,6 +2914,7 @@ Parameters:
 * \$1 - a link to the redirect to the page (so, \$1 is the page that the search result is redirected '''from''')",
 'search-section' => 'This text will be shown on the search result listing after the page title of a result if the search algorithm thinks that section is more relevant than the rest of the page. $1 is a section title.
 {{Identical|Section}}',
+'search-file-match' => 'This text will be shown on the search result listing after the page title of a result if the search engine got search results from the contents of files, rather than the pages.',
 'search-suggest' => 'Used for "Did you mean" suggestions:
 * $1 - suggested link',
 'search-interwiki-caption' => 'Used in [[Special:Search]], when showing search results from other wikis.',
index 3534810..8b76a6b 100644 (file)
@@ -979,6 +979,7 @@ $wgMessageStructure = array(
                'search-result-score',
                'search-redirect',
                'search-section',
+               'search-file-match',
                'search-suggest',
                'search-interwiki-caption',
                'search-interwiki-default',