Beispiel #1
0
 function addWatermark($srcPath, $dstPath, $width, $height)
 {
     global $IP, $wgImageMagickConvertCommand, $wgImageMagickCompositeCommand;
     // do not add a watermark if the image is too small
     if (WatermarkSupport::validImageSize($width, $height) == false) {
         return;
     }
     $wm = $IP . '/skins/WikiHow/images/watermark.svg';
     $watermarkWidth = 1074.447;
     $targetWidth = $width / 8;
     $density = 72 * $targetWidth / $watermarkWidth;
     // we have a lower limit on density so the watermark is readable
     if ($density < 4.0) {
         $density = 4.0;
     }
     $cmd = "";
     // make sure image is rgb format so the watermark applies correctly
     if (WatermarkSupport::isCMYK($srcPath)) {
         $cmd = wfEscapeShellArg($wgImageMagickConvertCommand) . " " . wfEscapeShellArg($srcPath) . " " . "-colorspace RGB " . wfEscapeShellArg($dstPath) . ";";
         $srcPath = $dstPath;
     }
     $cmd = $cmd . wfEscapeShellArg($wgImageMagickConvertCommand) . " -density {$density} -background none " . wfEscapeShellArg($wm) . " miff:- | " . wfEscapeShellArg($wgImageMagickCompositeCommand) . " -gravity southeast -quality 100 -geometry +8+10 - " . wfEscapeShellArg($srcPath) . " " . wfEscapeShellArg($dstPath) . " 2>&1";
     $beforeExists = file_exists($dstPath);
     wfDebug(__METHOD__ . ": running ImageMagick: {$cmd}\n");
     $err = wfShellExec($cmd, $retval);
     $afterExists = file_exists($dstPath);
     $currentDate = `date`;
     wfErrorLog(trim($currentDate) . " {$cmd} b:" . ($beforeExists ? 't' : 'f') . " a:" . ($afterExists ? 't' : 'f') . "\n", '/tmp/watermark.log');
     wfProfileOut('watermark');
 }
 static function onImageConvert($params)
 {
     $physicalWidth = $params['physicalWidth'];
     $physicalHeight = $params['physicalHeight'];
     $addWatermark = isset($params[WatermarkSupport::ADD_WATERMARK]) ? $params[WatermarkSupport::ADD_WATERMARK] : '';
     $srcWidth = $params['srcWidth'];
     $srcHeight = $params['srcHeight'];
     if ($physicalWidth == $srcWidth && $physicalHeight == $srcHeight && $addWatermark) {
         WatermarkSupport::addWatermark($params['srcPath'], $params['dstPath'], $physicalWidth, $physicalHeight);
         return false;
     }
     return true;
 }
Beispiel #3
0
function wfImageConvert($cmd, $image, $srcPath, $dstPath, $params)
{
    if ($params[WatermarkSupport::FORCE_TRANSFORM] == false) {
        global $wgMemc;
        $key = wfMemcKey('imgconvert', md5($cmd));
        if ($wgMemc->get($key)) {
            return false;
        }
        $wgMemc->set($key, 1, 3600);
    }
    $physicalWidth = $params['physicalWidth'];
    $physicalHeight = $params['physicalHeight'];
    $addWatermark = $params[WatermarkSupport::ADD_WATERMARK];
    $srcWidth = $image->getWidth();
    $srcHeight = $image->getHeight();
    if ($physicalWidth == $srcWidth && $physicalHeight == $srcHeight && $addWatermark) {
        WatermarkSupport::addWatermark($srcPath, $dstPath, $physicalWidth, $physicalHeight);
        return false;
    }
    return true;
}
Beispiel #4
0
 function getArticleThumbWithPath($t, $width, $height, $file)
 {
     global $wgContLang, $wgLanguageCode;
     $sourceWidth = $file->getWidth();
     $sourceHeight = $file->getHeight();
     $xScale = $width / $sourceWidth;
     if ($height > $xScale * $sourceHeight) {
         $heightPreference = true;
     } else {
         $heightPreference = false;
     }
     $thumb = WatermarkSupport::getUnwatermarkedThumbnail($file, $width, $height, true, true, $heightPreference);
     //removed the fixed width for now
     $articleName = $t->getText();
     if ($wgLanguageCode == "zh") {
         $articleName = $wgContLang->convert($articleName);
     }
     $html = "<div class='thumbnail' ><a href='{$t->getFullUrl()}'><img src='" . wfGetPad($thumb->getUrl()) . "' alt='' /><div class='text'><p>" . wfMessage('Howto', '')->text() . "<br /><span>{$articleName}</span></p></div></a></div>";
     return $html;
 }
 public function execute()
 {
     global $IP;
     require_once "{$IP}/extensions/wikihow/common/S3.php";
     define('WH_USE_BACKUP_DB', true);
     $pageIds = array();
     // allow for the input files to be specified on the command line
     if ($this->getOption('stream')) {
         $data = stream_get_contents(STDIN);
         $data = array_map('trim', explode("\n", $data));
         foreach ($data as $inputTitle) {
             $title = Title::newFromText($inputTitle, 6);
             if (!$title) {
                 continue;
             }
             $id = $title->getArticleID();
             $pageIds[] = $id;
         }
     }
     // if provided title, add that to the array
     $titleText = $this->getOption('title');
     if ($titleText) {
         $title = Title::newFromText($titleText, 6);
         $id = $title->getArticleID();
         $pageIds[] = $id;
     }
     // if there is a start, add articles to the array
     $start = $this->getOption('start');
     if ($start) {
         $dbr = wfGetDB(DB_SLAVE);
         $options = array("page_id > {$start}", "page_namespace = 6");
         $stop = $this->getOption('stop');
         if ($stop) {
             $options[] = "page_id < {$stop}";
         }
         $res = $dbr->select("page", "page_id", $options, __FILE__);
         // put them all into an array first
         foreach ($res as $row) {
             $pageIds[] = $row->page_id;
         }
     }
     $purgeTitles = array();
     $filesToPurgeFromCDN = array();
     foreach ($pageIds as $pageId) {
         $title = Title::newFromID($pageId);
         $file = wfLocalFile($title);
         if (!$file) {
             continue;
         }
         $userName = $file->getUser("text");
         if (WatermarkSupport::isWikihowCreator($userName)) {
             decho("file", $title->getText(), false);
             if ($this->getOption('s3')) {
                 decho("will purge from s3", false, false);
                 self::purgeThumbnailsFromS3($file);
             }
             if ($this->getOption('regenerate')) {
                 decho("will regenerate thumbnails", $file->getThumbnails(), false);
                 WatermarkSupport::recreateThumbnails($file);
                 decho("regeneration of thumbnails complete", false, false);
             }
             if ($this->getOption('purgelocal')) {
                 decho("will purge local cache thumbnails", $file->getThumbnails(), false);
                 $file->purgeCache();
                 // get titles that point here so we can purge them and
                 // regenerate those pages so the thumbnails come back
                 $purgeTitles = array_unique(array_merge($purgeTitles, ImageHelper::getLinkedArticles($title)));
                 decho("purging of thumbnails complete", false, false);
             }
             if ($this->getOption('cdn')) {
                 $filesToPurgeFromCDN[] = $file;
             }
         }
     }
     //purge the titles that have linked to these images
     foreach ($purgeTitles as $linkedTitle) {
         decho('will purge', $linkedTitle, false);
         // will now get the parser output to refresh the thumbnail
         // or else cdn may get reset before the thumbnails are regenerated
         $wp = new WikiPage($linkedTitle);
         $wp->doPurge();
         $po = ParserOptions::newFromUser($wgUser);
         $wp->getParserOutput($po);
     }
     if ($this->getOption('cdn')) {
         decho("will purge from cdn", false, false);
         $this->purgeThumbnailsFromCDNetworks($filesToPurgeFromCDN);
     }
 }
Beispiel #6
0
 function getArticleThumbWithPath($t, $width, $height, $file)
 {
     $sourceWidth = $file->getWidth();
     $sourceHeight = $file->getHeight();
     $xScale = $width / $sourceWidth;
     if ($height > $xScale * $sourceHeight) {
         $heightPreference = true;
     } else {
         $heightPreference = false;
     }
     $thumb = WatermarkSupport::getUnwatermarkedThumbnail($file, $width, $height, true, true, $heightPreference);
     //removed the fixed width for now
     $html = "<div class='thumbnail' ><a href='{$t->getFullUrl()}'><img src='" . wfGetPad($thumb->url) . "' alt='' /><div class='text'><p>" . wfMsg('Howto', '') . "<br /><span>{$t->getText()}</span></p></div></a></div>";
     return $html;
 }
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;
}
Beispiel #8
0
 private static function formatResults($results)
 {
     $ret = array();
     if ($results) {
         foreach ($results as $title) {
             $image = self::getArticleImage($title);
             $abstract = self::getAbstract($title);
             $rev = GoodRevision::newFromTitle($title, $title->getArticleId());
             if ($rev) {
                 $revid = $rev->latestGood();
             }
             if ($image['obj']) {
                 // Required to make a cropped square image
                 $imageObj = $image['obj'];
                 $srcWidth = $imageObj->getWidth();
                 $srcHeight = $imageObj->getHeight();
                 $heightPreference = $srcWidth > $srcHeight;
                 $thumb = WatermarkSupport::getUnwatermarkedThumbnail($imageObj, self::SEARCH_THUMB_WIDTH, self::SEARCH_THUMB_HEIGHT, true, true, $heightPreference);
                 if (!$thumb instanceof MediaTransformError) {
                     $thumburl = AppDataFormatter::uriencode(wfGetPad($thumb->url));
                 }
             }
             unset($image['obj']);
             $ret[] = array('id' => intval($title->getArticleId()), 'revision_id' => $revid, 'title' => $title->getText(), 'fulltitle' => wfMsg('howto', $title->getText()), 'url' => self::makeFullURL($title->getPartialUrl()), 'image' => $image, 'image_58x58' => $thumburl, 'abstract' => $abstract);
         }
     }
     return $ret;
 }
 public static function getImageDetails($image)
 {
     $result = array('obj' => '', 'url' => '');
     if ($image) {
         $result['obj'] = $image;
         $thumb = WatermarkSupport::getUnwatermarkedThumbnail($image, self::INDEX_THUMB_MAX_WIDTH);
         if ($thumb && !$thumb instanceof MediaTransformError) {
             $result['url'] = self::uriencode(wfGetPad($thumb->getUrl()));
             $dim = self::getThumbnailDimensions($thumb);
             $result['width'] = $dim['width'];
             $result['height'] = $dim['height'];
         }
         $thumb = WatermarkSupport::getUnwatermarkedThumbnail($image, self::INDEX_THUMB_LARGE_MAX_WIDTH);
         if ($thumb && !$thumb instanceof MediaTransformError) {
             $largeUrl = self::uriencode(wfGetPad($thumb->getUrl()));
             if ($largeUrl != $result['url']) {
                 $result['large'] = self::uriencode(wfGetPad($thumb->getUrl()));
                 $dim = self::getThumbnailDimensions($thumb);
                 $result['large_width'] = $dim['width'];
                 $result['large_height'] = $dim['height'];
             }
         }
         $original = self::uriencode(wfGetPad($image->url));
         if ($original != $largeUrl) {
             $result['original'] = self::uriencode(wfGetPad($image->getUrl()));
             $result['original_width'] = intval($image->getWidth());
             $result['original_height'] = intval($image->getHeight());
         }
     }
     return $result;
 }
    if (!$articleTitle) {
        continue;
    }
    $articleName = $articleTitle->getPartialURL();
    echo "processing article: {$articleName} with id: {$articleId}\n";
    $processedCount = $processedCount + 1;
    $articleName = $articleTitle->getPartialURL();
    $imageLinks = array();
    $res = $dbr->select(array('imagelinks'), 'il_to', array('il_from' => $articleId));
    $found = "";
    foreach ($res as $row) {
        $title = Title::newFromText($row->il_to, NS_IMAGE);
        $imageFile = wfFindFile($title, false);
        if ($imageFile && $imageFile->fileExists) {
            // make sure it's a wikiphoto image
            if ($imageFile->user_text != "Wikiphoto") {
                continue;
            }
            $fullPath = $imageFile->getFullPath();
            //decho("checking", $fullPath, false);
            $cmyk = WatermarkSupport::isCMYK($fullPath);
            if ($cmyk) {
                $found = $fullPath;
                break;
            }
        }
    }
    if ($found != "") {
        echo "article with CMYK image: {$articleId} - {$articleName} image is: {$found}\n";
    }
}