function peekNext()
 {
     wfProfileIn(__METHOD__);
     // Fill more articles into cache
     for ($i = $this->current + count($this->cache); $i < count($this->articles) && $i < $this->current + self::CHUNK_SIZE; $i++) {
         $link = $this->articles[$i];
         if (preg_match('@title="([^"]+)"@', $link, $matches)) {
             $title = Title::newFromText($matches[1]);
             if ($title) {
                 $image = Wikitext::getTitleImage($title);
                 // Make sure there aren't any issues with the image.
                 //Filenames with question mark characters seem to cause some problems
                 // Animatd gifs also cause problems.  Just use the default image if image is a gif
                 if (!($image && $image->getPath() && strpos($image->getPath(), "?") === false) || preg_match("@\\.gif\$@", $image->getPath())) {
                     $image = Wikitext::getDefaultTitleImage($title);
                 }
                 $this->cache[] = array('title' => $title, 'image' => $image);
             }
         }
     }
     wfProfileOut(__METHOD__);
     return $this->cache;
 }
 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;
             }
         }
     }
 }
 protected function makeRelatedBox($title, $forceProcessing = false)
 {
     global $wgUser;
     $sk = $wgUser->getSkin();
     $box = array();
     if (!$title || !$title->exists()) {
         return $box;
     }
     if (!$forceProcessing) {
         //exit if there's a word that will be too long
         $word_array = explode(' ', $title->getText());
         foreach ($word_array as $word) {
             if (strlen($word) >= 12) {
                 return $box;
             }
         }
     }
     //the image...
     $file = Wikitext::getTitleImage($title);
     if ($file && isset($file)) {
         $thumb = $file->getThumbnail(222, 222, true, true);
         if ($thumb->url == '') {
             return $box;
         }
         $box['bgimg'] = 'background-image:url(' . wfGetPad($thumb->url) . ')';
     } else {
         return $box;
     }
     if (strlen($title->getText()) > 35) {
         //too damn long
         $the_title = substr($title->getText(), 0, 32) . '...';
     } else {
         //we're good
         $the_title = $title->getText();
     }
     $box['url'] = $title->getLocalURL();
     $box['name'] = $the_title;
     $box['fullname'] = $title->getText();
     return $box;
 }
 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());
             }
         }
     }
 }
function getDocData($row, $noImages)
{
    $page_id = $row->page_id;
    $page_counter = $row->page_counter;
    $title = Title::newFromDBkey($row->page_title);
    if (!$title || !$title->exists()) {
        decho("unknown title for id", $page_id, false);
        return "";
    }
    $title_text = "<![CDATA[" . wfMsg('howto', $title->getText()) . "]]>";
    if (!$noImages) {
        $image = Wikitext::getTitleImage($title, true) ?: AppDataFormatter::getCategoryImageFile($title);
    }
    if ($image) {
        $heightPreference = $image->getWidth() > $image->getHeight();
        $thumb = WatermarkSupport::getUnwatermarkedThumbnail($image, AppDataFormatter::SEARCH_THUMB_WIDTH, AppDataFormatter::SEARCH_THUMB_HEIGHT, true, true, $heightPreference);
    }
    if ($thumb && !$thumb instanceof MediaTransformError) {
        $thumbUrl = AppDataFormatter::uriencode(wfGetPad($thumb->url));
    }
    $update = "";
    if ($noImages) {
        $update = 'update="set"';
    }
    $postData = '<doc>' . '<field name="id">' . $page_id . '</field>' . '<field name="title" ' . $update . '>' . $title_text . '</field>' . '<field name="page_counter" ' . $update . '>' . $page_counter . '</field>';
    if ($thumbUrl) {
        $postData .= '<field name="image_58x58">' . $thumbUrl . '</field>';
    }
    $postData .= '</doc>';
    return $postData;
}
Exemple #6
0
 static function getArticleImage($title, $sections = array())
 {
     // calling get title image with skip parser = true is faster even though comments indicate otherwise
     $image = Wikitext::getTitleImage($title, true);
     if ($image) {
         $image = self::getImageDetails($image);
     }
     if (!$image || !$image['url']) {
         // try any image on the page
         $image = self::findAnyImage($sections);
     }
     if (!$image || !$image['url']) {
         // still no image? get category image
         $image = self::getCategoryImageFile($title);
         if ($image) {
             $image = self::getImageDetails($image);
         }
     }
     return $image ?: array('obj' => '', 'url' => '', 'large' => '');
 }
$sk = $wgUser->getSkin();
if (count($argv)) {
    // you can pass in a parameter like A-L, or M-Z etc
    $parts = preg_split('@-@', $argv[0]);
    $where_sql = " AND page_title >= '{$parts[0]}' AND page_title <= '{$parts[1]}'";
}
$sql = 'SELECT page_title FROM page WHERE page_namespace = 0 AND page_is_redirect = 0' . $where_sql;
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->query($sql);
$titles = array();
foreach ($res as $row) {
    //next title...
    $title = Title::newFromDBkey($row->page_title);
    if (!$title || $title->getArticleID() == 0) {
        continue;
    }
    $titles[] = $title;
}
foreach ($titles as $title) {
    //get the title image
    $file = Wikitext::getTitleImage($title);
    if ($file && isset($file)) {
        //render it, crop it
        $thumb = $file->getThumbnail(222, 222, true, true);
        if ($thumb->url) {
            print $title->getText() . ": " . $thumb->url . "\n";
        } else {
            print $title->getText() . ": (none)\n";
        }
    }
}