/**
  * Adds awards for all registered users, updates statistics and purges
  * caches.
  * Special:PopulateAwards calls this function
  */
 public function update_system_gifts()
 {
     global $wgOut, $wgMemc;
     $dbw = wfGetDB(DB_MASTER);
     $stats = new UserStatsTrack(1, '');
     $this->categories = array_flip($this->categories);
     $res = $dbw->select('system_gift', array('gift_id', 'gift_category', 'gift_threshold', 'gift_name'), array(), __METHOD__, array('ORDER BY' => 'gift_category, gift_threshold ASC'));
     $x = 0;
     foreach ($res as $row) {
         if ($row->gift_category && !in_array($row->gift_category, $this->repeatableGifts)) {
             $res2 = $dbw->select('user_stats', array('stats_user_id', 'stats_user_name'), array($stats->stats_fields[$this->categories[$row->gift_category]] . " >= {$row->gift_threshold}", 'stats_user_id <> 0'), __METHOD__);
             foreach ($res2 as $row2) {
                 if ($this->doesUserHaveGift($row2->stats_user_id, $row->gift_id) == false) {
                     $dbw->insert('user_system_gift', array('sg_gift_id' => $row->gift_id, 'sg_user_id' => $row2->stats_user_id, 'sg_user_name' => $row2->stats_user_name, 'sg_status' => 0, 'sg_date' => date('Y-m-d H:i:s', time() - 60 * 60 * 24 * 3)), __METHOD__);
                     $sg_key = wfForeignMemcKey('huiji', '', 'user', 'profile', 'system_gifts', "{$row2->stats_user_id}");
                     $wgMemc->delete($sg_key);
                     // Update counters (bug #27981)
                     UserSystemGifts::incGiftGivenCount($row->gift_id);
                     $wgOut->addHTML(wfMessage('ga-user-got-awards', $row2->stats_user_name, $row->gift_name)->escaped() . '<br />');
                     $x++;
                 }
             }
         }
     }
     $wgOut->addHTML(wfMessage('ga-awards-given-out')->numParams($x)->parse());
 }
 static function getAllSitesRankFromDB($prefix, $yesterday)
 {
     global $wgMemc;
     wfDebug("Got site rank ( site = {$prefix},data = {$yesterday} ) from DB\n");
     $key = wfForeignMemcKey('huiji', '', 'site_rank', 'all_site_rank', $prefix, $yesterday);
     $allSiteRank = array();
     if ($prefix == '') {
         $dbr = wfGetDB(DB_SLAVE);
         $res = $dbr->select('site_rank', array('site_rank', 'site_score', 'site_prefix'), array('site_rank_date' => $yesterday), __METHOD__, array('ORDER BY' => 'site_rank ASC'));
         if ($res != false) {
             foreach ($res as $value) {
                 $result['site_prefix'] = $value->site_prefix;
                 $result['site_rank'] = $value->site_rank;
                 $result['site_score'] = $value->site_score;
                 $result['best_rank'] = AllSitesInfo::getSiteBestRank($value->site_prefix);
                 $allSiteRank[] = $result;
             }
         }
         $wgMemc->set($key, $allSiteRank);
         return $allSiteRank;
     } else {
         $dbr = wfGetDB(DB_SLAVE);
         $res = $dbr->select('site_rank', array('site_rank', 'site_score'), array('site_prefix' => $prefix, 'site_rank_date' => $yesterday), __METHOD__);
         if ($res != false) {
             foreach ($res as $value) {
                 $result['site_rank'] = $value->site_rank;
                 $result['site_score'] = $value->site_score;
                 $allSiteRank[] = $result;
             }
         }
         $wgMemc->set($key, $allSiteRank);
         return $allSiteRank;
     }
 }
 public function getUserEditInfo($userId)
 {
     global $wgMemc;
     $key = wfForeignMemcKey('huiji', '', 'user_daily_edit', 'all_days', $userId);
     $today = date("Y-m-d");
     $oneYearAgo = date("Y-m-d", strtotime("-1 year"));
     $yesterday = date("Y-m-d", strtotime("-1 day"));
     $userEditInfo = self::getUserEditInfoCache($userId);
     if ($userEditInfo == '') {
         $receive = RecordStatistics::getEditRecordsFromUserIdGroupByDay($userId, $oneYearAgo, $yesterday);
         if ($receive->status == 'success') {
             $userEditInfo = $receive->result;
             $userEditInfo['lastSeen'] = $today;
             $wgMemc->set($key, $userEditInfo);
         } else {
             $userEditInfo = false;
         }
     } else {
         if ($today == $userEditInfo['lastSeen']) {
             return $userEditInfo;
         }
         $receive = RecordStatistics::getEditRecordsFromUserIdGroupByDay($userId, $userEditInfo['lastSeen'], $yesterday);
         if ($receive->status == 'success') {
             $EditSinceLastSeen = $receive->result;
             $userEditInfo = array_merge($userEditInfo, $EditSinceLastSeen);
             $userEditInfo['lastSeen'] = $today;
             $wgMemc->set($key, $userEditInfo);
         } else {
             $userEditInfo = false;
         }
     }
     return $userEditInfo;
 }
 /**
  * Perform the queries necessary to update the social point counts and
  * purge memcached entries.
  */
 function updateMainEditsCount()
 {
     global $wgNamespacesForEditPoints;
     $out = $this->getOutput();
     $whereConds = array();
     $whereConds[] = 'rev_user <> 0';
     // If points are given out for editing non-main namespaces, take that
     // into account, too.
     if (isset($wgNamespacesForEditPoints) && is_array($wgNamespacesForEditPoints)) {
         foreach ($wgNamespacesForEditPoints as $pointNamespace) {
             $whereConds[] = 'page_namespace = ' . (int) $pointNamespace;
         }
     }
     $dbw = wfGetDB(DB_MASTER);
     $res = $dbw->select(array('revision', 'page'), array('rev_user_text', 'rev_user', 'COUNT(*) AS the_count'), $whereConds, __METHOD__, array('GROUP BY' => 'rev_user_text'), array('page' => array('INNER JOIN', 'page_id = rev_page')));
     foreach ($res as $row) {
         $user = User::newFromId($row->rev_user);
         $user->loadFromId();
         if (!$user->isAllowed('bot')) {
             $editCount = $row->the_count;
         } else {
             $editCount = 0;
         }
         $s = $dbw->selectRow('user_stats', array('stats_user_id'), array('stats_user_id' => $row->rev_user), __METHOD__);
         if (!$s->stats_user_id || $s === false) {
             $dbw->insert('user_stats', array('stats_year_id' => 0, 'stats_user_id' => $row->rev_user, 'stats_user_name' => $row->rev_user_text, 'stats_total_points' => 1000), __METHOD__);
         }
         $out->addWikiMsg('updateeditcounts-updating', $row->rev_user_text, $editCount);
         $dbw->update('user_stats', array('stats_edit_count = ' . $editCount), array('stats_user_id' => $row->rev_user), __METHOD__);
         global $wgMemc;
         // clear stats cache for current user
         $key = wfForeignMemcKey('huiji', '', 'user', 'stats', $row->rev_user);
         $wgMemc->delete($key);
     }
 }
 /**
  * Get latest revision ID of articles from NS_MEDIAWIKI for a given wiki
  *
  * @param integer $dbName - wiki database name (defaults to local wiki)
  */
 private static function getMemcacheKey($dbName = null)
 {
     global $wgDBname;
     if (is_null($dbName)) {
         $dbName = $wgDBname;
     }
     $key = wfForeignMemcKey($dbName, null, 'JSMessages', 'MWrevID');
     return $key;
 }
Example #6
0
 function getCacheKey()
 {
     if ($this->repo->hasSharedCache()) {
         $hashedName = md5($this->name);
         return wfForeignMemcKey($this->repo->dbName, $this->repo->tablePrefix, 'file', $hashedName);
     } else {
         return false;
     }
 }
 /**
  * Loads social profile info for the current user.
  * First tries fetching the info from memcached and if that fails, queries
  * the database.
  * Fetched info is cached in memcached.
  */
 public function getProfile()
 {
     global $wgMemc;
     $user = User::newFromId($this->user_id);
     $user->loadFromId();
     // Try cache first
     $key = wfForeignMemcKey('huiji', '', 'user', 'profile', 'info', $this->user_id);
     $data = $wgMemc->get($key);
     if ($data) {
         wfDebug("Got user profile info for {$this->user_name} from cache\n");
         $profile = $data;
     } else {
         wfDebug("Got user profile info for {$this->user_name} from DB\n");
         $dbr = wfGetDB(DB_SLAVE);
         $row = $dbr->selectRow('user_profile', '*', array('up_user_id' => $this->user_id), __METHOD__, array('LIMIT' => 5));
         if ($row) {
             $profile['user_id'] = $this->user_id;
         } else {
             $profile['user_page_type'] = 1;
             $profile['user_id'] = 0;
         }
         $showYOB = $user->getIntOption('showyearofbirth', !isset($row->up_birthday)) == 1;
         $issetUpBirthday = isset($row->up_birthday) ? $row->up_birthday : '';
         $profile['location_city'] = isset($row->up_location_city) ? $row->up_location_city : '';
         $profile['location_state'] = isset($row->up_location_state) ? $row->up_location_state : '';
         $profile['location_country'] = isset($row->up_location_country) ? $row->up_location_country : '';
         $profile['hometown_city'] = isset($row->up_hometown_city) ? $row->up_hometown_city : '';
         $profile['hometown_state'] = isset($row->up_hometown_state) ? $row->up_hometown_state : '';
         $profile['hometown_country'] = isset($row->up_hometown_country) ? $row->up_hometown_country : '';
         $profile['birthday'] = $this->formatBirthday($issetUpBirthday, $showYOB);
         $profile['about'] = isset($row->up_about) ? $row->up_about : '';
         $profile['places_lived'] = isset($row->up_places_lived) ? $row->up_places_lived : '';
         $profile['websites'] = isset($row->up_websites) ? $row->up_websites : '';
         $profile['relationship'] = isset($row->up_relationship) ? $row->up_relationship : '';
         $profile['occupation'] = isset($row->up_occupation) ? $row->up_occupation : '';
         $profile['schools'] = isset($row->up_schools) ? $row->up_schools : '';
         $profile['movies'] = isset($row->up_movies) ? $row->up_movies : '';
         $profile['music'] = isset($row->up_music) ? $row->up_music : '';
         $profile['tv'] = isset($row->up_tv) ? $row->up_tv : '';
         $profile['books'] = isset($row->up_books) ? $row->up_books : '';
         $profile['magazines'] = isset($row->up_magazines) ? $row->up_magazines : '';
         $profile['video_games'] = isset($row->up_video_games) ? $row->up_video_games : '';
         $profile['snacks'] = isset($row->up_snacks) ? $row->up_snacks : '';
         $profile['drinks'] = isset($row->up_drinks) ? $row->up_drinks : '';
         $profile['custom_1'] = isset($row->up_custom_1) ? $row->up_custom_1 : '';
         $profile['custom_2'] = isset($row->up_custom_2) ? $row->up_custom_2 : '';
         $profile['custom_3'] = isset($row->up_custom_3) ? $row->up_custom_3 : '';
         $profile['custom_4'] = isset($row->up_custom_4) ? $row->up_custom_4 : '';
         $profile['custom_5'] = isset($row->up_custom_5) ? $row->up_custom_5 : '';
         $profile['user_page_type'] = isset($row->up_type) ? $row->up_type : '';
         $wgMemc->set($key, $profile);
     }
     $profile['real_name'] = $user->getRealName();
     $profile['email'] = $user->getEmail();
     return $profile;
 }
    /**
     * Show the special page
     *
     * @param $par Mixed: parameter passed to the page or null
     */
    public function execute($par)
    {
        global $wgMemc, $wgUploadPath;
        $out = $this->getOutput();
        $request = $this->getRequest();
        $user = $this->getUser();
        // Set the page title, robot policies, etc.
        $this->setHeaders();
        // Add CSS
        $out->addModuleStyles('ext.socialprofile.usergifts.css');
        $this->gift_id = $request->getInt('gift_id');
        $rel = new UserGifts($user->getName());
        // Make sure that we have a gift ID, can't do anything without that
        if (!$this->gift_id || !is_numeric($this->gift_id)) {
            $out->setPageTitle($this->msg('g-error-title')->plain());
            $out->addHTML($this->msg('g-error-message-invalid-link')->plain());
            return false;
        }
        // And also ensure that we're not trying to delete *someone else's* gift(s)...
        if ($rel->doesUserOwnGift($user->getID(), $this->gift_id) == false) {
            $out->setPageTitle($this->msg('g-error-title')->plain());
            $out->addHTML($this->msg('g-error-do-not-own')->plain());
            return false;
        }
        $gift = $rel->getUserGift($this->gift_id);
        if ($request->wasPosted() && $_SESSION['alreadysubmitted'] == false) {
            $_SESSION['alreadysubmitted'] = true;
            $user_page_link = Title::makeTitle(NS_USER, $user->getName());
            if ($rel->doesUserOwnGift($user->getID(), $this->gift_id) == true) {
                $wgMemc->delete(wfForeignMemcKey('huiji', '', 'user', 'profile', 'gifts', $user->getID()));
                $rel->deleteGift($this->gift_id);
            }
            $gift_image = '<img src="' . $wgUploadPath . '/awards/' . Gifts::getGiftImage($gift['gift_id'], 'l') . '" border="0" alt="" />';
            $out->setPageTitle($this->msg('g-remove-success-title', $gift['name'])->parse());
            $out = '<div class="back-links">
				<a href="' . htmlspecialchars($user->getUserPage()->getFullURL()) . '">' . $this->msg('g-back-link', $gift['user_name_to'])->parse() . '</a>
			</div>
			<div class="g-container">' . $gift_image . $this->msg('g-remove-success-message', $gift['name'])->parse() . '<div class="cleared"></div>
			</div>
			<div class="g-buttons">
				<input type="button" class="site-button" value="' . $this->msg('g-main-page')->plain() . '" size="20" onclick="window.location=\'index.php?title=' . $this->msg('mainpage')->inContentLanguage()->escaped() . '\'" />
				<input type="button" class="site-button" value="' . $this->msg('g-your-profile')->plain() . '" size="20" onclick="window.location=\'' . htmlspecialchars($user_page_link->getFullURL()) . '\'" />
			</div>';
            $out->addHTML($out);
        } else {
            $_SESSION['alreadysubmitted'] = false;
            $out->addHTML($this->displayForm());
        }
    }
 public function getUserEditInfo($userId)
 {
     global $wgMemc;
     $key = wfForeignMemcKey('huiji', '', 'user_daily_edit', 'all_days', $userId);
     $today = date("Y-m-d");
     $oneYearAgo = date("Y-m-d", strtotime("-1 year"));
     $yesterday = date("Y-m-d", strtotime("-1 day"));
     $userEditInfo = self::getUserEditInfoCache($userId);
     if ($userEditInfo == '') {
         $receive = RecordStatistics::getEditRecordsFromUserIdGroupByDay($userId, $oneYearAgo, $yesterday);
         if ($receive->status == 'success') {
             $userEditInfo = $receive->result;
             $userEditInfo['lastSeen'] = $today;
             $wgMemc->set($key, $userEditInfo);
         } else {
             throw new Exception("Error getUserEditInfo/getEditRecordsFromUserIdGroupByDay Bad Request");
         }
     } else {
         if ($today == $userEditInfo['lastSeen']) {
             return $userEditInfo;
         }
         $Delres = array();
         if ($userEditInfo['lastSeen'] == $yesterday) {
             $receive = RecordStatistics::getPageEditCountOnWikiSiteFromUserId($userId, '', $yesterday, $yesterday);
             if ($receive->status == 'success') {
                 $Beres = $receive->result;
                 $Delres['_id'] = $yesterday;
                 $Delres['value'] = $Beres;
                 $resData[] = (object) $Delres;
                 $userEditInfo = array_merge($userEditInfo, $resData);
                 $userEditInfo['lastSeen'] = $today;
                 $wgMemc->set($key, $userEditInfo);
             } else {
                 throw new Exception("Error getUserEditInfo/getPageEditCountOnWikiSiteFromUserId Bad Request");
             }
         } else {
             $receive = RecordStatistics::getEditRecordsFromUserIdGroupByDay($userId, $userEditInfo['lastSeen'], $yesterday);
             if ($receive->status == 'success') {
                 $EditSinceLastSeen = $receive->result;
                 $userEditInfo = array_merge($userEditInfo, $EditSinceLastSeen);
                 $userEditInfo['lastSeen'] = $today;
                 $wgMemc->set($key, $userEditInfo);
             } else {
                 throw new Exception("Error getUserEditInfo/getEditRecordsFromUserIdGroupByDay Bad Request");
             }
         }
     }
     return $userEditInfo;
 }
Example #10
0
 /**
  * count all site edits,files,pages,sites,users,
  * @return array 
  */
 public function getStats()
 {
     $key = wfForeignMemcKey('huiji', '', 'Huiji', 'getStats');
     $stats = $this->cache->get($key);
     if ($stats != '') {
         return $stats;
     } else {
         $stats['edits'] = AllSitesInfo::getAllSiteEditCount();
         $stats['files'] = AllSitesInfo::getAllUploadFileCount();
         $stats['pages'] = AllSitesInfo::getAllPageCount();
         $stats['sites'] = AllSitesInfo::getSiteCountNum();
         $stats['users'] = AllSitesInfo::getUserCountNum();
         $this->cache->set($key, $stats, 24 * 60 * 60);
     }
     return $stats;
 }
Example #11
0
/**
 * Updates user's points after a page in a namespace that is listed in the
 * $wgNamespacesForEditPoints array that they've edited has been restored after
 * it was originally deleted.
 */
function restoreDeletedEdits(&$title, $new)
{
    global $wgNamespacesForEditPoints, $wgMemc, $wgHuijiPrefix;
    // only keep tally for allowable namespaces
    if (!is_array($wgNamespacesForEditPoints) || in_array($title->getNamespace(), $wgNamespacesForEditPoints)) {
        $dbr = wfGetDB(DB_MASTER);
        $res = $dbr->select('revision', array('rev_user_text', 'rev_user', 'COUNT(*) AS the_count'), array('rev_page' => $title->getArticleID(), 'rev_user <> 0'), __METHOD__, array('GROUP BY' => 'rev_user_text'));
        foreach ($res as $row) {
            $stats = new UserStatsTrack($row->rev_user, $row->rev_user_text);
            $stats->incStatField('edit', $row->the_count);
            $key = wfForeignMemcKey('huiji', '', 'revision', 'high_edit_site_followed', $row->rev_user_text, $wgHuijiPrefix);
            $wgMemc->incr($key, $row->the_count);
        }
    }
    return true;
}
 /**
  * @param string $key
  * @param array $ids
  * @param callable $loadCallback
  * @return array
  * @throws InvalidInputException
  */
 public function get($key, array $ids, $loadCallback)
 {
     $key = implode(':', (array) $key);
     $cacheKeys = array();
     foreach ($ids as $id) {
         if ($id instanceof UUID) {
             $cacheId = $id->getAlphadecimal();
         } elseif (!is_scalar($id)) {
             $type = is_object($id) ? get_class($id) : gettype($id);
             throw new InvalidInputException('Not scalar:' . $type, 'invalid-input');
         } else {
             $cacheId = $id;
         }
         $cacheKeys[wfForeignMemcKey('flow', '', $key, $cacheId, Container::get('cache.version'))] = $id;
     }
     return $this->getByKey($cacheKeys, $loadCallback);
 }
Example #13
0
 /**
  * get site name by prefix, if exist this prefix return site name, else return this prefix
  * @param  string $prefix site prefix ex:'lotr'
  * @return string         [description]
  */
 public static function prefixToSiteName($prefix)
 {
     global $wgMemc;
     $key = wfForeignMemcKey('huiji', '', 'prefixToSiteName', $prefix);
     $data = $wgMemc->get($key);
     if ($data != '') {
         return $data;
     } else {
         $dbr = wfGetDB(DB_SLAVE);
         $s = $dbr->selectRow('domain', array('domain_id', 'domain_name'), array('domain_prefix' => $prefix), __METHOD__);
         if ($s !== false) {
             $wgMemc->set($key, $s->domain_name);
             return $s->domain_name;
         } else {
             return $prefix;
         }
     }
 }
Example #14
0
 /**
  * Fetches the avatar image's name from the filesystem
  * @return Avatar image's file name (i.e. default_l.gif or wikidb_3_l.jpg;
  *			first part for non-default images is the database name, second
  *			part is the user's ID number and third part is the letter for
  *			image size (s, m, ml or l)
  */
 function getAvatarImage()
 {
     global $wgSiteAvatarKey, $wgUploadDirectory, $wgMemc;
     $key = wfForeignMemcKey('huiji', '', 'site', 'profile', 'avatar', $this->user_id, $this->avatar_size);
     $data = $wgMemc->get($key);
     // Load from memcached if possible
     if ($data) {
         $avatar_filename = $data;
     } else {
         $files = glob($wgUploadDirectory . '/avatars/' . $wgSiteAvatarKey . '_' . $this->user_id . '_' . $this->avatar_size . "*");
         if (!isset($files[0]) || !$files[0]) {
             $avatar_filename = 'site_default_' . $this->avatar_size . '.png';
         } else {
             $avatar_filename = basename($files[0]) . '?r=' . filemtime($files[0]);
         }
         $wgMemc->set($key, $avatar_filename, 60 * 60 * 24);
         // cache for 24 hours
     }
     return $avatar_filename;
 }
 /**
  * Show the special page
  *
  * @param $params Mixed: parameter(s) passed to the page or null
  */
 public function execute($params)
 {
     global $wgMemc;
     $out = $this->getOutput();
     $user = $this->getUser();
     // This feature is only available to logged-in users.
     if (!$user->isLoggedIn()) {
         throw new ErrorPageError('error', 'badaccess');
     }
     // Show a message if the database is in read-only mode
     if (wfReadOnly()) {
         $out->readOnlyPage();
         return;
     }
     $dbw = wfGetDB(DB_MASTER);
     $s = $dbw->selectRow('user_profile', array('up_user_id'), array('up_user_id' => $user->getID()), __METHOD__);
     if ($s === false) {
         $dbw->insert('user_profile', array('up_user_id' => $user->getID()), __METHOD__);
     }
     $profile = new UserProfile($user->getName());
     $profile_data = $profile->getProfile();
     $user_page_type = $profile_data['user_page_type'] == 1 ? 0 : 1;
     $dbw->update('user_profile', array('up_type' => $user_page_type), array('up_user_id' => $user->getID()), __METHOD__);
     $key = wfForeignMemcKey('huiji', '', 'user', 'profile', 'info', $user->getID());
     $wgMemc->delete($key);
     if ($user_page_type == 1 && !$user->isBlocked()) {
         $user_page = Title::makeTitle(NS_USER, $user->getName());
         $article = new Article($user_page);
         $user_page_content = $article->getContent();
         $user_wiki_title = Title::makeTitle(NS_USER_WIKI, $user->getName());
         $user_wiki = new Article($user_wiki_title);
         if (!$user_wiki->exists()) {
             $user_wiki->doEdit($user_page_content, 'import user wiki');
         }
     }
     $title = Title::makeTitle(NS_USER, $user->getName());
     $out->redirect($title->getFullURL());
 }
Example #16
0
 /**
  * Returns text contents by given text_id from foreign wiki
  *
  * @see Revision::loadText
  * @param $textId int Foreign wiki text id
  * @return String|false
  */
 protected function getContentByTextId($textId)
 {
     global $wgMemc;
     $key = wfForeignMemcKey($this->getDatabaseName(), null, 'revisiontext', 'textid', $textId);
     $text = $wgMemc->get($key);
     if (!empty($text)) {
         return $text;
     }
     $row = null;
     // copied from Article::loadText()
     if (!$row) {
         // Text data is immutable; check slaves first.
         $dbr = $this->getConnection(DB_SLAVE);
         $row = $dbr->selectRow('text', array('old_text', 'old_flags'), array('old_id' => $textId), __METHOD__);
     }
     if (!$row && wfGetLB()->getServerCount() > 1) {
         // Possible slave lag!
         $dbw = $this->getConnection(DB_MASTER);
         $row = $dbw->selectRow('text', array('old_text', 'old_flags'), array('old_id' => $textId), __METHOD__);
     }
     $text = Revision::getRevisionText($row);
     if (!is_string($text)) {
         $text = false;
     }
     return $text;
 }
 /**
  * @param string $name
  * @return mixed
  */
 private function getCachedConfigVar($name)
 {
     global $wgConf, $wgMemc;
     if ($this->wiki === wfWikiID()) {
         return $GLOBALS[$name];
         // common case
     } else {
         list($db, $prefix) = wfSplitWikiID($this->wiki);
         $key = wfForeignMemcKey($db, $prefix, 'configvalue', $name);
         $value = $wgMemc->get($key);
         // ('v' => ...) or false
         if (is_array($value)) {
             return $value['v'];
         } else {
             $value = $wgConf->getConfig($this->wiki, $name);
             $wgMemc->set($key, array('v' => $value), 86400 + mt_rand(0, 86400));
             return $value;
         }
     }
 }
Example #18
0
 /**
  * @param string $property
  * @return string
  */
 private function getCacheKey($property)
 {
     list($db, $prefix) = wfSplitWikiID($this->wiki);
     $cluster = is_string($this->cluster) ? $this->cluster : 'main';
     return wfForeignMemcKey($db, $prefix, 'jobqueue', $cluster, $this->type, $property);
 }
Example #19
0
 public function testWfForeignMemcKey()
 {
     $this->setMwGlobals(array('wgCachePrefix' => false, 'wgDBname' => 'example', 'wgDBprefix' => ''));
     $local = wfMemcKey('foo', 'bar');
     $this->setMwGlobals(array('wgDBname' => 'other', 'wgDBprefix' => 'mw_'));
     $this->assertEquals(wfForeignMemcKey('example', '', 'foo', 'bar'), $local, 'Match output of wfMemcKey from local wiki');
 }
Example #20
0
 /**
  * @param string $signature Hash identifier of the root job
  * @return string
  */
 protected function getRootJobCacheKey($signature)
 {
     list($db, $prefix) = wfSplitWikiID($this->wiki);
     return wfForeignMemcKey($db, $prefix, 'jobqueue', $this->type, 'rootjob', $signature);
 }
Example #21
0
	/**
	 * @return string
	 */
	private function getCacheKey( $property ) {
		list( $db, $prefix ) = wfSplitWikiID( $this->wiki );
		return wfForeignMemcKey( $db, $prefix, 'jobqueue', $this->type, $property );
	}
 /**
  * Get the amount of open user relationship requests from cache.
  *
  * @param $userId Integer: user ID for whom to get the requests
  * @param $relType Integer: 1 for friends, 2 (or anything else but 1) for foes
  * @return Integer
  */
 static function getOpenRequestCountCache($userId, $relType)
 {
     global $wgMemc;
     $key = wfForeignMemcKey('huiji', '', 'user_relationship', 'open_request', $relType, $userId);
     $data = $wgMemc->get($key);
     if ($data != '') {
         wfDebug("Got open request count of {$data} (type={$relType}) for id {$userId} from cache\n");
         return $data;
     }
 }
 /**
  * @param $group
  * @return String
  */
 public static function getGlobalRulesKey($group)
 {
     global $wgAbuseFilterIsCentral, $wgAbuseFilterCentralDB;
     if (!$wgAbuseFilterIsCentral) {
         list($globalSite, $globalPrefix) = wfSplitWikiID($wgAbuseFilterCentralDB);
         return wfForeignMemcKey($globalSite, $globalPrefix, 'abusefilter', 'rules', $group);
     }
     return wfMemcKey('abusefilter', 'rules', $group);
 }
 /**
  * Replaces User::touchUser()
  */
 function invalidateCache()
 {
     $this->db->update('user', array('user_touched' => $this->db->timestamp()), array('user_id' => $this->id), __METHOD__);
     global $wgMemc;
     $key = wfForeignMemcKey($this->database, false, 'user', 'id', $this->id);
     $wgMemc->delete($key);
 }
Example #25
0
 /**
  * Get the memcached keys
  * Returns an array, first element is the local cache key, second is the shared cache key, if there is one
  */
 function getCacheKeys()
 {
     global $wgUseSharedUploads, $wgSharedUploadDBname, $wgCacheSharedUploads;
     $hashedName = md5($this->name);
     $keys = array(wfMemcKey('Image', $hashedName));
     if ($wgUseSharedUploads && $wgSharedUploadDBname && $wgCacheSharedUploads) {
         $keys[] = wfForeignMemcKey($wgSharedUploadDBname, false, 'Image', $hashedName);
     }
     return $keys;
 }
Example #26
0
 function touchUser($database, $userid)
 {
     $this->db->update('user', array('user_touched' => $this->db->timestamp()), array('user_id' => $userid), 'MakesysopStewardForm::touchUser');
     global $wgMemc;
     if (function_exists('wfForeignMemcKey')) {
         $key = wfForeignMemcKey($database, false, 'user', 'id', $userid);
     } else {
         $key = "{$database}:user:id:{$userid}";
     }
     $wgMemc->delete($key);
 }
Example #27
0
 /**
  * Get the cache key for a container
  *
  * @param string $username
  * @return string
  */
 private function getCredsCacheKey($username)
 {
     // Wikia change - begin
     global $wgFSSwiftServer;
     // Wikia change - end
     return wfForeignMemcKey(__CLASS__, $wgFSSwiftServer, 'usercreds', $username);
 }
Example #28
0
 public function testWfForeignMemcKey()
 {
     $cache = ObjectCache::getLocalClusterInstance();
     $keyspace = $this->readAttribute($cache, 'keyspace');
     $this->assertEquals(wfForeignMemcKey($keyspace, '', 'foo', 'bar'), $cache->makeKey('foo', 'bar'));
 }
Example #29
0
 static function getLastEditerDB($revPageId, $prefix)
 {
     global $wgMemc;
     $key = wfForeignMemcKey('huiji', '', 'revision', 'last_edit_user', $revPageId, $prefix);
     $dbr = wfGetDB(DB_SLAVE);
     $data = $dbr->select('revision', array('rev_user', 'rev_user_text', 'rev_timestamp'), array('rev_page' => $revPageId), __METHOD__, array('ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => '1'));
     foreach ($data as $value) {
         $res['rev_user'] = $value->rev_user;
         $res['rev_user_text'] = $value->rev_user_text;
         $res['rev_timestamp'] = $value->rev_timestamp;
     }
     if ($res) {
         $wgMemc->set($key, $res);
         return $res;
     }
 }
 private function getTagsInfo()
 {
     global $wgMemc, $wgSharedDB, $wgStatsDB, $wgStatsDBEnabled;
     global $wgCityId;
     $tagsArticles = array();
     $memkey = wfForeignMemcKey($wgSharedDB, null, "TagsReport", $this->mTag, $wgCityId);
     $cached = $wgMemc->get($memkey);
     if (!is_array($cached) && !empty($wgStatsDBEnabled)) {
         $dbs = wfGetDB(DB_SLAVE, array(), $wgStatsDB);
         if (!is_null($dbs)) {
             $query = "select ct_namespace, ct_page_id from city_used_tags where ct_kind = " . $dbs->addQuotes($this->mTag) . " and ct_wikia_id = {$wgCityId} order by ct_namespace";
             $res = $dbs->query($query, __METHOD__);
             while ($row = $dbs->fetchObject($res)) {
                 $tagsArticles[$row->ct_namespace][] = $row->ct_page_id;
             }
             $dbs->freeResult($res);
             $wgMemc->set($memkey, $tagsArticles, 60 * 60 * 3);
         }
     } else {
         $tagsArticles = $cached;
     }
     return $tagsArticles;
 }