/** * add premium video * @param integer $userId * @return boolean */ public function addPremiumVideo($userId) { wfProfileIn(__METHOD__); $this->addedAt = wfTimestamp(TS_MW); if (!empty($userId)) { $this->addedBy = $userId; } $affected = $this->addToDatabase(); // create file page when adding premium video to wiki $videoHandlerHelper = new VideoHandlerHelper(); $status = $videoHandlerHelper->addCategoryVideos($this->videoTitle, $this->addedBy); wfProfileOut(__METHOD__); return $affected; }
/** * Remove video * @requestParam string title * @responseParam string result [ok/error] * @responseParam string msg - result message */ public function removeVideo() { wfProfileIn(__METHOD__); $videoTitle = $this->getVal('title', ''); if (empty($videoTitle)) { $this->result = 'error'; $this->msg = wfMessage('videos-error-empty-title')->text(); wfProfileOut(__METHOD__); return; } // check if user is logged in if (!$this->wg->User->isLoggedIn()) { $this->result = 'error'; $this->msg = wfMessage('videos-error-not-logged-in')->text(); wfProfileOut(__METHOD__); return; } // check if user is blocked if ($this->wg->User->isBlocked()) { $this->result = 'error'; $this->msg = wfMessage('videos-error-blocked-user')->text(); wfProfileOut(__METHOD__); return; } // check if read-only if (wfReadOnly()) { $this->result = 'error'; $this->msg = wfMessage('videos-error-readonly')->text(); wfProfileOut(__METHOD__); return; } $error = ''; $title = Title::newFromText($videoTitle, NS_FILE); $file = $title instanceof Title ? wfFindfile($title) : false; if ($file instanceof File && WikiaFileHelper::isFileTypeVideo($file)) { // check permissions $permissionErrors = $title->getUserPermissionsErrors('delete', $this->wg->User); if (count($permissionErrors)) { $this->result = 'error'; $this->msg = wfMessage('videos-error-permissions')->text(); wfProfileOut(__METHOD__); return; } $reason = ''; $suppress = false; if ($file->isLocal()) { $status = Status::newFatal('cannotdelete', wfEscapeWikiText($title->getPrefixedText())); $page = WikiPage::factory($title); $dbw = wfGetDB(DB_MASTER); try { // delete the associated article first if ($page->doDeleteArticleReal($reason, $suppress, 0, false) >= WikiPage::DELETE_SUCCESS) { $status = $file->delete($reason, $suppress); if ($status->isOK()) { $dbw->commit(); } else { $dbw->rollback(); } } } catch (MWException $e) { // rollback before returning to prevent UI from displaying incorrect "View or restore N deleted edits?" $dbw->rollback(); $error = $e->getMessage(); } if ($status->isOK()) { $oldimage = null; $user = $this->wg->User; wfRunHooks('FileDeleteComplete', array(&$file, &$oldimage, &$page, &$user, &$reason)); } else { if (!empty($error)) { $error = $status->getMessage(); } } } else { $article = null; if ($title->exists()) { $article = Article::newFromID($title->getArticleID()); } else { $botUser = User::newFromName('WikiaBot'); $flags = EDIT_NEW | EDIT_SUPPRESS_RC | EDIT_FORCE_BOT; // @FIXME Set $article here after calling addCategoryVideos so that the doDeleteArticle call below works properly $videoHandlerHelper = new VideoHandlerHelper(); $status = $videoHandlerHelper->addCategoryVideos($title, $botUser, $flags); } if (is_object($article) && !$article->doDeleteArticle($reason, $suppress, 0, true, $error)) { if (empty($error)) { $error = wfMessage('videohandler-remove-error-unknown')->text(); } } } } else { $error = wfMessage('videohandler-error-video-no-exist')->text(); } if (empty($error)) { $this->result = 'ok'; $this->msg = wfMessage('videohandler-remove-video-modal-success', $title)->text(); } else { $this->result = 'error'; $this->msg = $error; } wfProfileOut(__METHOD__); }