Exemple #1
0
 function getRelatedImagesWidget($title)
 {
     global $wgUser;
     $exceptions = wfMsg('ih_exceptions');
     $imageExceptions = split("\n", $exceptions);
     $articles = ImageHelper::getLinkedArticles($title);
     $images = array();
     foreach ($articles as $t) {
         $results = ImageHelper::getImages($t->getArticleID());
         if (count($results) <= 1) {
             continue;
         }
         $titleDb = $title->getDBkey();
         foreach ($results as $row) {
             if ($row['il_to'] != $titleDb && !in_array($row['il_to'], $imageExceptions)) {
                 $images[] = $row['il_to'];
             }
         }
     }
     $count = 0;
     $maxLoc = count($images);
     $maxImages = $maxLoc;
     $finalImages = array();
     while ($count < 6 && $count < $maxImages) {
         $loc = rand(0, $maxLoc);
         if ($images[$loc] != null) {
             $image = Title::newFromText("Image:" . $images[$loc]);
             if ($image && $image->getArticleID() > 0) {
                 $file = wfFindFile($image);
                 if ($file && isset($file)) {
                     $finalImages[] = array('title' => $image, 'file' => $file);
                     $images[$loc] = null;
                     $count++;
                 } else {
                     $maxImages--;
                 }
             } else {
                 $maxImages--;
             }
             $images[$loc] = null;
         }
     }
     if (count($finalImages) > 0) {
         $html = '<div><h3>' . wfMsg('ih_relatedimages_widget') . '</h3><table style="margin-top:10px" class="image_siderelated">';
         $count = 0;
         foreach ($finalImages as $imageObject) {
             $image = $imageObject['title'];
             $file = $imageObject['file'];
             if ($count % 2 == 0) {
                 $html .= "<tr>";
             }
             $heightPreference = ImageHelper::heightPreference(127, 140, $file);
             $thumb = $file->getThumbnail(127, 140, true, true, $heightPreference);
             $imageUrl = $image->getFullURL();
             $thumbUrl = $thumb->url;
             $imageTitle = $imageName;
             $html .= "<td valign='top'>\n\t\t\t\t\t\t\t<a href='" . $imageUrl . "' title='" . $imageTitle . "' class='image'>\n\t\t\t\t\t\t\t<img border='0' class='mwimage101' src='" . wfGetPad($thumbUrl) . "' alt='" . $imageTitle . "'>\n\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t</td>";
             if ($count % 2 == 2) {
                 $html .= "</tr>";
             }
             $count++;
         }
         if ($count % 3 != 2) {
             $html .= "</tr>";
         }
         $html .= "</table></div>";
         return $html;
     }
 }