public function index() { wfProfileIn(__METHOD__); $socialSharingService = SocialSharingService::getInstance(); $this->setVal('networks', $socialSharingService->getNetworks(array('facebook', 'twitter', 'plusone', 'email'))); wfProfileOut(__METHOD__); }
/** * Returns pre-formatted social sharing urls and codes * @requestParam string fileTitle * @requestParam string articleTitle (optional) * @responseParam string url - raw url that is automically determined. This is determined to be either article url or file page url. * @responseParam string articleUrl - url to article page * @responseParam string fileUrl - url to file page * @responseParam string networks - contains id(facebook, twitter, etc) and urls of external social networks */ public function getShareCodes() { $fileTitle = urldecode($this->request->getVal('fileTitle', '')); $file = wfFindFile($fileTitle); $shareUrl = ''; $articleUrl = ''; $articleNS = ''; $articleTitleText = ''; $fileUrl = ''; $thumbUrl = ''; $networks = array(); if (!empty($file)) { $fileTitleObj = Title::newFromText($fileTitle, NS_FILE); $fileTitle = $fileTitleObj->getText(); $articleTitle = $this->request->getVal('articleTitle'); $articleTitleObj = Title::newFromText($articleTitle); if (!empty($articleTitleObj) && $articleTitleObj->exists()) { $fileParam = wfUrlencode($fileTitleObj->getDBKey()); $articleUrl = $articleTitleObj->getFullURL("file={$fileParam}"); $articleNS = $articleTitleObj->getNamespace(); $articleTitleText = $articleTitleObj->getText(); } // check if the file is added to the wiki if (WikiaFileHelper::isAdded($file)) { $fileUrl = $fileTitleObj->getFullURL(); } else { $fileUrl = WikiaFileHelper::getFullUrlPremiumVideo($fileTitleObj->getDBkey()); } // determine share url $sharingNamespaces = array(NS_MAIN, NS_CATEGORY); $shareUrl = !empty($articleUrl) && in_array($articleNS, $sharingNamespaces) ? $articleUrl : $fileUrl; $thumb = $file->transform(array('width' => 300, 'height' => 250)); $thumbUrl = $thumb->getUrl(); if (WikiaFileHelper::isFileTypeVideo($file)) { $msgSuffix = '-video'; } else { $msgSuffix = ''; } $msgArticleTitle = empty($articleUrl) ? $fileTitle : $articleTitleText; $linkDescription = wfMessage('lightbox-share-description' . $msgSuffix, $msgArticleTitle, $this->wg->Sitename)->text(); $shareNetworks = SocialSharingService::getInstance()->getNetworks(array('facebook', 'twitter', 'stumbleupon', 'reddit', 'plusone')); foreach ($shareNetworks as $network) { $networks[] = array('id' => $network->getId(), 'url' => $network->getUrl($shareUrl, $linkDescription)); } } $this->shareUrl = $shareUrl; $this->articleUrl = $articleUrl; $this->fileUrl = $fileUrl; $this->networks = $networks; $this->fileTitle = $fileTitle; $this->imageUrl = $thumbUrl; // set cache control to 1 day $this->response->setCacheValidity(WikiaResponse::CACHE_STANDARD); }