Allow search to return matching category
authorNik Everett <neverett@wikimedia.org>
Fri, 24 Oct 2014 00:15:18 +0000 (20:15 -0400)
committerNik Everett <neverett@wikimedia.org>
Fri, 24 Oct 2014 00:15:18 +0000 (20:15 -0400)
Will be used by Cirrus.

Change-Id: I60e6b19d3b59ebf9bb45cc61d16936dfc7e4c708

includes/search/SearchResult.php
includes/specials/SpecialSearch.php
languages/i18n/en.json
languages/i18n/qqq.json

index aeaba8d..2cdf9f4 100644 (file)
@@ -185,6 +185,13 @@ class SearchResult {
                return null;
        }
 
+       /**
+        * @return string Highlighted relevant category name or '' if none or not supported
+        */
+       public function getCategorySnippet() {
+               return '';
+       }
+
        /**
         * @return string Timestamp
         */
index 3cb5444..895f1e8 100644 (file)
@@ -621,8 +621,9 @@ class SpecialSearch extends SpecialPage {
                $redirectText = $result->getRedirectSnippet();
                $sectionTitle = $result->getSectionTitle();
                $sectionText = $result->getSectionSnippet();
-               $redirect = '';
+               $categorySnippet = $result->getCategorySnippet();
 
+               $redirect = '';
                if ( !is_null( $redirectTitle ) ) {
                        if ( $redirectText == '' ) {
                                $redirectText = null;
@@ -635,7 +636,6 @@ class SpecialSearch extends SpecialPage {
                }
 
                $section = '';
-
                if ( !is_null( $sectionTitle ) ) {
                        if ( $sectionText == '' ) {
                                $sectionText = null;
@@ -647,6 +647,13 @@ class SpecialSearch extends SpecialPage {
                                "</span>";
                }
 
+               $category = '';
+               if ( $categorySnippet ) {
+                       $category = "<span class='searchalttitle'>" .
+                               $this->msg( 'search-category' )->rawParams( $categorySnippet )->text() .
+                               "</span>";
+               }
+
                // format text extract
                $extract = "<div class='searchresult'>" . $result->getTextSnippet( $terms ) . "</div>";
 
@@ -691,7 +698,7 @@ class SpecialSearch extends SpecialPage {
                                                $thumb->toHtml( array( 'desc-link' => true ) ) .
                                                '</td>' .
                                                '<td style="vertical-align: top;">' .
-                                               "{$link} {$redirect} {$section} {$fileMatch}" .
+                                               "{$link} {$redirect} {$category} {$section} {$fileMatch}" .
                                                $extract .
                                                "<div class='mw-search-result-data'>{$desc} - {$date}</div>" .
                                                '</td>' .
@@ -712,7 +719,7 @@ class SpecialSearch extends SpecialPage {
                        &$html
                ) ) ) {
                        $html = "<li><div class='mw-search-result-heading'>" .
-                               "{$link} {$redirect} {$section} {$fileMatch}</div> {$extract}\n" .
+                               "{$link} {$redirect} {$category} {$section} {$fileMatch}</div> {$extract}\n" .
                                "<div class='mw-search-result-data'>{$size} - {$date}</div>" .
                                "</li>\n";
                }
index b6ee3c7..1c6890c 100644 (file)
        "search-result-category-size": "{{PLURAL:$1|1 member|$1 members}} ({{PLURAL:$2|1 subcategory|$2 subcategories}}, {{PLURAL:$3|1 file|$3 files}})",
        "search-redirect": "(redirect $1)",
        "search-section": "(section $1)",
+       "search-category": "(category $1)",
        "search-file-match": "(matches file content)",
        "search-suggest": "Did you mean: $1",
        "search-interwiki-caption": "Sister projects",
index edd522a..61fbc88 100644 (file)
        "search-result-category-size": "Parameters:\n* $1 - number of members in this category. $1 is equal to $2+$3.\n* $2 - number of subcategories\n* $3 - number of files",
        "search-redirect": "\"Redirect\" is a noun here, not a verb.\n\nParameters:\n* $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.\n{{Identical|Section}}",
+       "search-category": "This text will be shown on the search result listing after the page title of a result if the search algorithm thinks that the page being in a particular category is relevant. $1 is the category's name with any matching portion highlighted.\n",
        "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:\n* $1 - suggested link",
        "search-interwiki-caption": "Used in [[Special:Search]], when showing search results from other wikis.",