/**
  * Load RelatedVideos NS article data (try to use cache layer)
  */
 protected function load($master = false)
 {
     wfProfileIn(__METHOD__);
     if (!$master) {
         $this->mData = F::app()->wg->memc->get($this->mMemcacheKey);
     }
     if (empty($this->mData)) {
         $article = Article::newFromID($this->mId);
         // check existence
         if (empty($article)) {
             wfDebug(__METHOD__ . ": RelatedVideos NS article doesn't exist\n");
             wfProfileOut(__METHOD__);
             return;
         }
         $lists = array();
         $lists[self::BLACKLIST_MARKER] = array();
         $lists[self::WHITELIST_MARKER] = array();
         $dbr = wfGetDB(DB_SLAVE);
         $res = $dbr->select(array('imagelinks'), array('il_to'), ' il_from = ' . $this->mId, __METHOD__);
         if (empty($res)) {
             return;
         }
         while ($row = $res->fetchObject($res)) {
             $sTitle = $row->il_to;
             $oTitle = Title::newFromText($sTitle, NS_VIDEO);
             if (is_object($oTitle) && WikiaFileHelper::isTitleVideo($oTitle)) {
                 $lists[self::WHITELIST_MARKER][] = $this->createEntry($sTitle);
             }
         }
         $this->mData = array('lists' => $lists);
         wfDebug(__METHOD__ . ": loaded from scratch\n");
         // store it in memcache
         F::app()->wg->memc->set($this->mMemcacheKey, $this->mData, self::CACHE_TTL);
     } else {
         wfDebug(__METHOD__ . ": loaded from memcache\n");
     }
     $this->mExists = true;
     wfProfileOut(__METHOD__);
     return;
 }
Пример #2
0
 /**
  * add video
  * @param string $url
  * @return string error message or array( $videoTitle, $videoPageId, $videoProvider )
  */
 public function addVideo($url)
 {
     $this->wf->ProfileIn(__METHOD__);
     if (empty($url)) {
         $this->wf->ProfileOut(__METHOD__);
         return $this->wf->Msg('videos-error-no-video-url');
     }
     try {
         if (WikiaFileHelper::isVideoStoredAsFile()) {
             // is it a WikiLink?
             $title = Title::newFromText($url);
             if (!$title || !WikiaFileHelper::isTitleVideo($title)) {
                 $title = Title::newFromText(str_replace(array('[[', ']]'), array('', ''), $url));
             }
             if (!$title || !WikiaFileHelper::isTitleVideo($title)) {
                 if (($pos = strpos($url, 'Video:')) !== false) {
                     $title = Title::newFromText(substr($url, $pos));
                 } elseif (($pos = strpos($url, 'File:')) !== false) {
                     $title = Title::newFromText(substr($url, $pos));
                 }
             }
             if ($title && WikiaFileHelper::isTitleVideo($title)) {
                 $videoTitle = $title;
                 $videoPageId = $title->getArticleId();
                 $videoProvider = '';
                 wfRunHooks('AddPremiumVideo', array($title));
             } else {
                 list($videoTitle, $videoPageId, $videoProvider) = $this->addVideoVideoHandlers($url);
             }
         } else {
             throw new Exception($this->wf->Msg('videos-error-old-type-video'));
         }
     } catch (Exception $e) {
         $this->wf->ProfileOut(__METHOD__);
         return $e->getMessage();
     }
     $this->wf->ProfileOut(__METHOD__);
     return array($videoTitle, $videoPageId, $videoProvider);
 }
 /**
  * adaptor for getRecentlyUploaded to format as mediaTable
  */
 public static function getRecentlyUploadedAsMediaTable($limit)
 {
     $output = array();
     $list = static::getRecentlyUploaded($limit);
     if (empty($list)) {
         return $output;
     }
     foreach ($list as $title) {
         $output[] = array('title' => $title, 'type' => WikiaFileHelper::isTitleVideo($title) ? self::MEDIA_TYPE_VIDEO : self::MEDIA_TYPE_IMAGE);
     }
     return $output;
 }
Пример #4
0
 /**
  * @TODO support for video from repo
  * @param string $name
  * @return boolean
  */
 private static function isValidVideo($name)
 {
     $bResult = WikiaFileHelper::isTitleVideo($name);
     return $bResult;
 }
 public function onSkinTemplateNavigation($skin, &$tabs)
 {
     global $wgTitle, $wgCityId;
     // Ignore Video Wiki videos
     if ($wgCityId == self::VIDEO_WIKI) {
         return true;
     }
     if (WikiaFileHelper::isTitleVideo($wgTitle)) {
         $file = wfFindFile($wgTitle);
         if (!$file->isLocal()) {
             $tabs['actions']['remove'] = array('class' => 'remove', 'text' => wfMsg('videohandler-remove'), 'href' => '#');
         }
     }
     return true;
 }
 public function getHTML()
 {
     global $wgRequest, $wgCategoryExhibitionMediaSectionRows;
     $cachedContent = $this->getFromCache();
     if (empty($cachedContent)) {
         // grabs data fo videos and images
         $aTmpData = $this->fetchSectionItems(array(NS_FILE));
         // we wan't old videos
         if (is_array($aTmpData) && count($aTmpData) > 0) {
             $pages = Paginator::newFromArray($aTmpData, $wgCategoryExhibitionMediaSectionRows * 4);
             $pageData = $pages->getPage($this->paginatorPosition, true);
             $aData = array();
             foreach ($pageData as $item) {
                 $itemTitle = Title::newFromID($item['page_id']);
                 $forceHeight = '';
                 $forceWidth = '';
                 // item is image
                 $image = wfFindFile($itemTitle);
                 $elementClass = 'lightbox';
                 if (!is_object($image) || $image->height == 0 || $image->width == 0) {
                     $imageSrc = '';
                 } else {
                     if (WikiaFileHelper::isFileTypeVideo($image)) {
                         $elementClass .= ' video';
                     }
                     $proportions = $image->width / $image->height;
                     if ($proportions < 1) {
                         $calculatedWidth = floor($proportions * $this->thumbWidth);
                     } else {
                         $calculatedWidth = $this->thumbMedia;
                     }
                     $forceWidth = floor($calculatedWidth);
                     $forceHeight = floor($calculatedWidth / $proportions);
                     $imageServing = new ImageServing(array($item['page_id']), $calculatedWidth, array("w" => $image->width, "h" => $image->height));
                     $imageSrc = wfReplaceImageServer($image->getThumbUrl($imageServing->getCut($image->width, $image->height) . "-" . $image->getName()));
                 }
                 $linkedFiles = $this->getLinkedFiles($itemTitle);
                 if (!empty($linkedFiles)) {
                     $linkText = $linkedFiles->getText();
                     $linkFullUrl = $linkedFiles->getFullURL();
                 } else {
                     $linkText = '';
                     $linkFullUrl = '';
                 }
                 // types casting for proper caching;
                 $aData[] = array('id' => $item['page_id'], 'title' => $itemTitle->getText(), 'img' => (string) $imageSrc, 'url' => $itemTitle->getFullURL(), 'dimensions' => array('w' => (int) $forceWidth, 'h' => (int) $forceHeight), 'class' => $elementClass, 'data-ref' => $itemTitle->getPrefixedURL(), 'targetUrl' => $linkFullUrl, 'targetText' => $linkText, 'useVideoOverlay' => WikiaFileHelper::isVideoStoredAsFile() && WikiaFileHelper::isTitleVideo($itemTitle));
             }
             $aContent = array('data' => $aData, 'category' => $this->categoryTitle->getText(), 'paginator' => $pages->getBarHTML($this->sUrl));
             $this->saveToCache($aContent);
         } else {
             return false;
         }
     } else {
         $aContent = $cachedContent;
     }
     if (!empty($aContent) && is_array($aContent)) {
         $oTmpl = new EasyTemplate(dirname(__FILE__) . "/templates/");
         $oTmpl->set_vars($aContent);
         $oTmpl->set_vars(array('fromAjax' => $this->isFromAjax));
         if ($this->isFromAjax) {
             return array('page' => $oTmpl->render($this->templateName), 'paginator' => $oTmpl->mVars['paginator']);
         } else {
             return $oTmpl->render($this->templateName);
         }
     }
 }