public static function add($file_url = '', $force_upload = false) { $uploader = new self(); $uploader->file_url = $file_url; $already_uploaded = $uploader->attachment_exists(); if ($already_uploaded && $force_upload === false) { return $already_uploaded; } $uploader->upload(); if (!$uploader->file_data) { return false; } $uploader->add_to_media_library(); return $uploader->attachment_id; }
/** * Translate URL to Title object. Can transparently upload new video if it doesn't exist * @param string $url * @param string $sTitle - if $requestedTitle new Video will be created you can optionally request * it's title (otherwise Video name from provider is used) * @param string $sDescription * @return null|Title */ public static function URLtoTitle($url, $sTitle = '', $sDescription = '') { wfProfileIn(__METHOD__); $oTitle = null; $oUploader = new self(); $oUploader->setExternalUrl($url); $oUploader->setTargetTitle($sTitle); if (!empty($sDescription)) { $categoryVideosTxt = self::getCategoryVideosWikitext(); if (strpos($sDescription, $categoryVideosTxt) === false) { $sDescription .= $categoryVideosTxt; } $oUploader->setDescription($sDescription); } $status = $oUploader->upload($oTitle); if ($status->isOK()) { wfProfileOut(__METHOD__); return $oTitle; } wfProfileOut(__METHOD__); return null; }