<?php

// get wiki thumbnail and thumbnail tracking
$isOnWikiMatch = isset($result['onWikiMatch']) && $result['onWikiMatch'];
$imageFileName = PromoImage::fromPathname($result['image_s'])->ensureCityIdIsSet($result['id'])->getPathname();
$imageOriginalURL = ImagesService::getImageSrcByTitle($corporateWikiId, $imageFileName, WikiaSearchController::CROSS_WIKI_PROMO_THUMBNAIL_WIDTH, WikiaSearchController::CROSS_WIKI_PROMO_THUMBNAIL_HEIGHT);
if (!empty($imageOriginalURL)) {
    $imageURL = ImagesService::overrideThumbnailFormat($imageOriginalURL, ImagesService::EXT_JPG);
    $thumbTracking = 'class="wiki-thumb-tracking" data-pos="' . $pos . '" data-event="search_click_wiki-thumb"';
}
if (empty($imageURL)) {
    // display placeholder image if no thumbnail
    $imageURL = $wg->ExtensionsPath . '/wikia/Search/images/wiki_image_placeholder.png';
    $thumbTracking = 'class="wiki-thumb-tracking" data-pos="' . $pos . '" data-event="search_click_wiki-no-thumb"';
}
$service = new Wikia\Search\MediaWikiService();
$pagesMsg = $service->shortnumForMsg($result['articles_i'] ?: 0, 'wikiasearch2-pages');
$imgMsg = $service->shortnumForMsg($result['images_i'] ?: 0, 'wikiasearch2-images');
$videoMsg = $service->shortnumForMsg($result['videos_i'] ?: 0, 'wikiasearch2-videos');
$title = ($sn = $result->getText('sitename_txt')) ? $sn : $result->getText('headline_txt');
$url = $result->getText('url');
?>

<li class="result">
	<?php 
$suffix = $result['exactWikiMatch'] ? "match" : "wiki";
$trackingData = 'class="result-link" data-pos="' . $pos . '" data-event="search_click_' . $suffix . '"';
?>
	<a href="<?php 
echo $url;
?>
 /**
  * @param array $wikiIds
  * @param int $imageWidth
  * @param int $imageHeight
  *
  * @return mixed|null|string
  */
 public function getWikiImages($wikiIds, $imageWidth, $imageHeight = self::IMAGE_HEIGHT_KEEP_ASPECT_RATIO)
 {
     $images = array();
     try {
         $db = wfGetDB(DB_SLAVE, array(), $this->wg->ExternalSharedDB);
         $tables = array('city_visualization');
         $fields = array('city_id', 'city_lang_code', 'city_main_image');
         $conds = array('city_id' => $wikiIds);
         $results = $db->select($tables, $fields, $conds, __METHOD__, array(), array());
         while ($row = $results->fetchObject()) {
             $promoImage = PromoImage::fromPathname($row->city_main_image);
             $promoImage->ensureCityIdIsSet($row->city_id);
             $file = $promoImage->corporateFileByLang($row->city_lang_code);
             if ($file->exists()) {
                 $imageServing = new ImageServing(null, $imageWidth, $imageHeight);
                 $images[$row->city_id] = ImagesService::overrideThumbnailFormat($imageServing->getUrl($file, $file->getWidth(), $file->getHeight()), ImagesService::EXT_JPG);
             }
         }
     } catch (Exception $e) {
         Wikia::log(__METHOD__, false, $e->getMessage());
     }
     return $images;
 }
 private function prepareWikisForVisualization($batch)
 {
     foreach ($batch as $slotName => &$wikis) {
         $size = $this->getProcessedWikisImgSizes($slotName);
         foreach ($wikis as &$wiki) {
             if (!empty($wiki['image'])) {
                 $wiki['main_image'] = $wiki['image'];
             }
             $wiki['image'] = ImagesService::overrideThumbnailFormat($this->getImageUrl($wiki['main_image'], $size->width, $size->height), ImagesService::EXT_JPG);
             unset($wiki['main_image']);
         }
     }
     return $batch;
 }
 /**
  * Get URL for avatar
  *
  * @param string|User $user user name
  * @param int $avatarSize
  * @return String avatar's URL
  */
 static function getAvatarUrl($user, $avatarSize = 20)
 {
     global $wgEnableVignette;
     wfProfileIn(__METHOD__);
     static $avatarsCache;
     if ($user instanceof User) {
         $key = "{$user->getName()}::{$avatarSize}";
     } else {
         // assumes $user is a string with user name
         $key = "{$user}::{$avatarSize}";
     }
     if (isset($avatarsCache[$key])) {
         $avatarUrl = $avatarsCache[$key];
     } else {
         if (!$user instanceof User) {
             $user = self::getUser($user);
         }
         // handle anon users - return default avatar
         if (empty($user) || !class_exists('Masthead')) {
             $avatarUrl = self::getDefaultAvatar($avatarSize);
             wfProfileOut(__METHOD__);
             return $avatarUrl;
         }
         $masthead = Masthead::newFromUser($user);
         // use per-user cachebuster when custom avatar is used
         $cb = !$masthead->isDefault() ? intval($user->getGlobalAttribute('avatar_rev')) : 0;
         if ($wgEnableVignette) {
             $avatarUrl = self::getVignetteUrl($masthead, $avatarSize, $cb);
         } else {
             $avatarUrl = $masthead->getThumbnailPurgeUrl($avatarSize);
             // Make URLs consistent and using no-cookie domain.  We need to pass a
             // stringified zero rather than an actual zero because this function
             // treats them differently o_O  Setting this to string zero matches
             // the anonymous user behavior (BugId:22190)
             $avatarUrl = wfReplaceImageServer($avatarUrl, $cb > 0 ? $cb : "0");
             // make avatars as JPG intead of PNGs / GIF but only when it will be a gain (most likely)
             if (intval($avatarSize) > self::PERFORMANCE_JPEG_THRESHOLD) {
                 $avatarUrl = ImagesService::overrideThumbnailFormat($avatarUrl, ImagesService::EXT_JPG);
             }
         }
         $avatarsCache[$key] = $avatarUrl;
     }
     wfProfileOut(__METHOD__);
     return $avatarUrl;
 }