Пример #1
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);
 }
Пример #2
0
 private static function getURL($type = null, $name = null, $param = null, $for_html = true)
 {
     global $wgStyleVersion, $wgCityId, $wgContLanguageCode, $wgDBname, $wgDBcluster, $wgUser, $wgArticle, $wgTitle, $wgAdServerTest;
     $sep = $for_html ? '&' : '&';
     $url = Track::BASE_URL . ($type ? "/{$type}" : '') . ($name ? "/{$name}" : '') . '?' . 'cb=' . $wgStyleVersion . $sep . 'c=' . $wgCityId . $sep . 'lc=' . $wgContLanguageCode . $sep . 'lid=' . WikiFactory::LangCodeToId($wgContLanguageCode) . $sep . 'x=' . $wgDBname . $sep . 'y=' . $wgDBcluster . $sep . 'u=' . $wgUser->getID() . $sep . 'a=' . (is_object($wgArticle) ? $wgArticle->getID() : null) . $sep . 's=' . RequestContext::getMain()->getSkin()->getSkinName() . ($wgTitle && !is_object($wgArticle) ? $sep . 'pg=' . urlencode($wgTitle->getPrefixedDBkey()) : '') . ($wgTitle ? $sep . 'n=' . $wgTitle->getNamespace() : '') . (!empty($wgAdServerTest) ? $sep . 'db_test=1' : '');
     // Handle any parameters passed to us
     if ($param) {
         foreach ($param as $key => $val) {
             $url .= $sep . urlencode($key) . '=' . urlencode($val);
         }
     }
     return $url;
 }
Пример #3
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;
}
 public function setLanguage($lang_code = '')
 {
     if (empty($lang_code)) {
         $lang_code = $this->app->wg->LanguageCode;
     }
     $this->mParams['languageId'] = WikiFactory::LangCodeToId($lang_code);
 }
Пример #5
0
 public function getWikiActivity($params = array(), $xls = 0)
 {
     global $wgLang, $wgStatsDB, $wgUser, $wgMemc, $wgStatsDBEnabled;
     wfProfileIn(__METHOD__);
     if (empty($params)) {
         wfProfileOut(__METHOD__);
         return false;
     }
     if (empty($wgStatsDBEnabled)) {
         wfProfileOut(__METHOD__);
         return false;
     }
     # only for special users
     if (!WikiStats::isAllowed()) {
         Wikia::log(__METHOD__, false, "unauthorized user: "******" tried to retrieve data");
         wfProfileOut(__METHOD__);
         return false;
     }
     $data = array('cnt' => 0, 'res' => null);
     $year = isset($params['year']) ? intval($params['year']) : date('Y');
     $month = isset($params['month']) ? intval($params['month']) : date('m');
     $lang = isset($params['lang']) ? $params['lang'] : '';
     $cat = isset($params['cat']) ? $params['cat'] : '';
     $order = isset($params['order']) ? $params['order'] : '';
     $limit = isset($params['limit']) ? intval($params['limit']) : self::DEF_LIMIT;
     $offset = isset($params['offset']) ? intval($params['offset']) : 0;
     $summary = isset($params['summary']) ? intval($params['summary']) : 0;
     $lang_id = WikiFactory::LangCodeToId($lang);
     if (empty($lang_id)) {
         Wikia::log(__METHOD__, false, "invalid language code: {$lang}");
         wfProfileOut(__METHOD__);
         return false;
     }
     $dbr = wfGetDB(DB_SLAVE, 'stats', $wgStatsDB);
     # order
     $orderOptions = array('id' => 'wiki_id', 'dbname' => 'city_dbname', 'title' => 'city_title', 'url' => 'city_url', 'users' => 'users_all', 'edits' => 'articles_edits', 'articles' => 'articles', 'lastedit' => 'city_last_timestamp');
     $sql_order = 'null';
     if (!empty($order)) {
         $options = array();
         $tmp = explode('|', $order);
         if (!empty($tmp)) {
             foreach ($tmp as $inx) {
                 @(list($val, $desc) = explode(':', $inx));
                 $options[] = $orderOptions[$val] . " " . $desc;
             }
         }
         if (!empty($options)) {
             $sql_order = implode(',', $options);
         }
     }
     # tables
     if ($summary) {
         $tables = array('lang_monthly_stats');
     } else {
         $tables = array('wikia_monthly_stats', 'wikicities.city_list AS cl', 'wikicities.city_cat_mapping AS ccm');
     }
     #conditions
     $conditions = $join = array();
     if ($summary) {
         $conditions = array('stats_date' => sprintf("%04d%02d", $year, $month), 'wiki_lang_id' => $lang_id);
     } else {
         $conditions = array('stats_date' => sprintf("%04d%02d", $year, $month), 'city_public' => 1);
         if (!empty($lang)) {
             $conditions['cl.city_lang'] = $lang;
         }
         if (!empty($cat)) {
             $conditions['ccm.cat_id'] = $cat;
         }
         # join
         $join = array('wikicities.city_list AS cl' => array('JOIN', 'cl.city_id = wiki_id'), 'wikicities.city_cat_mapping AS ccm' => array('JOIN', 'ccm.city_id = wiki_id'));
     }
     $memkey = sprintf("count_%s_%s_%s_%d", __METHOD__, implode('_', array_keys($conditions)), implode('_', array_values($conditions)), $xls);
     $data['cnt'] = $wgMemc->get($memkey);
     /* number of records */
     if ($summary) {
         $data['cnt'] = 1;
     } else {
         if (empty($data['cnt'])) {
             $oRow = $dbr->selectRow($tables, array('count(0) as cnt'), $conditions, __METHOD__, '', $join);
             if (is_object($oRow)) {
                 $data['cnt'] = $oRow->cnt;
             }
             $wgMemc->set($memkey, $data['cnt'], 60 * 60 * 3);
         }
     }
     if ($data['cnt'] > 0) {
         $memkey = sprintf("acdata_%s_%s_%d", __METHOD__, $year . '_' . $month . '_' . $lang . '_' . $cat . '_' . $order . '_' . $limit . '_' . $offset . '_' . $wgLang->getCode() . '_' . $summary, $xls);
         $data['res'] = $wgMemc->get($memkey);
         if (empty($data['res'])) {
             $data['res'] = array();
             # order & limit
             $order = $xls == 1 ? array() : array('ORDER BY' => $sql_order, 'LIMIT' => $limit, 'OFFSET' => $offset);
             if ($summary) {
                 $oRes = $dbr->select($tables, array('0 as city_id', '\'\' as city_dbname', '\'\' as city_title', '\'\' as city_url', 'users_all', 'articles', 'articles_edits', 'ts'), $conditions, __METHOD__);
             } else {
                 $oRes = $dbr->select($tables, array('cl.city_id', 'city_dbname', 'city_title', 'city_url', 'users_all', 'articles', 'articles_edits', 'city_last_timestamp as ts'), $conditions, __METHOD__, $order, $join);
             }
             while ($oRow = $dbr->fetchObject($oRes)) {
                 $data['res'][$summary ? 0 : $oRow->city_id] = array($summary ? 0 : $oRow->city_id, $summary ? wfMsg('wikistats_summary_data') : $oRow->city_dbname, $summary ? wfMsg('wikistats_summary_data') : $oRow->city_title, $summary ? wfMsg('wikistats_summary_data') : $oRow->city_url, $oRow->users_all, $oRow->articles_edits, $oRow->articles, $summary ? '' : $wgLang->timeanddate($oRow->ts), 0, 0, 0);
             }
             $dbr->freeResult($oRes);
             if (!empty($data['res']) && $xls == 0) {
                 $prev_year = $year;
                 $prev_month = $month - 1;
                 if ($prev_month == 0) {
                     $prev_month = 12;
                     $prev_year--;
                 }
                 if ($summary) {
                     $conditions['stats_date'] = sprintf("%04d%02d", $prev_year, $prev_month);
                     $oRes = $dbr->select($tables, array('0 as wiki_id', 'users_all', 'articles', 'articles_edits'), $conditions, __METHOD__);
                 } else {
                     $where = array('stats_date' => sprintf("%04d%02d", $prev_year, $prev_month), 'wiki_id' => array_keys($data['res']));
                     $oRes = $dbr->select(array('wikia_monthly_stats'), array('wiki_id', 'users_all', 'articles', 'articles_edits'), $where, __METHOD__);
                 }
                 while ($oRow = $dbr->fetchObject($oRes)) {
                     $data['res'][$oRow->wiki_id][8] = $oRow->users_all > $data['res'][$oRow->wiki_id][4] ? 1 : ($oRow->users_all < $data['res'][$oRow->wiki_id][4] ? -1 : 0);
                     $data['res'][$oRow->wiki_id][9] = $oRow->articles_edits > $data['res'][$oRow->wiki_id][5] ? 1 : ($oRow->articles_edits < $data['res'][$oRow->wiki_id][5] ? -1 : 0);
                     $data['res'][$oRow->wiki_id][10] = $oRow->articles > $data['res'][$oRow->wiki_id][6] ? 1 : ($oRow->articles < $data['res'][$oRow->wiki_id][6] ? -1 : 0);
                 }
                 $dbr->freeResult($oRes);
             }
             $wgMemc->set($memkey, $data['res'], 60 * 60 * 3);
         }
     }
     wfProfileOut(__METHOD__);
     return $data;
 }
    /**
     * get top wikis
     *
     * @author Tomasz Odrobny
     * @access public
     *
     */
    public function getTopWikis($tag_id, $lang, $limit, $show_hide = false, $force_reload = false)
    {
        global $wgMemc, $wgDotDisplay;
        wfProfileIn(__METHOD__);
        $mcKey = wfSharedMemcKey("auto_hubs", "wikis_top", $tag_id, $lang, $limit);
        if (!$force_reload) {
            $out = $wgMemc->get($mcKey);
            if (!empty($out)) {
                wfProfileOut(__METHOD__);
                return $out;
            }
        }
        if (empty($this->dbEnabled)) {
            wfProfileOut(__METHOD__);
            return array("value" => array(), "age" => time());
        }
        $tag_id = (int) $tag_id;
        $limit = 40;
        $lang_id = WikiFactory::LangCodeToId($lang);
        $conditions = array("tag_id" => $tag_id, "city_lang" => $lang_id);
        $res = $this->dbs->select(array('specials.page_views_summary_tags'), array('tag_id as tag_id, city_id as city_id, pv_views as count '), $conditions, __METHOD__, array('ORDER BY' => 'count DESC', 'LIMIT' => $limit));
        if ($this->dbs->numRows($res) == 0 && !empty($wgDotDisplay)) {
            $date = date('Ymd', time() - 7 * 24 * 60 * 60);
            $conditions = array("pv_use_date > {$date}", 'ct.city_id = pv.pv_city_id');
            $res = $this->dbs->select(array('stats.page_views as pv', 'wikicities.city_tag_map as ct'), array('ct.tag_id as tag_id,
						pv_city_id as city_id,
						sum(pv_views) as count '), $conditions, __METHOD__, array('GROUP BY' => ' ct.tag_id,pv_city_id ', 'ORDER BY' => ' count DESC ', 'LIMIT' => $limit));
        }
        $limits = $this->loadHideLimits("city");
        $limits_array = array();
        if (!empty($limits[$tag_id]) && count($limits[$tag_id]) > 0) {
            foreach ($limits[$tag_id] as $value) {
                $limits_array[] = $value['city_id'];
            }
        } else {
            $limits_array = array();
        }
        $pre_out = 1;
        $count = 0;
        $city_array = array();
        $numberOne = 1;
        while ($value = $this->dbs->fetchRow($res)) {
            $in_limits = in_array($value['city_id'], $limits_array);
            if (!$in_limits || $show_hide) {
                $row = array('count' => $value['count']);
                if ($in_limits) {
                    $row['hide'] = true;
                }
                $city_array[$value['city_id']] = $row;
                $count++;
                if ($count == $limit) {
                    break;
                }
                if ($count == 1) {
                    $numberOne = $value['city_id'];
                }
            }
        }
        $dbs = WikiFactory::db(DB_SLAVE);
        if (empty($city_array)) {
            return array("value" => array(), "age" => time());
        }
        $res = $dbs->select(array("city_list"), array("city_id, city_description, city_sitename, city_url, city_title"), array("city_id" => array_keys($city_array)), __METHOD__);
        while ($value = $dbs->fetchRow($res)) {
            if (!empty($city_array[$value['city_id']])) {
                $city_array[$value['city_id']] = array_merge($value, $city_array[$value['city_id']]);
                $city_array[$value['city_id']]['city_description'] = trim($city_array[$value['city_id']]['city_description']);
            }
        }
        $out = array("value" => $city_array, "age" => time());
        $wgMemc->set($mcKey, $out, 60 * 60 * 12);
        wfProfileOut(__METHOD__);
        return $out;
    }