/** * 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(); }