/**
  * Reset the video thumbnail to its original image as defined by the video provider.
  * @param File $file The video file to reset
  * @param string|null $thumbnailUrl
  * @param int $delayIndex Corresponds to a delay for a job to be queued up if we aren't
  * able to reset the thumbnail. This index corresponds to a class constant kept in the
  * ApiWrapper classes.
  * @return FileRepoStatus The status of the publish operation
  */
 public function resetVideoThumb(File $file, $thumbnailUrl = null, $delayIndex = 0)
 {
     $mime = $file->getMimeType();
     list(, $provider) = explode('/', $mime);
     $videoId = $file->getVideoId();
     $title = $file->getTitle();
     $oUploader = new VideoFileUploader();
     $oUploader->setProvider($provider);
     $oUploader->setVideoId($videoId);
     $oUploader->setTargetTitle($title->getDBkey());
     if (empty($thumbnailUrl)) {
         $thumbnailUrl = $oUploader->getApiWrapper()->getThumbnailUrl();
     }
     $result = $oUploader->resetThumbnail($file, $thumbnailUrl, $delayIndex);
     if ($result->isGood()) {
         // update data and clear cache
         $status = $this->updateThumbnailData($file);
         if (!$status->isGood()) {
             $result->fatal($status->getMessage());
         }
     }
     return $result;
 }
예제 #2
0
function upgradeYouTubeTag($editpage, $request)
{
    $app = F::app();
    // Don't convert <youtube> tags if the user is not logged in or is blocked.
    // It provides a loophole for those users to upload video.
    if (!$app->wg->User->isLoggedIn()) {
        return true;
    }
    if ($app->wg->User->isBlocked()) {
        return true;
    }
    if (!$app->wg->User->isAllowed('videoupload')) {
        return true;
    }
    $text = $editpage->textbox1;
    // Note that we match <nowiki> here to consume that text and any possible
    // <youtube> tags within it.  We don't want to convert anything within <nowiki>
    $text = preg_replace_callback('/(<nowiki>.*?<\\/nowiki>)|(<youtube([^>]*)>([^<]+)<\\/youtube>)/i', function ($matches) {
        // If we don't have a youtube match (its a nowiki tag) return as is
        if (empty($matches[2])) {
            return $matches[0];
        }
        // Separate the Youtube ID and parameters
        $paramText = trim($matches[3]);
        // Node value can look like: <youtube_id>|400px|thumb|center
        // @TODO evaluate calling parser to parse params and upload correctly styled video
        $nodeValues = explode('|', $matches[4]);
        $ytid = trim($nodeValues[0]);
        // Check to see if the whole URL is used
        if (preg_match('/(?:youtube\\.com\\/watch\\?(?:[^&]*&)*v=|youtu\\.be\\/)([^?&\\n]+)/', $ytid, $ytidMatches) === 1) {
            $ytid = $ytidMatches[1];
        }
        // Parse out the width and height parameters
        $params = parseSizeParams($paramText);
        // If height is less than 30, they probably are using this as an audio file
        // so don't bother converting it.
        if ($params['height'] <= AUDIO_ONLY_HEIGHT) {
            return $matches[0];
        }
        $url = 'http://www.youtube.com/watch?v=' . $ytid;
        $videoService = new VideoService();
        $videoFileUploader = new VideoFileUploader();
        $videoFileUploader->setExternalUrl($url);
        $apiWrapper = $videoFileUploader->getApiWrapper();
        if (!$apiWrapper->videoExists()) {
            return createRawOutput($matches[0]);
        }
        $retval = $videoService->addVideo($url);
        if (is_array($retval)) {
            list($title, $videoPageId, $videoProvider) = $retval;
            return "[[{$title}|" . $params['width'] . "px]]";
        } else {
            return $matches[0];
        }
    }, $text);
    $editpage->textbox1 = $text;
    return true;
}