Ejemplo n.º 1
0
 /**
  * Returns complete details about a single media (file).  JSON only, no associated template to this method.
  * @requestParam string fileTitle
  * @requestParam boolean isInline (optional) - Determines whether the media file should show inline
  * @requestParam int width (optional) - Context width
  * @requestParam int height (optional) - Context height
  * @responseParam string mediaType - media type.  either image or video
  * @responseParam string videoEmbedCode - embed html code if video
  * @responseParam string imageUrl - thumb image url that is hard scaled
  * @responseParam string fileUrl - url to file page
  * @responseParam string caption - video caption
  * @responseParam string userThumbUrl - user avatar thumbUrl scaled to 30x30
  * @responseParam string userName - user name
  * @responseParam string userPageUrl - url to user profile page
  * @responseParam array articles - array of articles that has title and url
  * @responseParam string providerName - provider name for videos or '' for others
  * @responseParam boolean exists - check if the file exists
  * @responseParam boolean isAdded - check if the file is added to the wiki
  */
 public function getMediaDetail()
 {
     $fileTitle = urldecode($this->request->getVal('fileTitle', ''));
     $isInline = $this->request->getVal('isInline', false);
     // BugId:32939
     // There is no sane way to check whether $fileTitle is OK other
     // than an attempt to create a Title object and then a check
     // whether the object has been created.
     $title = Title::newFromText($fileTitle, NS_FILE);
     // BugId:32939
     // Can't create a valid Title object based on $fileTitle. This method
     // only changes $this's properties. Leave them unchanged.
     if (!$title instanceof Title) {
         return;
     }
     if (!$this->wg->User->isAllowed('read')) {
         return;
     }
     $config = ['imageMaxWidth' => 1000, 'contextWidth' => $this->request->getVal('width', self::CONTEXT_DEFAULT_WIDTH), 'contextHeight' => $this->request->getVal('height', self::CONTEXT_DEFAULT_HEIGHT), 'userAvatarWidth' => 16, 'isInline' => $isInline];
     // set max height if play in lightbox
     if ($this->request->getVal('width', 0) == 0) {
         $config['maxHeight'] = self::CONTEXT_DEFAULT_HEIGHT;
     }
     $data = WikiaFileHelper::getMediaDetail($title, $config);
     $articles = $data['articles'];
     list($smallerArticleList, $articleListIsSmaller) = WikiaFileHelper::truncateArticleList($articles, self::POSTED_IN_ARTICLES);
     // file details
     $this->views = wfMessage('lightbox-video-views', $this->wg->Lang->formatNum($data['videoViews']))->parse();
     $this->title = $title->getDBKey();
     $this->fileTitle = $title->getText();
     $this->mediaType = $data['mediaType'];
     $this->videoEmbedCode = $data['videoEmbedCode'];
     $this->playerAsset = $data['playerAsset'];
     $this->imageUrl = $data['imageUrl'];
     $this->fileUrl = $data['fileUrl'];
     $this->rawImageUrl = $data['rawImageUrl'];
     $this->userThumbUrl = $data['userThumbUrl'];
     $this->userName = User::isIP($data['userName']) ? wfMessage('oasis-anon-user')->plain() : $data['userName'];
     $this->userPageUrl = $data['userPageUrl'];
     $this->articles = $articles;
     $this->isPostedIn = !empty($smallerArticleList);
     // Bool to tell mustache to print "posted in" section
     $this->smallerArticleList = $smallerArticleList;
     $this->articleListIsSmaller = $articleListIsSmaller;
     $this->providerName = $data['providerName'];
     $this->exists = $data['exists'];
     $this->isAdded = $data['isAdded'];
     $this->extraHeight = $data['extraHeight'];
     // Make sure that a request with missing &format=json does not throw a "template not found" exception
     $this->response->setFormat('json');
     // set cache control to 15 minutes
     $this->response->setCacheValidity(900);
 }
Ejemplo n.º 2
0
 public static function onImageBeforeProduceHTML(&$dummy, Title &$title, &$file, &$frameParams, &$handlerParams, &$time, &$res)
 {
     global $wgArticleAsJson;
     wfProfileIn(__METHOD__);
     if ($wgArticleAsJson) {
         $linkHref = '';
         if (isset($frameParams['link-title']) && $frameParams['link-title'] instanceof Title) {
             $linkHref = $frameParams['link-title']->getLocalURL();
         } else {
             if (!empty($frameParams['link-url'])) {
                 $linkHref = $frameParams['link-url'];
             }
         }
         $details = WikiaFileHelper::getMediaDetail($title, self::$mediaDetailConfig);
         //information for mobile skins how they should display small icons
         $details['context'] = self::isIconImage($handlerParams) ? self::MEDIA_CONTEXT_ICON : self::MEDIA_CONTEXT_ARTICLE_IMAGE;
         self::$media[] = self::createMediaObject($details, $title->getText(), $frameParams['caption'], $linkHref);
         self::addUserObj($details);
         $res = self::createMarker($details['width'], $details['height']);
         wfProfileOut(__METHOD__);
         return false;
     }
     wfProfileOut(__METHOD__);
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Returns the output of passing a title instance fo WikiaFileHelper::getMediaDetail, which out to be an array
  * @param int $pageId
  * @return array
  */
 public function getMediaDetailFromPageId($pageId)
 {
     return \WikiaFileHelper::getMediaDetail($this->getTitleFromPageId($pageId));
 }
Ejemplo n.º 4
0
 public function testGetMediaDetail()
 {
     $fileTitle = __METHOD__ . time();
     $request = $this->getMockBuilder('WikiaRequest')->disableOriginalConstructor()->setMethods(['getVal'])->getMock();
     $request->expects($this->at(0))->method('getVal')->with('fileTitle', '')->will($this->returnValue($fileTitle));
     $request->expects($this->at(1))->method('getVal')->with('isInline', false)->will($this->returnValue(false));
     $request->expects($this->at(2))->method('getVal')->with('width', $this->anything())->will($this->returnValue(\LightboxController::CONTEXT_DEFAULT_WIDTH));
     $request->expects($this->at(3))->method('getVal')->with('height', $this->anything())->will($this->returnValue(\LightboxController::CONTEXT_DEFAULT_HEIGHT));
     $request->expects($this->at(4))->method('getVal')->with('width', $this->anything())->will($this->returnValue(\LightboxController::CONTEXT_DEFAULT_WIDTH));
     $userMock = $this->getMock('stdClass', ['isAnon', 'isAllowed', 'isItemLoaded', 'getOption', 'getStubThreshold']);
     $userMock->expects($this->any())->method('isAnon')->will($this->returnValue(false));
     $userMock->expects($this->once())->method('isAllowed')->with('read')->will($this->returnValue(true));
     $userMock->expects($this->any())->method('isItemLoaded')->with($this->anything())->will($this->returnValue(false));
     $userMock->expects($this->any())->method('getStubThreshold')->will($this->returnValue(0));
     $this->mockGlobalVariable('wgUser', $userMock);
     $width = LightboxController::CONTEXT_DEFAULT_WIDTH;
     $height = LightboxController::CONTEXT_DEFAULT_HEIGHT;
     $isInline = false;
     $config = ['imageMaxWidth' => 1000, 'contextWidth' => $width, 'contextHeight' => $height, 'userAvatarWidth' => 16, 'isInline' => $isInline];
     $title = \Title::newFromText($fileTitle, NS_FILE);
     $data = \WikiaFileHelper::getMediaDetail($title, $config);
     $articles = $data['articles'];
     list($smallerArticleList, $articleListIsSmaller) = \WikiaFileHelper::truncateArticleList($articles, LightboxController::POSTED_IN_ARTICLES);
     $mediaType = $data['mediaType'];
     $videoEmbedCode = $data['videoEmbedCode'];
     $playerAsset = $data['playerAsset'];
     $imageUrl = $data['imageUrl'];
     $fileUrl = $data['fileUrl'];
     $rawImageUrl = $data['rawImageUrl'];
     $userThumbUrl = $data['userThumbUrl'];
     $userName = $data['userName'];
     $userPageUrl = $data['userPageUrl'];
     $isPostedIn = !empty($smallerArticleList);
     // Bool to tell mustache to print "posted in" section
     $providerName = $data['providerName'];
     $exists = $data['exists'];
     $isAdded = $data['isAdded'];
     $extraHeight = $data['extraHeight'];
     $format = \WikiaResponse::FORMAT_JSON;
     global $wgLang;
     $views = wfMessage('lightbox-video-views', $wgLang->formatNum($data['videoViews']))->parse();
     $mediaDetail = ['mediaType' => $mediaType, 'videoEmbedCode' => $videoEmbedCode, 'playerAsset' => $playerAsset, 'imageUrl' => $imageUrl, 'fileUrl' => $fileUrl, 'rawImageUrl' => $rawImageUrl, 'userThumbUrl' => $userThumbUrl, 'userName' => $userName, 'userPageUrl' => $userPageUrl, 'articles' => $articles, 'providerName' => $providerName, 'views' => $views, 'exists' => $exists, 'isAdded' => $isAdded, 'extraHeight' => $extraHeight, 'title' => $title->getDBkey(), 'fileTitle' => $title->getText(), 'isPostedIn' => $isPostedIn, 'smallerArticleList' => $smallerArticleList, 'articleListIsSmaller' => $articleListIsSmaller];
     $lightboxController = new \LightboxController();
     $lightboxController->setRequest($request);
     $response = new \WikiaResponse($format);
     $lightboxController->setResponse($response);
     $lightboxController->getMediaDetail();
     // Inspect response object
     foreach ($mediaDetail as $key => $value) {
         $this->assertEquals($value, $lightboxController->getResponse()->getVal($key), "mismatch on {$key}");
     }
     $this->assertEquals($format, $lightboxController->getResponse()->getFormat());
 }
 /**
  * @brief - Returns complete details about a single media (file).  JSON only, no associated template to this method.
  * @requestParam string fileTitle
  * @requestParam string sourceArticleId (optional) - article id that the file belongs to
  * @responseParam string mediaType - media type.  either image or video
  * @responseParam string videoEmbedCode - embed html code if video
  * @responseParam string imageUrl - thumb image url that is hard scaled
  * @responseParam string fileUrl - url to file page
  * @responseParam string caption - video caption
  * @responseParam string userThumbUrl - user avatar thumbUrl scaled to 30x30
  * @responseParam string userName - user name
  * @responseParam string userPageUrl - url to user profile page
  * @responseParam array articles - array of articles that has title and url
  * @responseParam string providerName - provider name for videos or '' for others
  */
 public function getMediaDetail()
 {
     $fileTitle = $this->request->getVal('fileTitle', '');
     $fileTitle = urldecode($fileTitle);
     // BugId:32939
     // There is no sane way to check whether $fileTitle is OK other
     // than an attempt to create a Title object and then a check
     // whether the object has been created.
     $title = F::build('Title', array($fileTitle, NS_FILE), 'newFromText');
     // BugId:32939
     // Can't create a valid Title object based on $fileTitle. This method
     // only changes $this's properties. Leave them unchanged.
     if (!$title instanceof Title) {
         return;
     }
     $config = array('imageMaxWidth' => 1000, 'contextWidth' => $this->request->getVal('width', 750), 'contextHeight' => $this->request->getVal('height', 415), 'userAvatarWidth' => 16);
     // set max height if play in lightbox
     if ($this->request->getVal('width', 0) == 0) {
         $config['maxHeight'] = 415;
     }
     $data = WikiaFileHelper::getMediaDetail($title, $config);
     $articles = $data['articles'];
     $isPostedIn = false;
     // Bool to tell mustache to print "posted in" section
     if (!empty($articles)) {
         $isPostedIn = true;
     }
     list($smallerArticleList, $articleListIsSmaller) = F::build('WikiaFileHelper', array($articles, self::POSTED_IN_ARTICLES), 'truncateArticleList');
     // file details
     $this->views = $this->wf->Msg('lightbox-video-views', $this->wg->Lang->formatNum($data['videoViews']));
     $this->title = $title->getDBKey();
     $this->fileTitle = $title->getText();
     $this->mediaType = $data['mediaType'];
     $this->videoEmbedCode = $data['videoEmbedCode'];
     $this->playerAsset = $data['playerAsset'];
     $this->imageUrl = $data['imageUrl'];
     $this->fileUrl = $data['fileUrl'];
     $this->rawImageUrl = $data['rawImageUrl'];
     $this->userThumbUrl = $data['userThumbUrl'];
     $this->userName = User::isIP($data['userName']) ? $this->wf->Msg('oasis-anon-user') : $data['userName'];
     $this->userPageUrl = $data['userPageUrl'];
     $this->articles = $articles;
     $this->isPostedIn = $isPostedIn;
     $this->smallerArticleList = $smallerArticleList;
     $this->articleListIsSmaller = $articleListIsSmaller;
     $this->providerName = $data['providerName'];
     $this->exists = $data['exists'];
     // set cache control to 1 hour
     $this->response->setCacheValidity(3600, 3600, array(WikiaResponse::CACHE_TARGET_BROWSER, WikiaResponse::CACHE_TARGET_VARNISH));
 }
 public function save()
 {
     if (!$this->wg->User->isAllowed('gameguidessponsored')) {
         $this->displayRestrictionError();
         return false;
         // skip rendering
     }
     $this->response->setFormat('json');
     $languages = $this->request->getArray('languages');
     $err = [];
     if (!empty($languages)) {
         foreach ($languages as $lang => $videos) {
             foreach ($videos as $key => $video) {
                 $wikiId = (int) WikiFactory::DomainToID($video['wiki_domain']);
                 $video['wiki_id'] = $wikiId;
                 $wiki = WikiFactory::getWikiByID($wikiId);
                 $video['wiki_name'] = $wiki->city_title;
                 $video['wiki_lang'] = $wiki->city_lang;
                 $title = Title::newFromText($video['video_name'], NS_FILE);
                 if (!empty($title) && $title->exists()) {
                     $vid = wfFindFile($title);
                     if (!empty($vid) && $vid instanceof WikiaLocalFile) {
                         $handler = $vid->getHandler();
                         if ($handler instanceof OoyalaVideoHandler) {
                             $metadata = $handler->getVideoMetadata(true);
                             $video['video_id'] = $metadata['videoId'];
                             $video['duration'] = WikiaFileHelper::formatDuration($metadata['duration']);
                             $video['video_thumb'] = WikiaFileHelper::getMediaDetail($title)['imageUrl'];
                         } else {
                             $err[$video['video_name']] = self::VIDEO_IS_NOT_PROVIDED_BY_OOYALA;
                         }
                     } else {
                         $err[$video['video_name']] = self::VIDEO_DOES_NOT_EXIST;
                     }
                 } else {
                     $err[$video['video_name']] = self::VIDEO_DOES_NOT_EXIST;
                 }
                 $videos[$key] = $video;
             }
             $languages[$lang] = $videos;
         }
     }
     if (!empty($err)) {
         $this->response->setVal('error', $err);
     } else {
         $status = WikiFactory::setVarByName('wgWikiaGameGuidesSponsoredVideos', $this->wg->CityId, $languages);
         $this->response->setVal('status', $status);
         if ($status) {
             wfRunHooks('GameGuidesSponsoredVideosSave');
         }
     }
     return true;
 }
Ejemplo n.º 7
0
 public function processTrendingVideoData($data)
 {
     $videosData = $data['videos'];
     if (!isset($videosData) || !is_array($videosData)) {
         return null;
     }
     $items = [];
     foreach ($videosData as $item) {
         $items[] = ArticleAsJson::createMediaObject(WikiaFileHelper::getMediaDetail(Title::newFromText($item['title'], NS_FILE), ['imageMaxWidth' => false]), $item['title']);
     }
     return $items;
 }
 /**
  * Get the embed code for the given video title
  *
  * @requestParam fileTitle - The video title to get an embed code for
  * @requestParam width - The desired width (default 460)
  * @requestParam height - The desired height (default 250)
  */
 public function getEmbedCode()
 {
     $fileTitle = $this->request->getVal('fileTitle', '');
     $fileTitle = urldecode($fileTitle);
     $title = Title::newFromText($fileTitle, NS_FILE);
     if (!$title instanceof Title) {
         return;
     }
     $config = ['contextWidth' => $this->request->getVal('width', 460), 'maxHeight' => $this->request->getVal('height', 250)];
     $data = WikiaFileHelper::getMediaDetail($title, $config);
     $this->response->setData($data);
 }
 /**
  * This method does the brunt of the work for populating an array with the values
  * we need when servicing the backend search indexer processes
  * @see WikiaSearchIndexer::getPages()
  * @see WikiaSearchController::getPage()
  * @param int $pageId
  * @throws WikiaException
  * @return array result
  */
 public function getPage($pageId)
 {
     wfProfileIn(__METHOD__);
     $result = array();
     $page = F::build('Article', array($pageId), 'newFromID');
     if (!$page instanceof Article) {
         throw new WikiaException('Invalid Article ID');
     }
     if (!$this->parserHookActive) {
         $this->app->registerHook('ParserClearState', 'WikiaSearchIndexer', 'onParserClearState');
         $this->parserHookActive = true;
     }
     // hack: setting wgTitle as rendering fails otherwise
     $wgTitle = $this->wg->Title;
     $this->wg->Title = $page->getTitle();
     // hack: setting action=render to exclude "Related Pages" and other unwanted stuff
     $wgRequest = $this->wg->Request;
     $this->wg->Request->setVal('action', 'render');
     if ($page->isRedirect()) {
         $redirectPage = F::build('Article', array($page->getRedirectTarget()));
         $redirectPage->loadContent();
         // hack: setting wgTitle as rendering fails otherwise
         $this->wg->Title = $page->getRedirectTarget();
         $redirectPage->render();
         $canonical = $page->getRedirectTarget()->getPrefixedText();
     } else {
         $page->render();
         $canonical = '';
     }
     $html = $this->wg->Out->getHTML();
     $namespace = $this->wg->Title->getNamespace();
     $isVideo = false;
     $isImage = false;
     if ($namespace == NS_FILE && ($file = $this->wf->findFile($this->wg->Title->getText()))) {
         $detail = WikiaFileHelper::getMediaDetail($this->wg->Title);
         $isVideo = WikiaFileHelper::isVideoFile($file);
         $isImage = $detail['mediaType'] == 'image' && !$isVideo;
         $metadata = $file->getMetadata();
         if ($metadata !== "0") {
             $metadata = unserialize($metadata);
             $fileParams = array('description', 'keywords') + ($isVideo ? array('movieTitleAndYear', 'videoTitle') : array());
             foreach ($fileParams as $datum) {
                 $html .= isset($metadata[$datum]) ? ' ' . $metadata[$datum] : '';
             }
         }
     }
     $title = $page->getTitle()->getText();
     if (in_array($namespace, array(NS_WIKIA_FORUM_BOARD_THREAD, NS_USER_WALL_MESSAGE))) {
         $wm = WallMessage::newFromId($page->getId());
         $wm->load();
         if ($wm->isMain()) {
             $title = $wm->getMetaTitle();
         } else {
             if ($main = $wm->getTopParentObj() and !empty($main)) {
                 $main->load();
                 $title = $main->getMetaTitle();
             }
         }
     }
     // clear output buffer in case we want get more pages
     $this->wg->Out->clearHTML();
     $result['wid'] = empty($this->wg->ExternalSharedDB) ? $this->wg->SearchWikiId : (int) $this->wg->CityId;
     $result['pageid'] = $pageId;
     $result['id'] = $result['wid'] . '_' . $result['pageid'];
     $result['title'] = $title;
     $result['canonical'] = $canonical;
     $result['html'] = html_entity_decode($html, ENT_COMPAT, 'UTF-8');
     $result['url'] = $page->getTitle()->getFullUrl();
     $result['ns'] = $page->getTitle()->getNamespace();
     $result['host'] = substr($this->wg->Server, 7);
     $result['lang'] = $this->wg->Lang->mCode;
     # these need to be strictly typed as bool strings since they're passed via http when in the hands of the worker
     $result['iscontent'] = in_array($result['ns'], $this->wg->ContentNamespaces) ? 'true' : 'false';
     $result['is_main_page'] = $page->getId() == Title::newMainPage()->getArticleId() && $page->getId() != 0 ? 'true' : 'false';
     $result['is_redirect'] = $canonical == '' ? 'false' : 'true';
     $result['is_video'] = $isVideo ? 'true' : 'false';
     $result['is_image'] = $isImage ? 'true' : 'false';
     if ($this->wg->EnableBacklinksExt && $this->wg->IndexBacklinks) {
         $result['backlink_text'] = Backlinks::getForArticle($page);
     }
     $result = array_merge($result, $this->getPageMetaData($page));
     // restore global state
     $this->wg->Title = $wgTitle;
     $this->wg->Request = $wgRequest;
     wfProfileOut(__METHOD__);
     return $result;
 }