/** * Examine every non-premium video on this wiki and add suggestions where needed. * @return array - An associative array of stats from processing the videos */ private function processVideoList() { wfProfileIn(__METHOD__); $suggestDateProp = WPP_LVS_SUGGEST_DATE; $suggestExpire = time() - LicensedVideoSwapHelper::SUGGESTIONS_TTL; $pageNS = NS_FILE; // Only select videos with nonexistent or expired suggestions unless --refresh is on $whereExpired = ''; if (!$this->refresh) { $whereExpired = " AND (props IS NULL OR props <= {$suggestExpire})"; } // A list of all videos, returning the video title, its file page ID and $sql = "SELECT video_title as title,\n\t\t\t\t\t page.page_id as page_id,\n\t\t\t\t\t props as suggest_date\n\t\t\t\t FROM video_info\n\t\t\t\t JOIN page\n\t\t\t\t ON video_title = page_title\n\t\t\t\t AND page_namespace = {$pageNS}\n\t\t\t\t LEFT JOIN page_wikia_props\n\t\t\t\t ON page.page_id = page_wikia_props.page_id\n\t\t\t\t AND propname = {$suggestDateProp}\n\t\t\t\t WHERE removed = 0\n\t\t\t\t AND premium = 0\n\t\t\t\t {$whereExpired}"; $db = wfGetDB(DB_SLAVE); $results = $db->query($sql, __METHOD__); $lvsHelper = new LicensedVideoSwapHelper(); $vidsFound = 0; $vidsWithSugggestions = 0; $totalSuggestions = 0; // Get the total count of relevant videos while ($row = $db->fetchObject($results)) { $vidsFound++; $title = $row->title; $this->debug("Processing '{$title}'\n"); // This sets page_wikia_props for WPP_LVS_SUGGEST_DATE, WPP_LVS_EMPTY_SUGGEST and WPP_LVS_SUGGEST $suggestions = $lvsHelper->suggestionSearch($title, $this->test, $this->verbose); if ($suggestions) { $vidsWithSugggestions++; $totalSuggestions += count($suggestions); $this->debug("\tFound " . count($suggestions) . " suggestion(s)\n"); } else { $this->debug("\tNo suggestions found\n"); } } // clear cache for total videos $lvsHelper->invalidateCacheTotalVideos(); // clear cache for total new videos $lvsHelper->invalidateCacheTotalNewVideos(); wfProfileOut(__METHOD__); return array('vidsFound' => $vidsFound, 'vidsWithSuggestions' => $vidsWithSugggestions, 'totalSuggestions' => $totalSuggestions); }
/** * keep video * @requestParam string videoTitle * @requestParam integer currentPage * @requestParam string forever [true/false] * @requestParam array suggestions * @responseParam string result [ok/error] * @responseParam string msg - result message * @responseParam string html * @responseParam integer totalVideos - total videos with suggestions * @responseParam string redirect - redirect url */ public function keepVideo() { $videoTitle = $this->request->getVal('videoTitle', ''); $forever = $this->request->getVal('forever', ''); $suggestions = $this->request->getVal('suggestions', array()); $currentPage = $this->getVal('currentPage', 1); $sort = 'recent'; // set default value for response params $this->setDefaultParams(); // validate action $response = $this->sendRequest('LicensedVideoSwapSpecial', 'validateAction', array('videoTitle' => $videoTitle)); $msg = $response->getVal('msg', ''); if (!empty($msg)) { $this->result = 'error'; $this->msg = $msg; } $file = WikiaFileHelper::getVideoFileFromTitle($videoTitle); // check if file exists if (empty($file)) { $this->result = 'error'; $this->msg = wfMessage('videohandler-error-video-no-exist')->text(); return; } $helper = new LicensedVideoSwapHelper(); // set the LVS status of this file page $articleId = $file->getTitle()->getArticleID(); if ($helper->isKeptForever($articleId)) { $this->result = 'error'; $this->msg = wfMessage('lvs-error-already-kept-forever')->text(); return; } // get valid suggestions $suggestTitles = $helper->getValidVideos($suggestions); // get videos that have been suggested (kept videos) $historicalSuggestions = $helper->getHistoricalSuggestions($articleId); // combine suggested videos and current suggestions $value['suggested'] = array_unique(array_merge($historicalSuggestions, $suggestTitles)); // set keep status $isForever = $forever == 'true'; $helper->setPageStatusKeep($articleId, $isForever); $helper->setPageStatusInfoKeep($articleId, $value, $isForever); // clear cache for total videos $helper->invalidateCacheTotalVideos(); // clear cache for total new videos $helper->invalidateCacheTotalNewVideos(); // Get list video of non-premium videos available to swap $useMaster = true; $videoList = $helper->getRegularVideoList($sort, $currentPage, $useMaster); // get total videos with suggestions $this->totalVideos = $helper->getUnswappedVideoTotal($useMaster); if (empty($videoList)) { $this->redirect = $helper->getRedirectUrl($currentPage, $sort); } else { $this->html = $this->app->renderView('LicensedVideoSwapSpecial', 'row', array('videoList' => $videoList)); $this->html .= $helper->getPagination($this->totalVideos, $currentPage, $sort); } $undoOptions = array('class' => 'undo', 'href' => '#', 'data-video-title' => $videoTitle->getDBkey()); $undo = Xml::element('a', $undoOptions, wfMessage('lvs-undo-keep')->text()); $this->msg = wfMessage('lvs-keep-video-success')->rawParams($undo)->parse(); }