/**
  * 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);
 }
 public function setMediaLinks($oPage)
 {
     wfProfileIn(__METHOD__);
     $links = array('image' => 0, 'video' => 0);
     if (isset($oPage->mPreparedEdit) && isset($oPage->mPreparedEdit->output)) {
         $images = $oPage->mPreparedEdit->output->getImages();
         if (!empty($images)) {
             foreach ($images as $iname => $dummy) {
                 if (WikiaFileHelper::isVideoStoredAsFile()) {
                     $file = wfFindFile($iname);
                     if ($file instanceof LocalFile) {
                         $mediaType = $file->getMediaType();
                         switch ($mediaType) {
                             case MEDIATYPE_VIDEO:
                                 $links['video']++;
                                 break;
                             default:
                                 $links['image']++;
                         }
                     }
                 } else {
                     //@todo remove this code after video refactoring
                     if (substr($iname, 0, 1) == ':') {
                         $links['video']++;
                     } else {
                         $links['image']++;
                     }
                 }
             }
         }
     }
     $this->setImageLinks($links['image']);
     $this->setVideoLinks($links['video']);
     wfProfileOut(__METHOD__);
     return $links;
 }
 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);
         }
     }
 }