/** * Resize the steps images in a list of Title objects. */ private static function enlargeImagesUrls(&$urls, $recenter, $px, $introPx) { foreach ($urls as &$url) { if (!$url['title']) { $err = 'Unable to load article'; $numImages = 0; } else { list($err, $numImages) = Wikitext::enlargeImages($url['title'], $recenter, $px, $introPx); } $url['err'] = $err; $url['images'] = $numImages; } }
public function processHybridMedia($articleID, $creator, $videoList, $photoList) { $err = ''; $numSteps = 0; $replaced = 0; $vidBrTag = self::BRTAG_TO_VID ? self::BRTAG : ''; $imgBrTag = self::BRTAG_TO_IMG ? self::BRTAG : ''; self::d("processHybridMedia parse out steps section replacing it with a token, leaving the above and below wikitext intact"); // parse out steps section replacing it with a token, leaving // the above and below wikitext intact list($text, $url, $title) = $this->getArticleDetails($articleID); if (!$text || !$title) { $err = 'Could not find article ID ' . $articleID; } self::d("getArticleDetails: err:" . $err); if (!$err) { list($text, $steps, $stepsToken) = $this->cutStepsSection($text); if (!$stepsToken) { if (preg_match('@^(\\s|\\n)*#redirect@i', $text)) { $err = 'Could not parse Steps section out of article -- article text is #REDIRECT'; } else { $err = 'Could not parse Steps section out of article'; } } } $hybridMediaList = null; // try to place videos into wikitext, using tokens as placeholders. if (!$err) { $userIsScreenshotter = $this->isCreatorKnownScreenShotter($creator); list($err, $hybridMediaList) = $this->placeHybridMediaInSteps($articleID, $title, $videoList, $photoList, $text, $steps, $numSteps, $replaced, $userIsScreenshotter); } // detect if no photos and videos were to be processed if (!$err) { if (count($videoList) == 0 && count($photoList) == 0) { $err = 'No photos and videos to process'; } } // replace the tokens within the video or image tag if (!$err && $hybridMediaList && count($hybridMediaList) > 0) { $isAllLandscape = true; $hadColourProblems = false; $hadSizeProblems = false; $userIsScreenshotter = false; $isAllPhotoLandscape = count(photoList) > 0 ? true : false; $text = str_replace($stepsToken, $steps, $text); foreach ($hybridMediaList as &$media) { $video = $media['video']; if ($video) { //video related validation if (!empty($video['width']) && !empty($video['height']) && $video['width'] > $video['height']) { $sizeParam = WikiVisualTranscoder::VIDEO_LANDSCAPE_WIDTH; } else { $sizeParam = WikiVisualTranscoder::VIDEO_PORTRAIT_WIDTH; // Log first portrait video if (!$isAllLandscape) { $warning .= "portrait:{$video['name']}\n"; } $isAllLandscape = false; } // Log pixel width issues if (!$userIsScreenshotter && !$hadSizeProblems && !empty($video['width']) && $video['width'] < WikiVisualTranscoder::VIDEO_WARNING_MIN_WIDTH) { $warning .= "size:{$video['width']}px:{$video['name']}\n"; $hadSizeProblems = true; } } $image = $media['photo']; if ($image) { if (!empty($image['width']) && !empty($image['height']) && $image['width'] > $image['height']) { $sizeParam = WikiVisualTranscoder::IMAGE_LANDSCAPE_WIDTH; } else { $sizeParam = WikiVisualTranscoder::IMAGE_PORTRAIT_WIDTH; // Log first portrait image if (!$isAllPhotoLandscape) { $warning .= "portrait:{$image['name']}\n"; } $isAllPhotoLandscape = false; } // Detect colour profile issues if (!$hadColourProblems && !empty($image['filename'])) { $exifProfile = WikiPhoto::getExifColourProfile($image['filename']); if ($exifProfile && WikiPhoto::isBadWebColourProfile($exifProfile)) { $warning .= "colour:{$exifProfile}:{$image['name']}\n"; $hadColourProblems = true; } } // Log pixel width issues if (!$userIsScreenshotter && !$hadSizeProblems && !empty($image['width']) && $image['width'] < WikiVisualTranscoder::WARNING_MIN_WIDTH) { $warning .= "size:{$image['width']}px:{$image['name']}\n"; $hadSizeProblems = true; } // Log pixel width issues if (!$userIsScreenshotter && !$hadSizeProblems && !empty($image['width'])) { if ($image['width'] < WikiVisualTranscoder::WARNING_MIN_WIDTH) { $warning .= "size:{$image['width']}px:{$image['name']}\n"; $hadSizeProblems = true; } else { $maxImgDimen = $image['width'] > $image['height'] ? $image['width'] : $image['height']; if ($maxImgDimen > WikiVisualTranscoder::ERROR_MAX_IMG_DIMEN) { $err .= "size:{$image['width']}px > max size " . WikiVisualTranscoder::ERROR_MAX_IMG_DIMEN . "px:{$image['name']}\n"; $hadSizeProblems = true; } } } } self::d("video={$video}, image={$image}"); $mediaTag = null; if ($video && !$image) { //video only $mediaTag = $vidBrTag . '{{whvid|' . $video['mediawikiName'] . '|' . $video['previewMediawikiName'] . '}}'; $text = str_replace($video['token'], $mediaTag, $text); } elseif (!$video && $image) { //image only $mediaTag = $imgBrTag . '[[Image:' . $image['mediawikiName'] . '|center|' . $sizeParam . ']]'; $text = str_replace($image['token'], $mediaTag, $text); } elseif ($video && $image) { //hybrid $mediaTag = $vidBrTag . '{{whvid|' . $video['mediawikiName'] . '|' . $video['previewMediawikiName'] . '|' . $image['mediawikiName'] . '}}'; $text = str_replace($video['token'], $mediaTag, $text); } } } // remove certain templates from start of wikitext if (!$err) { $templates = array('illustrations', 'pictures', 'screenshots', 'stub'); $text = $this->removeTemplates($text, $templates); } // write wikitext and add/update wikivideo row if (!$err) { $err = $this->saveArticleText($articleID, $text); } // try to enlarge the uploaded photos of certain users if (!$err) { // now we want to ALWAYS enlarge the images for articles with ALL Landscape if ($isAllPhotoLandscape) { Wikitext::enlargeImages($title, true, AdminEnlargeImages::DEFAULT_CENTER_PIXELS); } } // if ($err) { // self::dbSetArticleProcessed($articleID, $creator, $err, $warning, $url, 0, $numSteps, 0, self::STATUS_ERROR); // } else { // self::dbSetArticleProcessed($articleID, $creator, '', $warning, $url, count($videoList), $numSteps, $replaced, self::STATUS_COMPLETE); // } // remove transcoding job db entries and s3 URIs //self::removeOldTranscodingJobs($articleID); $numPhotos = $photoList ? count($photoList) : 0; $numVideos = $photoList ? count($videoList) : 0; self::i("processed wikitext: {$creator} {$articleID} {$url} " . "photos=" . $numPhotos . ", " . "videos=" . $numVideos . " {$err}"); return array($err, $warning, $url, $numSteps, $replaced); // if ($err) { // self::dbSetArticleProcessed($articleID, $creator, $err, $warning, $url, 0, $numSteps, 0, self::STATUS_ERROR); // } else { // self::dbSetArticleProcessed($articleID, $creator, '', $warning, $url, count($videoList), $numSteps, $replaced, self::STATUS_COMPLETE); // } }
/** * Process all images for an article from the wikiphoto upload dir */ private static function processImages($articleID, $creator, $imageList, $warning) { $err = ''; $numSteps = 0; $replaced = 0; // load article list($text, $url, $title) = self::getArticleDetails($articleID); if (!$text || !$title) { $err = 'Could not find article ID ' . $articleID; } // parse out steps section replacing it with a token, leaving // the above and below wikitext intact if (!$err) { list($text, $steps, $stepsToken) = self::cutStepsSection($text); if (!$stepsToken) { if (preg_match('@^(\\s|\\n)*#redirect@i', $text)) { $err = 'Could not parse Steps section out of article -- article text is #REDIRECT'; } else { $err = 'Could not parse Steps section out of article'; } } } // check if user is a known screenshot uploader if (!$err) { $userIsScreenshotter = false; $screenshotters = explode("\n", ConfigStorage::dbGetConfig('wikiphoto-exclude-from-image-warning')); foreach ($screenshotters as $ssUser) { $ssUser = trim($ssUser); if (!$ssUser) { continue; } if (strtolower($ssUser) == strtolower($creator)) { $userIsScreenshotter = true; break; } } } // try to place images into wikitext, using tokens as placeholders. if (!$err) { $err = self::placeImagesInSteps($articleID, $title, $imageList, $text, $steps, $numSteps, $replaced, $userIsScreenshotter); } // detect if no photos were to be processed if (!$err) { if (count($imageList) == 0) { $err = 'No photos to process'; } } // replace the tokens within the image tag if (!$err) { $isAllLandscape = true; $hadColourProblems = false; $hadSizeProblems = false; $text = str_replace($stepsToken, $steps, $text); foreach ($imageList as $image) { if (!empty($image['width']) && !empty($image['height']) && $image['width'] > $image['height']) { $sizeParam = self::IMAGE_LANDSCAPE_WIDTH; } else { $sizeParam = self::IMAGE_PORTRAIT_WIDTH; // Log first portrait image if (!$isAllLandscape) { $warning .= "portrait:{$image['name']}\n"; } $isAllLandscape = false; } // Detect colour profile issues if (!$hadColourProblems && !empty($image['filename'])) { $exifProfile = WikiPhoto::getExifColourProfile($image['filename']); if ($exifProfile && WikiPhoto::isBadWebColourProfile($exifProfile)) { $warning .= "colour:{$exifProfile}:{$image['name']}\n"; $hadColourProblems = true; } } // Log pixel width issues if (!$userIsScreenshotter && !$hadSizeProblems && !empty($image['width']) && $image['width'] < self::WARNING_MIN_WIDTH) { $warning .= "size:{$image['width']}px:{$image['name']}\n"; $hadSizeProblems = true; } $imageTag = '[[Image:' . $image['mediawikiName'] . '|right|' . $sizeParam . ']]'; $text = str_replace($image['token'], $imageTag, $text); } } // remove certain templates from start of wikitext if (!$err) { $templates = array('illustrations', 'pictures', 'screenshots', 'stub'); $text = self::removeTemplates($text, $templates); } // write wikitext and add/update wikiphoto row if (!$err) { $err = self::saveArticleText($articleID, $text); } // try to enlarge the uploaded photos of certain users if (!$err) { // now we want to ALWAYS enlarge the images for articles with ALL Landscape if ($isAllLandscape) { Wikitext::enlargeImages($title, true, AdminEnlargeImages::DEFAULT_CENTER_PIXELS); } } if ($err) { self::dbSetArticleProcessed($articleID, $creator, $err, $warning, $url, 0, $numSteps, 0); } else { self::dbSetArticleProcessed($articleID, $creator, '', $warning, $url, count($imageList), $numSteps, $replaced); } return array($err, $title); }