Ejemplo n.º 1
0
 /**
  * Get the vertical name for a wiki by its' ID
  *
  * @param integer $wikiId The wiki's ID
  *
  * @return string The name of the vertical (e.g. Gaming, Entertainment, etc.)
  */
 private function getVerticalByWikiId($wikiId)
 {
     //this has its' own cache layer
     $cat = WikiFactory::getCategory($wikiId);
     $ret = null;
     if (!empty($cat)) {
         $ret = $cat->cat_name;
     }
     return $ret;
 }
Ejemplo n.º 2
0
 public static function loadData($forceRefresh = false, $forceLanguage = null)
 {
     global $wgMemc, $wgStatsDB, $wgContLang, $wgExternalSharedDB, $wgStatsDBEnabled;
     wfProfileIn(__METHOD__);
     self::$mLanguage = !empty($forceLanguage) ? $forceLanguage : $wgContLang->getCode();
     $cacheKey = self::CACHE_KEY_TOKEN . ':' . strtoupper(self::$mLanguage);
     self::$mData = $wgMemc->get($cacheKey);
     if (empty(self::$mData) || $forceRefresh) {
         self::$mData = array();
         $wikisIDs = array();
         // get all the active wikis selected by the sales team
         $wikiFactoryRecommended = WikiFactory::getVarByName(self::WF_VAR_NAME, null);
         self::$mData['recommended'] = array();
         if (!empty($wikiFactoryRecommended) && !empty($wikiFactoryRecommended->cv_variable_id)) {
             $dbr = WikiFactory::db(DB_SLAVE);
             $res = $dbr->select(array('city_list', 'city_variables'), 'city_id', array('city_id = cv_city_id', 'city_public' => 1, 'city_lang' => self::$mLanguage, 'cv_variable_id' => $wikiFactoryRecommended->cv_variable_id, 'cv_value' => serialize(true)));
             while ($row = $dbr->fetchObject($res)) {
                 self::$mData['recommended'][] = $row->city_id;
             }
             $dbr->freeResult($res);
         }
         $counter = 0;
         self::$mData['hubs'] = array();
         if (!empty($wgStatsDBEnabled)) {
             $wikis = DataMartService::getTopWikisByPageviews(DataMartService::PERIOD_ID_MONTHLY, 200, self::$mLanguage, null, 1);
             $minPageViews = isset(self::$pageviewsLimits[self::$mLanguage]) ? self::$pageviewsLimits[self::$mLanguage] : self::$pageviewsLimits['default'];
             foreach ($wikis as $wikiID => $pvCount) {
                 if ($pvCount >= $minPageViews) {
                     $hub = WikiFactory::getCategory($wikiID);
                     if (!$hub) {
                         continue;
                     }
                     if (!isset(self::$mData['hubs'][$hub->cat_id])) {
                         self::$mData['hubs'][$hub->cat_id] = array();
                     }
                     self::$mData['hubs'][$hub->cat_id][] = $wikiID;
                     $counter++;
                 }
             }
         }
         // removing entries from hubs that have a match in recommended
         if (!empty(self::$mData['recommended']) && !empty(self::$mData['hubs'])) {
             $counter = 0;
             foreach (self::$mData['hubs'] as $hubID => &$item) {
                 $item = array_diff($item, self::$mData['recommended']);
                 $counter += count($item);
             }
         }
         self::$mData['total'] = $counter;
         $wgMemc->set($cacheKey, self::$mData, 3600 * self::CACHE_EXPIRY);
     }
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 3
0
 protected function appendWikidesc($property)
 {
     global $wgLanguageCode, $wgDBcluster;
     $result = $this->getResult();
     $lang_id = WikiFactory::LangCodeToId($wgLanguageCode);
     $cats = WikiFactory::getCategory($this->cityId);
     $oWiki = WikiFactory::getWikiByID($this->cityId);
     $cat_id = !empty($cats) ? $cats->cat_id : 0;
     $data = array("langid" => $lang_id, "id" => $this->cityId, "catid" => $cat_id, "pagetitle" => wfMsg('pagetitle'), "flags" => $oWiki->city_flags, "db" => $oWiki->city_dbname, "position" => isset($wgDBcluster) ? $wgDBcluster : $oWiki->city_cluster);
     $result->setIndexedTagName($data, $property);
     $result->addValue('query', $property, $data);
 }
Ejemplo n.º 4
0
function generateList($format)
{
    global $wgMemc, $wgExternalSharedDB;
    $func = "begin_" . $format;
    $res = $func();
    $dbr = WikiFactory::db(DB_SLAVE, array(), $wgExternalSharedDB);
    $sth = $dbr->select(array("city_list"), array("city_title", "city_lang", "city_url", "city_id"), array("city_public = 1"), __METHOD__);
    while ($row = $dbr->fetchObject($sth)) {
        $row->category = WikiFactory::getCategory($row->city_id);
        $func = "body_" . $format;
        $res .= $func($row);
    }
    $func = "end_" . $format;
    $res .= $func();
    if (!empty($res)) {
        $gz_res = gzdeflate($res, 3);
        $wgMemc->set(wfSharedMemcKey("{$format}-city-list"), $gz_res, 3600 * 6);
    }
}
	public function init() {
		global $wgCityId;

		$this->app->wf->ProfileIn(__METHOD__);

		$category = WikiFactory::getCategory($wgCityId);

		$messageName = 'shared-Globalnavigation';
		if ($category) {
			$messageNameWithCategory = $messageName . '-' . $category->cat_id;
			if (!wfEmptyMsg($messageNameWithCategory, wfMsg($messageNameWithCategory))) {
				$messageName = $messageNameWithCategory;
			}
		}

		$navigation = new NavigationService(true /* useSharedMemcKey */);
		$menuNodes = $navigation->parseMessage($messageName, array(3, 4, 5), 10800 /* 3 hours */);

		wfRunHooks('AfterGlobalHeader', array(&$menuNodes, $category, $messageName));

		$this->menuNodes = $menuNodes;

		$this->app->wf->ProfileOut(__METHOD__);
	}
Ejemplo n.º 6
0
 public function execute($wikiID)
 {
     global $wgOut, $wgRequest, $wgCityId, $wgUser;
     wfProfileIn(__METHOD__);
     $this->setHeaders();
     $firstVisit = true;
     $wikiID = !empty($wikiID) ? (int) $wikiID : $wgCityId;
     if (isset($_COOKIE[$this->mCookieName])) {
         $this->mCookie = json_decode($_COOKIE[$this->mCookieName]);
         $firstVisit = false;
     } else {
         $this->mCookie = new stdClass();
         $this->mCookie->origHub = null;
         $this->mCookie->langCode = null;
         $this->mCookie->history = array();
         if (!empty($wikiID)) {
             $hub = WikiFactory::getCategory($wikiID);
             if (is_object($hub)) {
                 $this->mCookie->origHub = $hub->cat_id;
                 $this->mCookie->langCode = WikiFactory::getWikiByID($wikiID)->city_lang;
                 $this->mCookie->history[] = $wikiID;
             }
         }
     }
     $this->loadData();
     $historyCount = count($this->mCookie->history);
     // reset the history if the user visited all the possible targets
     if ($historyCount >= $this->mData['total']) {
         $this->mCookie->history = array($wikiID);
     }
     // if language other than English and list of targets exhausted fall back to english
     if (($historyCount >= $this->mData['total'] || $this->mData['total'] == 0 && (count($this->mData['recommended']) == 0 || !$firstVisit)) && $this->mCookie->langCode != 'en') {
         $this->mCookie->langCode = 'en';
         $this->loadData();
     }
     $destinationID = null;
     $from = null;
     srand(time());
     // pick a recommended wiki the first time
     if ($firstVisit && !empty($this->mData['recommended'])) {
         $destinationID = $this->mData['recommended'][array_rand($this->mData['recommended'])];
         $from = 'recommended';
     } elseif (!empty($this->mCookie->origHub) && !empty($this->mData['hubs'][$this->mCookie->origHub])) {
         $currentHub = array_diff($this->mData['hubs'][$this->mCookie->origHub], $this->mCookie->history);
         if (count($currentHub) && count($this->mCookie->history) < RandomWikiHelper::TRACK_LIMIT) {
             $destinationID = $currentHub[array_rand($currentHub)];
             $from = 'origHub';
         }
     }
     // in case no wiki has been selected in the previous block pick a wiki from a random hub
     if (empty($destinationID)) {
         $hubsCount = count($this->mData['hubs']);
         $hub = array_rand($this->mData['hubs'], $hubsCount);
         if (!is_array($hub)) {
             $hub = array($hub);
         }
         foreach ($hub as $key) {
             $tmpHub = array_diff($this->mData['hubs'][$key], $this->mCookie->history);
             if (!count($tmpHub)) {
                 continue;
             }
             $itemKey = array_rand($tmpHub);
             $destinationID = $tmpHub[$itemKey];
             $from = "hub {$itemKey}";
         }
     }
     $this->mCookie->history[] = $destinationID;
     $cookieValue = json_encode($this->mCookie);
     $wgRequest->response()->setcookie(self::COOKIE_NAME_TOKEN, $cookieValue, time() + 3600 * self::COOKIE_EXPIRY);
     $url = WikiFactory::getVarValueByName('wgServer', $destinationID);
     //FB#1033: avoid being sent to Special:WikiActivity when logged-in, see MyHomw::getInitialMainPage
     if ($wgUser->isLoggedIn()) {
         $url .= '?redirect=no';
     }
     // Redirect the user to a randomly-chosen wiki (or not if profiling requested)
     $profiling = $wgRequest->getInt('forceprofile', 0);
     if ($profiling !== 1) {
         $wgOut->redirect($url);
     }
     wfProfileOut(__METHOD__);
 }
Ejemplo n.º 7
0
?>
</td>
				<td><?php 
echo $wiki->city_dbname;
?>
</td>
				<td><?php 
echo empty($cluster) ? "c1<acronym title='default'>*</acronym>" : $cluster;
?>
</td>
				<td><?php 
echo $wiki->city_lang;
?>
</td>
				<td><?php 
$wgHub = WikiFactory::getCategory($wiki->city_id);
if ($wgHub) {
    echo "<acronym title=\"id:{$wgHub->cat_id}\">{$wgHub->cat_name}</acronym>";
}
?>
</td>
				<td data-status="<?php 
echo $wiki->city_public;
?>
"><?php 
echo "<acronym title=\"{$wiki->city_public}\">{$statuses[$wiki->city_public]}</acronym>";
?>
</td>
			</tr>
		</table>
		</td>
Ejemplo n.º 8
0
 /**
  * Get category id for given cityId
  *
  * @param int $city_id city id
  *
  * @return stdClass ($row->cat_id $row->cat_name)
  */
 private static function getCategoryIdForCity($cityId)
 {
     $categoryId = null;
     if (self::isCorporatePage($cityId)) {
         $categoryId = WikiFactoryHub::CATEGORY_ID_CORPORATE;
     } else {
         $category = WikiFactory::getCategory($cityId);
         if ($category) {
             $categoryId = $category->cat_id;
         }
     }
     // Look for Comscore tag
     $wftags = new WikiFactoryTags($cityId);
     $tags = $wftags->getTags();
     if (is_array($tags)) {
         foreach ($tags as $name) {
             if (startsWith($name, self::$comscore_prefix, false)) {
                 $catName = substr($name, strlen(self::$comscore_prefix));
                 $category = WikiFactoryHub::getInstance()->getCategoryByName($catName);
                 if ($category) {
                     return $category['id'];
                 }
             }
         }
     }
     return $categoryId;
 }
Ejemplo n.º 9
0
function compareEventRecordWithRevision($dbname, $oRow, $debug)
{
    global $wgTitle, $wgLanguageCode;
    $langcode = WikiFactory::getVarValueByName('wgLanguageCode', $oRow->wiki_id);
    $lang_id = WikiFactory::LangCodeToId($langcode);
    $cats = WikiFactory::getCategory($oRow->wiki_id);
    $cat_id = !empty($cats) ? $cats->cat_id : 0;
    $result = false;
    if (is_object($oRow) && !empty($oRow->page_id) && !empty($oRow->rev_id)) {
        $data = loadFromDB($dbname, $oRow->page_id, $oRow->rev_id);
        if (is_object($data)) {
            $oRevision = new Revision($data);
            if ($oRow->rev_id > 0) {
                $wgTitle = Title::makeTitle($data->page_namespace, $data->page_title);
            } else {
                $wgTitle = $oRevision->getTitle();
            }
            $content = $oRevision->getText(Revision::FOR_THIS_USER);
            $is_bot = _user_is_bot($data->rev_user_text);
            $is_content = _revision_is_content();
            $is_redirect = _revision_is_redirect($content);
            $size = intval($oRevision->getSize());
            $words = str_word_count($content);
            $links = _make_links($oRow->page_id, $oRow->rev_id, $content);
            $timestamp = $data->ts;
            if ($data->rev_page == $oRow->page_id && $data->page_namespace == $oRow->page_ns && $data->rev_id == $oRow->rev_id && $timestamp == $oRow->rev_timestamp && $data->rev_user == $oRow->user_id && $is_bot == $oRow->user_is_bot && $is_content == $oRow->is_content && $is_redirect == $oRow->is_redirect && $size == $oRow->rev_size && $words == $oRow->total_words && $cat_id == $oRow->wiki_cat_id && $lang_id == $oRow->wiki_lang_id && $links['image'] == $oRow->image_links && $links['video'] == $oRow->video_links) {
                $result = true;
            } else {
                if ($debug) {
                    echo <<<TEXT
\tpage: {$data->rev_page} == {$oRow->page_id}
\tnamespage: {$data->page_namespace}\t== {$oRow->page_ns}
\trevision: {$data->rev_id}\t== {$oRow->rev_id}
\ttimestamp: {$timestamp} == {$oRow->rev_timestamp}
\tuser: {$data->rev_user} == {$oRow->user_id}
\tis_bot: {$is_bot} == {$oRow->user_is_bot}
\tis_content: {$is_content} == {$oRow->is_content}
\tis_redirect: {$is_redirect} == {$oRow->is_redirect}
\tsize: {$size} == {$oRow->rev_size}
\twords: {$words} == {$oRow->total_words}
\tcategory: {$cat_id} == {$oRow->wiki_cat_id}
\tlanguage: {$lang_id} == {$oRow->wiki_lang_id}
\timage links:{$links['image']} == {$oRow->image_links}
\tvideo links: {$links['video']} == {$oRow->video_links}

TEXT;
                }
            }
        } else {
            echo "Not local data found for: page: {$oRow->page_id} && revision: {$oRow->rev_id}  \n";
        }
    } else {
        echo "Not events data found for: page: {$oRow->page_id} && revision: {$oRow->rev_id}  \n";
    }
    return $result;
}
Ejemplo n.º 10
0
 protected function saveWiki($wiki)
 {
     $data = $wiki;
     $data['city_id'] = $data['id'];
     $data['city_public'] = $data['public'];
     $data['created'] = $this->ts($data['created']);
     $data['lastedited'] = $this->ts($data['lastedited']);
     $catData = WikiFactory::getCategory($data['id']);
     $data['city_cat_name'] = $catData ? $catData->cat_name : '';
     unset($data['public']);
     unset($data['id']);
     unset($data['url']);
     $this->getCache()->update($data);
 }
Ejemplo n.º 11
0
 public function setCategory()
 {
     //This field is called categoryId but getCategory returns an object with cat_id and cat_name fields
     $this->mParams['categoryId'] = WikiFactory::getCategory($this->app->wg->CityId);
     // The code should probably be changed to this after double checking the scribe consumers
     //$category = WikiFactory::getCategory( $this->app->wg->CityId );
     //$this->mParams['categoryId'] = isset($category->cat_id) ? $category->cat_id : 0;
     //
     // And when categories are updated:
     //$this->mParams['categories'] = WikiFactory::getCategories( $this->app->wg->CityId );
 }
Ejemplo n.º 12
0
 /**
  * __loadWikia
  *
  * @access private
  *
  * @param Array range of columns in main table (A..Z)
  */
 private function __loadWikia()
 {
     global $wgLang, $wgContLang;
     $this->oWikia = WikiFactory::getWikiByID($this->mCityId);
     if (isset($this->oWikia) && !empty($this->oWikia)) {
         # created
         $this->oWikia->city_created_txt = "";
         if (isset($this->oWikia->city_created)) {
             $city_created = preg_replace("/(\\s|\\:|\\-)/", "", $this->oWikia->city_created);
             $this->oWikia->city_created_txt = $wgLang->timeanddate($city_created, true);
         }
         # category
         $this->oWikia->category = WikiFactory::getCategory($this->mCityId);
         # language name
         $this->oWikia->languageName = isset($this->oWikia->city_lang) ? $wgContLang->getLanguageName($this->oWikia->city_lang) : " - ";
         # Wikia title
         $this->oWikia->city_title = $this->mCityId > 0 ? ucfirst($this->oWikia->city_title) : wfMsg("wikistats_trend_all_wikia_text");
         # Wikia url
         $this->oWikia->city_url = $this->mCityId > 0 ? Xml::openElement('a', array('target' => 'new', 'href' => $this->oWikia->city_url)) . $this->oWikia->city_url . Xml::closeElement('a') : "";
         # Wikia domain
         $this->oWikia->city_domain = WikiFactory::getVarValueByName("wgServer", $this->mCityId);
     }
 }
 protected function initVertical()
 {
     global $wgCityId;
     $this->verticalId = HubService::getCanonicalCategoryId(WikiFactory::getCategory($wgCityId)->cat_id);
     $this->cityId = $wgCityId;
     $this->verticalName = $this->getContext()->getTitle()->getText();
     $this->canonicalVerticalName = str_replace(' ', '', $this->model->getCanonicalVerticalNameById($this->cityId));
     $this->wg->out->setPageTitle($this->verticalName);
     // For the main page, overwrite the <title> element with the contents of 'pagetitle-view-mainpage'.
     if ($this->getContext()->getTitle()->isMainPage()) {
         $msg = wfMessage('pagetitle-view-mainpage')->inContentLanguage();
         if (!$msg->isDisabled()) {
             $this->wg->out->setHTMLTitle($msg->title($this->getContext()->getTitle()));
         }
     }
 }
 public function setCategory()
 {
     $this->mParams['categoryId'] = WikiFactory::getCategory($this->app->wg->CityId);
 }