+ // If the page doesn't *exist*... our search index is out of date.
+ // The least confusing at this point is to drop the result.
+ // You may get less results, but... oh well. :P
+ if( !$revision ) {
+ return "<!-- missing page " .
+ htmlspecialchars( $t->getPrefixedText() ) . "-->\n";
+ }
+
+ if( is_null( $result->getScore() ) ) {
+ // Search engine doesn't report scoring info
+ $score = '';
+ } else {
+ $percent = sprintf( '%2.1f', $result->getScore() * 100 );
+ $score = wfMsg( 'search-result-score', $wgLang->formatNum( $percent ) )
+ . ' - ';
+ }
+
+ // try to fetch everything from the search engine backend
+ // then fill-in what couldn't be fetched
+ $extract = $result->getTextSnippet();
+ $byteSize = $result->getByteSize();
+ $wordCount = $result->getWordCount();
+ $timestamp = $result->getTimestamp();
+ $redirectTitle = $result->getRedirectTitle();
+ $redirectText = $result->getRedirectSnippet();
+ $sectionTitle = $result->getSectionTitle();
+ $sectionText = $result->getSectionSnippet();
+
+ // fallback
+ if( is_null($extract) || is_null($wordCount) || is_null($byteSize) ){
+ $text = $revision->getText();
+ if( is_null($extract) )
+ $extract = $this->extractText( $text, $terms, $contextlines, $contextchars );
+ if( is_null($byteSize) )
+ $byteSize = strlen( $text );
+ if( is_null($wordCount) )
+ $wordCount = str_word_count( $text );
+ }
+ if( is_null($timestamp) ){
+ $timestamp = $revision->getTimestamp();
+ }
+
+ // format description
+ $size = wfMsgExt( 'search-result-size', array( 'parsemag', 'escape' ),
+ $sk->formatSize( $byteSize ),
+ $wordCount );
+ $date = $wgLang->timeanddate( $timestamp );
+
+ // format redirects / sections
+ $redirect = '';
+ if( !is_null($redirectTitle) )
+ $redirect = "<span class='searchalttitle'>"
+ .wfMsg('search-redirect',$sk->makeKnownLinkObj( $redirectTitle, $redirectText))
+ ."</span>";
+ $section = '';
+ if( !is_null($sectionTitle) )
+ $section = "<span class='searchalttitle'>"
+ .wfMsg('search-section', $sk->makeKnownLinkObj( $sectionTitle, $sectionText))
+ ."</span>";
+ // wrap extract
+ $extract = "<div class='searchresult'>".$extract."</div>";
+
+ // Include a thumbnail for media files...
+ if( $t->getNamespace() == NS_IMAGE ) {
+ $img = wfFindFile( $t );
+ if( $img ) {
+ $thumb = $img->getThumbnail( 120, 120 );
+ if( $thumb ) {
+ $desc = $img->getShortDesc();
+ wfProfileOut( $fname );
+ // Ugly table. :D
+ // Float doesn't seem to interact well with the bullets.
+ // Table messes up vertical alignment of the bullet, but I'm
+ // not sure what more I can do about that. :(
+ return "<li>" .
+ '<table class="searchResultImage">' .
+ '<tr>' .
+ '<td width="120" align="center">' .
+ $thumb->toHtml( array( 'desc-link' => true ) ) .
+ '</td>' .
+ '<td valign="top">' .
+ $link .
+ $extract .
+ "<div class='mw-search-result-data'>{$score}{$desc} - {$date}</div>" .
+ '</td>' .
+ '</tr>' .
+ '</table>' .
+ "</li>\n";
+ }
+ }
+ }
+
+ wfProfileOut( $fname );
+ return "<li>{$link} {$redirect} {$section} {$extract}\n" .
+ "<div class='mw-search-result-data'>{$score}{$size} - {$date}</div>" .
+ "</li>\n";