Esempio n. 1
0
 /**
  * @param Title $title
  * @param Page $article
  *
  * @return true because it's a hook
  */
 public function onArticleFromTitle(&$title, &$article)
 {
     wfProfileIn(__METHOD__);
     $app = F::app();
     $dbKeyName = $title->getDBKey();
     if (!empty($app->wg->EnableWikiaHomePageExt) && $this->isHubsPage($dbKeyName)) {
         $app->wg->SuppressPageHeader = true;
         $article = F::build('WikiaHubsV2Article', array($title, $this->getHubPageId($dbKeyName)));
     }
     wfProfileOut(__METHOD__);
     return true;
 }
Esempio n. 2
0
 /**
  * @param Title $title
  * @param Page $article
  *
  * @return true because it's a hook
  */
 public static function onArticleFromTitle(&$title, &$article)
 {
     wfProfileIn(__METHOD__);
     $app = F::app();
     if (WikiaPageType::isWikiaHubMain() || $title->isSubpageOf(Title::newMainPage())) {
         $model = new WikiaHubsV3HooksModel();
         $dbKeyName = $title->getDBKey();
         $dbKeyNameSplit = explode('/', $dbKeyName);
         $hubTimestamp = $model->getTimestampFromSplitDbKey($dbKeyNameSplit);
         $app->wg->SuppressRail = true;
         $app->wg->SuppressFooter = true;
         if (!$app->wg->request->wasPosted()) {
             // don't change article object while saving data
             $article = new WikiaHubsV3Article($title, $hubTimestamp);
         }
     }
     wfProfileOut(__METHOD__);
     return true;
 }
Esempio n. 3
0
 /**
  * @param $title Title
  * @param $repo ForeignApiRepo
  * @return ForeignAPIFile|null
  */
 static function newFromTitle(Title $title, $repo)
 {
     $data = $repo->fetchImageQuery(array('titles' => 'File:' . $title->getDBKey(), 'iiprop' => self::getProps(), 'prop' => 'imageinfo', 'iimetadataversion' => MediaHandler::getMetadataVersion()));
     $info = $repo->getImageInfo($data);
     if ($info) {
         $lastRedirect = isset($data['query']['redirects']) ? count($data['query']['redirects']) - 1 : -1;
         if ($lastRedirect >= 0) {
             $newtitle = Title::newFromText($data['query']['redirects'][$lastRedirect]['to']);
             $img = new self($newtitle, $repo, $info, true);
             if ($img) {
                 $img->redirectedFrom($title->getDBkey());
             }
         } else {
             $img = new self($title, $repo, $info, true);
         }
         return $img;
     } else {
         return null;
     }
 }
Esempio n. 4
0
 /**
  * Update the revision's rev_deleted field
  * @param Revision $rev
  * @param Title $title
  * @param int $bitfield new rev_deleted bitfield value
  */
 function updateArchive($rev, $title, $bitfield)
 {
     $this->dbw->update('archive', array('ar_deleted' => $bitfield), array('ar_namespace' => $title->getNamespace(), 'ar_title' => $title->getDBKey(), 'ar_timestamp' => $this->dbw->timestamp($rev->getTimestamp()), 'ar_rev_id' => $rev->getId()), __METHOD__);
 }
 /**
  * Hook: remove premium video and clear cache
  * @param Title $title
  * @return true
  */
 public static function onRemovePremiumVideo($title)
 {
     if ($title instanceof Title) {
         $videoInfo = VideoInfo::newFromTitle($title->getDBKey());
         if (!empty($videoInfo) && $videoInfo->isPremium()) {
             $videoInfo->deleteVideo();
             // clear cache
             $mediaService = new MediaQueryService();
             $mediaService->clearCacheTotalVideos();
             $mediaService->clearCacheTotalPremiumVideos();
         }
     }
     return true;
 }
 public function getNumberOfUsage(Title $title)
 {
     $num = 0;
     $db =& wfGetDB(DB_SLAVE);
     if ($title->getNamespace() == NS_TEMPLATE) {
         $templatelinks = $db->tableName('templatelinks');
         $res = $db->query('SELECT COUNT(tl_from) AS numOfSubjects FROM ' . $templatelinks . ' s WHERE tl_title = ' . $db->addQuotes($title->getDBKey()) . ' GROUP BY tl_title ');
     } else {
         if ($title->getNamespace() == SMW_NS_PROPERTY) {
             $smw_atts2 = $db->tableName('smw_atts2');
             $smw_rels2 = $db->tableName('smw_rels2');
             $smw_ids = $db->tableName('smw_ids');
             $res = $db->query('SELECT COUNT(s_id) AS numOfSubjects FROM ' . $smw_atts2 . ' s JOIN ' . $smw_ids . ' ON p_id = smw_id WHERE smw_title = ' . $db->addQuotes($title->getDBKey()) . ' GROUP BY smw_title ' . ' UNION SELECT COUNT(s_id) AS numOfSubjects FROM ' . $smw_rels2 . ' s JOIN ' . $smw_ids . ' ON p_id = smw_id WHERE smw_title = ' . $db->addQuotes($title->getDBKey()) . ' GROUP BY smw_title');
         }
     }
     if ($db->numRows($res) > 0) {
         $row = $db->fetchObject($res);
         $num = $row->numOfSubjects;
     }
     $db->freeResult($res);
     return $num;
 }
Esempio n. 7
0
 protected function isWAMFAQPage(Title $title)
 {
     return $title->isSubpage() && $title->getDBKey() == self::WAM_FAQ_PAGE_NAME;
 }
 /**
  * Hook: add new video if old video does not exist or rename old video and clear cache when file is renamed
  * @param $form
  * @param Title $oldTitle
  * @param Title $newTitle
  * @return true
  */
 public static function onFileRenameComplete(&$form, &$oldTitle, &$newTitle)
 {
     if (!F::build('VideoInfoHelper', array(), 'videoInfoExists')) {
         return true;
     }
     $videoInfo = F::build('VideoInfo', array($oldTitle->getDBKey()), 'newFromTitle');
     if (empty($videoInfo)) {
         // add new video
         $videoInfoHelper = F::build('VideoInfoHelper');
         $videoData = $videoInfoHelper->getVideoDataByTitle($newTitle);
         if (!empty($videoData)) {
             $videoInfo = F::build('VideoInfo', array($videoData));
             $videoInfo->addVideo();
             $mediaService = F::build('MediaQueryService');
             $mediaService->clearCacheTotalVideos();
         }
     } else {
         $videoInfo->renameVideo($newTitle->getDBKey());
     }
     return true;
 }
 private function getMediaDataFromCache(Title $media, $length = 256)
 {
     wfProfileIn(__METHOD__);
     if (!isset($this->mediaCache[$media->getDBKey()])) {
         $file = wfFindFile($media);
         if (!empty($file) && $file->canRender()) {
             $articleService = new ArticleService($media);
             $isVideo = WikiaFileHelper::isFileTypeVideo($file);
             if ($isVideo) {
                 /** @var $videoHandler VideoHandler */
                 $videoHandler = $file->getHandler();
                 $thumb = $file->transform(array('width' => 320), 0);
             } else {
                 $videoHandler = false;
             }
             $this->mediaCache[$media->getDBKey()] = array('title' => $media->getText(), 'desc' => $articleService->getTextSnippet($length), 'type' => $isVideo ? self::MEDIA_TYPE_VIDEO : self::MEDIA_TYPE_IMAGE, 'meta' => $videoHandler ? array_merge($videoHandler->getVideoMetadata(true), $videoHandler->getEmbedSrcData()) : array(), 'thumbUrl' => !empty($thumb) ? $thumb->getUrl() : false);
         } else {
             $this->mediaCache[$media->getDBKey()] = false;
         }
     }
     wfProfileOut(__METHOD__);
     return $this->mediaCache[$media->getDBKey()];
 }
Esempio n. 10
0
 public function setTitle(Title $title)
 {
     $this->title = $title;
     $pageId = $title->getArticleId();
     if ($pageId) {
         $this->pageId = $pageId;
     } else {
         $this->extra['page_title'] = $title->getDBKey();
         $this->extra['page_namespace'] = $title->getNamespace();
     }
 }
Esempio n. 11
0
 /**
  * restore premium video
  * @param Title $title
  * @param integer $userId
  * @return boolean $affected
  */
 public function restorePremiumVideo($title, $userId)
 {
     wfProfileIn(__METHOD__);
     $affected = false;
     if ($title instanceof Title) {
         $videoInfo = VideoInfo::newFromTitle($title->getDBKey());
         if (empty($videoInfo)) {
             $newVideoInfo = $this->getVideoInfoFromTitle($title, true);
             if (!empty($newVideoInfo)) {
                 // add premium video if not exist
                 $affected = $newVideoInfo->addPremiumVideo($userId);
             }
         } else {
             $affected = $videoInfo->restoreVideo();
         }
     }
     wfProfileOut(__METHOD__);
     return $affected;
 }