function displayCategoryTable()
 {
     global $wgOut;
     $catmap = Categoryhelper::getIconMap();
     ksort($catmap);
     $queryString = WikihowCategoryViewer::getViewModeParam();
     if (!empty($queryString)) {
         $queryString = "?" . $queryString;
     }
     $wgOut->addHTML("<div class='section_text'>");
     foreach ($catmap as $cat => $image) {
         $title = Title::newFromText($image);
         if ($title) {
             $file = wfFindFile($title, false);
             $sourceWidth = $file->getWidth();
             $sourceHeight = $file->getHeight();
             $heightPreference = false;
             if (self::CAT_HEIGHT > self::CAT_WIDTH && $sourceWidth > $sourceHeight) {
                 //desired image is portrait
                 $heightPreference = true;
             }
             $thumb = $file->getThumbnail(self::CAT_WIDTH, self::CAT_HEIGHT, true, true, $heightPreference);
             $category = urldecode(str_replace("-", " ", $cat));
             $catTitle = Title::newFromText("Category:" . $category);
             if ($catTitle) {
                 $wgOut->addHTML("<div class='thumbnail'><a href='{$catTitle->getLocalUrl()}{$queryString}'><img src='" . wfGetPad($thumb->getUrl()) . "' /><div class='text'><p><span>{$category}</span></p></div></a></div>");
             }
         }
     }
     $wgOut->addHTML("<div class='clearall'></div>");
     $wgOut->addHTML("</div><!-- end section_text -->");
 }
Exemplo n.º 2
0
 function getPinterestImage($title, $fromPad = true)
 {
     global $wgLanguageCode, $wgContLang;
     if (in_array($title->getNamespace(), array(NS_MAIN, NS_CATEGORY))) {
         if ($title->getNamespace() == NS_MAIN) {
             $file = Wikitext::getTitleImage($title);
             if ($file && isset($file)) {
                 $url = "/images/" . $file->getRel();
                 if ($fromPad) {
                     $url = wfGetPad($url);
                 }
                 return $url;
             }
         }
         $catmap = Categoryhelper::getIconMap();
         // still here? use default categoryimage
         // if page is a top category itself otherwise get top
         if (isset($catmap[urldecode($title->getPartialURL())])) {
             $cat = urldecode($title->getPartialURL());
         } else {
             $cat = Categoryhelper::getTopCategory($title);
             //INTL: Get the partial URL for the top category if it exists
             // For some reason only the english site returns the partial URL for getTopCategory
             if (isset($cat) && $wgLanguageCode != 'en') {
                 $title = Title::newFromText($cat);
                 if ($title != null) {
                     $cat = $title->getPartialURL();
                 }
             }
         }
         if (isset($catmap[$cat])) {
             $image = Title::newFromText($catmap[$cat]);
             $file = wfFindFile($image, false);
             if ($file) {
                 $url = "/images/" . $file->getRel();
                 if ($fromPad) {
                     $url = wfGetPad($url);
                 }
                 if ($url) {
                     return $url;
                 }
             } else {
                 $url = "/skins/WikiHow/images/wikihow_large.jpg";
                 if ($fromPad) {
                     $url = wfGetPad($url);
                 }
                 if ($url) {
                     return $url;
                 }
             }
         } else {
             $url = "/skins/WikiHow/images/wikihow_large.jpg";
             if ($fromPad) {
                 $url = wfGetPad($url);
             }
             if ($url) {
                 return $url;
             }
         }
     }
 }
Exemplo n.º 3
0
 static function getGalleryImage($title, $width, $height, $skip_parser = false)
 {
     global $wgMemc, $wgLanguageCode, $wgContLang;
     $cachekey = wfMemcKey('gallery1', $title->getArticleID(), $width, $height);
     $val = $wgMemc->get($cachekey);
     if ($val) {
         return $val;
     }
     if ($title->getNamespace() == NS_MAIN || $title->getNamespace() == NS_CATEGORY) {
         if ($title->getNamespace() == NS_MAIN) {
             $file = Wikitext::getTitleImage($title, $skip_parser);
             if ($file && isset($file)) {
                 //need to figure out what size it will actually be able to create
                 //and put in that info. ImageMagick gives prefence to width, so
                 //we need to see if it's a landscape image and adjust the sizes
                 //accordingly
                 $sourceWidth = $file->getWidth();
                 $sourceHeight = $file->getHeight();
                 $heightPreference = false;
                 if ($width / $height < $sourceWidth / $sourceHeight) {
                     //desired image is portrait
                     $heightPreference = true;
                 }
                 $thumb = $file->getThumbnail($width, $height, true, true, $heightPreference);
                 if ($thumb instanceof MediaTransformError) {
                     // we got problems!
                     $thumbDump = print_r($thumb, true);
                     wfDebug("problem getting thumb for article '{$title->getText()}' of size {$width}x{$height}, image file: {$file->getTitle()->getText()}, path: {$file->getPath()}, thumb: {$thumbDump}\n");
                 } else {
                     $wgMemc->set($cachekey, wfGetPad($thumb->getUrl()), 2 * 3600);
                     // 2 hours
                     return wfGetPad($thumb->getUrl());
                 }
             }
         }
         $catmap = Categoryhelper::getIconMap();
         // if page is a top category itself otherwise get top
         if (isset($catmap[urldecode($title->getPartialURL())])) {
             $cat = urldecode($title->getPartialURL());
         } else {
             $cat = Categoryhelper::getTopCategory($title);
             //INTL: Get the partial URL for the top category if it exists
             // For some reason only the english site returns the partial
             // URL for getTopCategory
             if (isset($cat) && $wgLanguageCode != 'en') {
                 $title = Title::newFromText($cat);
                 if ($title) {
                     $cat = $title->getPartialURL();
                 }
             }
         }
         if (isset($catmap[$cat])) {
             $image = Title::newFromText($catmap[$cat]);
             $file = wfFindFile($image, false);
             if ($file) {
                 $sourceWidth = $file->getWidth();
                 $sourceHeight = $file->getHeight();
                 $heightPreference = false;
                 if ($width / $height < $sourceWidth / $sourceHeight) {
                     //desired image is portrait
                     $heightPreference = true;
                 }
                 $thumb = $file->getThumbnail($width, $height, true, true, $heightPreference);
                 if ($thumb) {
                     $wgMemc->set($cachekey, wfGetPad($thumb->getUrl()), 2 * 3600);
                     // 2 hours
                     return wfGetPad($thumb->getUrl());
                 }
             }
         } else {
             $image = Title::makeTitle(NS_IMAGE, "Book_266.png");
             $file = wfFindFile($image, false);
             if (!$file) {
                 $file = wfFindFile("Book_266.png");
             }
             $sourceWidth = $file->getWidth();
             $sourceHeight = $file->getHeight();
             $heightPreference = false;
             if ($width / $height < $sourceWidth / $sourceHeight) {
                 //desired image is portrait
                 $heightPreference = true;
             }
             $thumb = $file->getThumbnail($width, $height, true, true, $heightPreference);
             if ($thumb) {
                 $wgMemc->set($cachekey, wfGetPad($thumb->getUrl()), 2 * 3600);
                 // 2 hours
                 return wfGetPad($thumb->getUrl());
             }
         }
     }
 }
Exemplo n.º 4
0
 static function getCategoryImageFile($title)
 {
     $catmap = Categoryhelper::getIconMap();
     // if page is a top category itself otherwise get top
     if (isset($catmap[urldecode($title->getPartialURL())])) {
         $cat = urldecode($title->getPartialURL());
     } else {
         $cat = Categoryhelper::getTopCategory($title);
         //INTL: Get the partial URL for the top category if it exists
         // For some reason only the english site returns the partial
         // URL for getTopCategory
         if (isset($cat) && $wgLanguageCode != 'en') {
             $title = Title::newFromText($cat);
             if ($title) {
                 $cat = $title->getPartialURL();
             }
         }
     }
     if (isset($catmap[$cat])) {
         $image = Title::newFromText($catmap[$cat]);
         $file = wfFindFile($image, false);
     } else {
         $image = Title::makeTitle(NS_IMAGE, "Book_266.png");
         $file = wfFindFile($image, false);
         if (!$file) {
             $file = wfFindFile("Book_266.png");
         }
     }
     return $file;
 }