/** * Check the file passed and fail if its a ghost file; that is, a file * that is from the video wiki but doesn't have any local record * * @param File $file A file object to check * @return bool Whether this hook has succeeded */ public static function onCheckGhostFile(&$file) { # If we're on a file page and we don't have any video_info for the current # title, treat it like a non-existent file if ($file && WikiaFileHelper::isFileTypeVideo($file)) { $title = $file->getTitle()->getDBkey(); $info = VideoInfo::newFromTitle($title); if (empty($info)) { F::app()->wg->IsGhostVideo = true; $file = null; } } return true; }
/** * @param $video - Video to flag in the video_info table * @param $removeVideo - Boolean, whether the video should be deleted or not * Flag removed status of video in the video_info table. All videos which have some sort of error * (deleted, private, or other), are flagged as removed, all working videos are flagged as not removed. */ private function setRemovedValue($video, $removeVideo) { $videoInfo = VideoInfo::newFromTitle($video['video_title']); if (is_null($videoInfo)) { $videoInfoHelper = new VideoInfoHelper(); $videoTitle = Title::newFromText($video['video_title'], NS_FILE); $videoInfo = $videoInfoHelper->getVideoInfoFromTitle($videoTitle); $videoInfo->addVideo(); } if ($removeVideo) { if (!$videoInfo->isRemoved()) { $videoInfo->removeVideo(); } } else { if ($videoInfo->isRemoved()) { $videoInfo->restoreVideo(); } } $removedStatus = $removeVideo ? "removed" : "not removed"; $this->debug("Video set as {$removedStatus}: " . $video['video_title']); }
/** * Override the getUser method for foreign files to return the user that originally added the * video rather than the one who uploaded it to the foreign repo * @param string $type * @return int|string */ public function getUser($type = 'text') { // Try to get video info for this file $info = VideoInfo::newFromTitle($this->getName()); if (!empty($info)) { $addedBy = $info->getAddedBy(); } // If we got an addedBy user ID, use that otherwise fall back to the parent method if (!empty($addedBy)) { if ($type == 'text') { $user = User::newFromId($addedBy); if ($user instanceof User) { return $user->getName(); } } else { return $addedBy; } } return parent::getUser($type); }
/** * Check if the premium video is added to the wiki * @param File $file * @return boolean $isAdded */ public static function isAdded($file) { $isAdded = true; if ($file instanceof File && !$file->isLocal() && F::app()->wg->WikiaVideoRepoDBName == $file->getRepo()->getWiki()) { $info = VideoInfo::newFromTitle($file->getTitle()->getDBkey()); if (empty($info)) { $isAdded = false; } } return $isAdded; }
/** * restore premium video * @param Title $title * @param integer $userId * @return boolean $affected */ public function restorePremiumVideo($title, $userId) { wfProfileIn(__METHOD__); $affected = false; if ($title instanceof Title) { $videoInfo = VideoInfo::newFromTitle($title->getDBKey()); if (empty($videoInfo)) { $newVideoInfo = $this->getVideoInfoFromTitle($title, true); if (!empty($newVideoInfo)) { // add premium video if not exist $affected = $newVideoInfo->addPremiumVideo($userId); } } else { $affected = $videoInfo->restoreVideo(); } } wfProfileOut(__METHOD__); return $affected; }