/**
  * swap video
  * @requestParam string videoTitle
  * @requestParam string newTitle
  * @requestParam integer currentPage
  * @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 swapVideo()
 {
     $videoTitle = $this->request->getVal('videoTitle', '');
     $newTitle = $this->request->getVal('newTitle', '');
     $currentPage = $this->getVal('currentPage', 1);
     $sort = 'recent';
     // set default value for response params
     $this->setDefaultParams();
     // validate action
     $validAction = $this->sendRequest('LicensedVideoSwapSpecial', 'validateAction', array('videoTitle' => $videoTitle));
     $msg = $validAction->getVal('msg', '');
     if (!empty($msg)) {
         $this->result = 'error';
         $this->msg = $msg;
         return;
     }
     $file = WikiaFileHelper::getVideoFileFromTitle($videoTitle);
     // check if file exists
     if (empty($file)) {
         $this->html = '';
         $this->result = 'error';
         $this->msg = wfMessage('videohandler-error-video-no-exist')->text();
         return;
     }
     $helper = new LicensedVideoSwapHelper();
     // check if the file is swapped
     $articleId = $file->getTitle()->getArticleID();
     if ($helper->isSwapped($articleId)) {
         $this->result = 'error';
         $this->msg = wfMessage('lvs-error-already-swapped')->text();
         return;
     }
     // check if the file is premium
     if (!$file->isLocal()) {
         $this->result = 'error';
         $this->msg = wfMessage('lvs-error-permission')->text();
         return;
     }
     // set swap status
     $helper->setPageStatusInfo($articleId);
     // check if the new file exists
     $params = array('controller' => 'VideoHandlerController', 'method' => 'fileExists', 'fileTitle' => $newTitle);
     $response = ApiService::foreignCall($this->wg->WikiaVideoRepoDBName, $params, ApiService::WIKIA);
     if (empty($response['fileExists'])) {
         $helper->deletePageStatusInfo($articleId);
         $this->result = 'error';
         $this->msg = wfMessage('videohandler-error-video-no-exist')->text();
         return;
     }
     // remove local video
     $removeVideo = $this->sendRequest('VideoHandlerController', 'removeVideo', array('title' => $file->getName()));
     $result = $removeVideo->getVal('result', '');
     if ($result != 'ok') {
         $helper->deletePageStatusInfo($articleId);
         $this->result = 'error';
         $this->msg = $removeVideo->getVal('msg', '');
         return;
     }
     $isSameTitle = $videoTitle->getDBKey() == $newTitle;
     $swapValue['newTitle'] = $newTitle;
     // force to get new file for same title
     $newFile = WikiaFileHelper::getVideoFileFromTitle($newTitle, $isSameTitle);
     // check if new file exists
     if (empty($newFile)) {
         $helper->deletePageStatusInfo($articleId);
         $this->result = 'error';
         $this->msg = wfMessage('videohandler-error-video-no-exist')->text();
         return;
     }
     // add premium video
     wfRunHooks('AddPremiumVideo', array($newFile->getTitle()));
     $title = Title::newFromText($videoTitle->getDBKey(), NS_FILE);
     if (!$isSameTitle) {
         // add redirect url
         $status = $helper->addRedirectLink($title, $newFile->getTitle());
         if (!$status->isGood()) {
             $helper->deletePageStatusInfo($articleId);
             $this->result = 'error';
             $this->msg = $status->getMessage();
             return;
         }
         // set swap status
         $helper->setPageStatusSwap($title->getArticleID(), $articleId);
         $helper->setPageStatusInfoSwap($title->getArticleID(), $swapValue);
     } else {
         // set swap status
         $helper->setPageStatusSwapExact($title->getArticleID(), $articleId);
         $helper->setPageStatusInfoSwapExact($title->getArticleID(), $swapValue);
     }
     // remove old page status
     $helper->deletePageStatus($articleId);
     $helper->deletePageStatusInfo($articleId);
     // move suggestion data to new article
     $helper->moveSuggestionData($articleId, $title->getArticleID());
     // add to log
     $reason = wfMessage('lvs-log-summary', $file->getTitle()->getText(), $newFile->getTitle()->getText())->text();
     $helper->addLog($file->getTitle(), wfMessage('lvs-log-description')->text(), $reason);
     // clear cache for total videos
     $helper->invalidateCacheTotalVideos();
     // clear cache for total new videos
     $helper->invalidateCacheTotalNewVideos();
     // get video list
     $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(), 'data-new-title' => $newTitle->getDBKey());
     $undo = Xml::element('a', $undoOptions, wfMessage('lvs-undo-swap')->text());
     $this->msg = wfMessage('lvs-swap-video-success')->rawParams($undo)->parse();
 }