public function doSubmit() { global $wgOut, $wgRequest, $wgUser; $replaced = false; if ('' == $wgRequest->getVal('wpWikiaVideoAddName')) { if ('' != $wgRequest->getVal('wpWikiaVideoAddPrefilled')) { $this->mName = $wgRequest->getVal('wpWikiaVideoAddPrefilled'); $replaced = true; } else { $this->mName = ''; } } else { $this->mName = $wgRequest->getVal('wpWikiaVideoAddName'); } '' != $wgRequest->getVal('wpWikiaVideoAddUrl') ? $this->mUrl = $wgRequest->getVal('wpWikiaVideoAddUrl') : ($this->mUrl = ''); if ('' != $this->mName && '' != $this->mUrl) { $this->mName = ucfirst($this->mName); // sanitize all video titles $this->mName = VideoFileUploader::sanitizeTitle($this->mName); $title = Title::makeTitleSafe(NS_VIDEO, $this->mName); if ($title instanceof Title) { $permErrors = $title->getUserPermissionsErrors('edit', $wgUser); $permErrorsUpload = $title->getUserPermissionsErrors('upload', $wgUser); $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $wgUser); if ($permErrors || $permErrorsUpload || $permErrorsCreate) { header('X-screen-type: error'); $wgOut->addWikiMsg('wva-protected'); return; } if (WikiaFileHelper::useVideoHandlersExtForEmbed()) { $res = null; try { $res = VideoFileUploader::URLtoTitle($this->mUrl, $this->mName); } catch (Exception $e) { } if (!$res) { $wgOut->addHTML(wfMsg('wva-failure')); return; } } if (WikiaFileHelper::useWikiaVideoExtForEmbed()) { $video = new VideoPage($title); $video->parseUrl($this->mUrl); $video->setName($this->mName); $video->save(); } $sk = RequestContext::getMain()->getSkin(); $link_back = $sk->makeKnownLinkObj($title); if ($replaced) { $wgOut->addHTML(wfMsg('wva-success-replaced', $link_back)); } else { $wgOut->addHTML(wfMsg('wva-success', $link_back)); } } else { //bad title returned $wgOut->addHTML(wfMsg('wva-failure')); } } else { //one of two params blank $wgOut->addHTML(wfMsg('wva-failure')); } }
public function doSubmit() { global $wgOut; $errors = array(); $replaced = false; $this->mUrl = $this->getRequest()->getVal('wpWikiaVideoAddUrl', ''); $this->mName = $this->getRequest()->getVal('wpWikiaVideoAddName', ''); if ($this->mName == '') { $this->mName = $this->getRequest()->getVal('name', ''); if ($this->mName != '') { $replaced = true; } } if ($this->mUrl == '') { $errors['videoUrl'] = wfMessage('wva-failure')->text(); $this->showForm($errors); return; } else { if ($this->mName == '') { $videoService = new VideoService(); $retval = $videoService->addVideo($this->mUrl); if (is_array($retval)) { list($title, $videoPageId, $videoProvider) = $retval; } else { $errors['videoUrl'] = $retval; $this->showForm($errors); return; } } else { $this->mName = ucfirst($this->mName); // sanitize all video titles $this->mName = VideoFileUploader::sanitizeTitle($this->mName); $title = Title::makeTitleSafe(NS_FILE, $this->mName); if ($title instanceof Title) { $permErrors = $title->getUserPermissionsErrors('edit', $this->getUser()); $permErrorsUpload = $title->getUserPermissionsErrors('upload', $this->getUser()); $permErrorsCreate = $title->exists() ? array() : $title->getUserPermissionsErrors('create', $this->getUser()); if ($permErrors || $permErrorsUpload || $permErrorsCreate) { header('X-screen-type: error'); $wgOut->addWikiMsg('wva-protected'); return; } if (empty(F::app()->wg->allowNonPremiumVideos)) { $errors['videoUrl'] = wfMessage('videohandler-non-premium')->parse(); $this->showForm($errors); return; } if (WikiaFileHelper::useVideoHandlersExtForEmbed()) { $res = null; try { $res = VideoFileUploader::URLtoTitle($this->mUrl, $this->mName); } catch (Exception $e) { } if (!$res) { $errors['videoUrl'] = wfMessage('wva-failure')->text(); $this->showForm($errors); return; } } } else { //bad title returned $errors['name'] = wfMessage('wva-failure')->text(); $this->showForm($errors); return; } } } if ($replaced) { $successMsgKey = 'wva-success-replaced'; } else { $successMsgKey = 'wva-success'; } $query = array("sort" => "recent", "msg" => $successMsgKey, "msgTitle" => urlencode($title)); $wgOut->redirect(SpecialPage::getTitleFor("Videos")->getLocalUrl($query)); }