Two fixups to SearchResult
authorChad Horohoe <chadh@wikimedia.org>
Wed, 15 Jan 2014 00:20:53 +0000 (16:20 -0800)
committerChad Horohoe <chadh@wikimedia.org>
Wed, 15 Jan 2014 00:21:53 +0000 (16:21 -0800)
- Make variables protected. Only class that uses these is LuceneResult
  and it's fine
- Don't bother constructing a new file object if we've already got
  one in memory (we likely do)

Change-Id: I7973aff1e96297a2fea70392b765c93a8c884d52

includes/search/SearchEngine.php
includes/specials/SpecialSearch.php

index 94d39a5..9ebe5e7 100644 (file)
@@ -762,18 +762,22 @@ class SearchResult {
        /**
         * @var Revision
         */
-       var $mRevision = null;
-       var $mImage = null;
+       protected $mRevision = null;
+
+       /**
+        * @var File
+        */
+       protected $mImage = null;
 
        /**
         * @var Title
         */
-       var $mTitle;
+       protected $mTitle;
 
        /**
         * @var String
         */
-       var $mText;
+       protected $mText;
 
        /**
         * Return a new SearchResult and initializes it with a title.
@@ -840,10 +844,7 @@ class SearchResult {
         * @return Boolean
         */
        function isBrokenTitle() {
-               if ( is_null( $this->mTitle ) ) {
-                       return true;
-               }
-               return false;
+               return is_null( $this->mTitle );
        }
 
        /**
@@ -862,6 +863,14 @@ class SearchResult {
                return $this->mTitle;
        }
 
+       /**
+        * Get the file for this page, if one exists
+        * @return File|null
+        */
+       function getFile() {
+               return $this->mImage;
+       }
+
        /**
         * @return float|null if not supported
         */
index 98ae6f5..802efeb 100644 (file)
@@ -689,7 +689,8 @@ class SpecialSearch extends SpecialPage {
 
                // Include a thumbnail for media files...
                if ( $t->getNamespace() == NS_FILE ) {
-                       $img = wfFindFile( $t );
+                       $img = $result->getFile();
+                       $img = $img ?: wfFindFile( $t );
                        if ( $img ) {
                                $thumb = $img->transform( array( 'width' => 120, 'height' => 120 ) );
                                if ( $thumb ) {