本文整理汇总了PHP中wfMemcKey函数的典型用法代码示例。如果您正苦于以下问题:PHP wfMemcKey函数的具体用法?PHP wfMemcKey怎么用?PHP wfMemcKey使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wfMemcKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: WidgetFounderBadge
function WidgetFounderBadge($id, $params)
{
$output = "";
wfProfileIn(__METHOD__);
global $wgMemc;
$key = wfMemcKey("WidgetFounderBadge", "user");
$user = $wgMemc->get($key);
if (is_null($user)) {
global $wgCityId;
$user = WikiFactory::getWikiById($wgCityId)->city_founding_user;
$wgMemc->set($key, $user, 3600);
}
if (0 == $user) {
return wfMsgForContent("widget-founderbadge-notavailable");
}
$key = wfMemcKey("WidgetFounderBadge", "edits");
$edits = $wgMemc->get($key);
if (empty($edits)) {
$edits = AttributionCache::getInstance()->getUserEditPoints($user);
$wgMemc->set($key, $edits, 300);
}
$author = array("user_id" => $user, "user_name" => User::newFromId($user)->getName(), "edits" => $edits);
$output = Answer::getUserBadge($author);
wfProfileOut(__METHOD__);
return $output;
}
示例2: execute
/**
* Generates feed's content
*
* @param $feed ChannelFeed subclass object (generally the one returned by getFeedObject())
* @param $rows ResultWrapper object with rows in recentchanges table
* @param $lastmod Integer: timestamp of the last item in the recentchanges table (only used for the cache key)
* @param $opts FormOptions as in SpecialRecentChanges::getDefaultOptions()
* @return null or true
*/
public function execute($feed, $rows, $lastmod, $opts)
{
global $messageMemc, $wgFeedCacheTimeout;
global $wgSitename, $wgLang;
if (!FeedUtils::checkFeedOutput($this->format)) {
return;
}
$timekey = wfMemcKey($this->type, $this->format, 'timestamp');
$optionsHash = md5(serialize($opts->getAllValues()));
$key = wfMemcKey($this->type, $this->format, $wgLang->getCode(), $optionsHash);
FeedUtils::checkPurge($timekey, $key);
/*
* Bumping around loading up diffs can be pretty slow, so where
* possible we want to cache the feed output so the next visitor
* gets it quick too.
*/
$cachedFeed = $this->loadFromCache($lastmod, $timekey, $key);
if (is_string($cachedFeed)) {
wfDebug("RC: Outputting cached feed\n");
$feed->httpHeaders();
echo $cachedFeed;
} else {
wfDebug("RC: rendering new feed and caching it\n");
ob_start();
self::generateFeed($rows, $feed);
$cachedFeed = ob_get_contents();
ob_end_flush();
$this->saveToCache($cachedFeed, $timekey, $key);
}
return true;
}
示例3: WidgetCategoryCloud
function WidgetCategoryCloud($id, $params)
{
$output = "";
wfProfileIn(__METHOD__);
global $wgMemc;
$key = wfMemcKey("WidgetCategoryCloud", "data");
$data = $wgMemc->get($key);
if (is_null($data)) {
$data = WidgetCategoryCloudCloudizeData(WidgetCategoryCloudGetData());
$wgMemc->set($key, $data, 3600);
}
if (empty($data)) {
wfProfileOut(__METHOD__);
return wfMsgForContent("widget-categorycloud-empty");
}
foreach ($data as $name => $value) {
$category = Title::newFromText($name, NS_CATEGORY);
if (is_object($category)) {
$class = "cloud" . $value;
$output .= Xml::openElement("li", array("class" => $class));
// FIXME fix Wikia:link and use it here
$output .= Xml::element("a", array("class" => $class, "href" => $category->getLocalURL(), "title" => $category->getFullText()), $category->getBaseText());
$output .= Xml::closeElement("li");
$output .= "\n";
}
}
if (empty($output)) {
wfProfileOut(__METHOD__);
return wfMsgForContent("widget-categorycloud-empty");
}
$output = Xml::openElement("ul") . $output . Xml::closeElement("ul");
wfProfileOut(__METHOD__);
return $output;
}
示例4: wfNumberOfWikisAssignValue
function wfNumberOfWikisAssignValue(&$parser, &$cache, &$magicWordId, &$ret)
{
global $wgMemc;
if ($magicWordId == 'NUMBEROFWIKIS') {
$key = wfMemcKey('shoutwiki', 'numberofwikis');
$data = $wgMemc->get($key);
if ($data != '') {
// We have it in cache? Oh goody, let's just use the cached value!
wfDebugLog('NumberOfWikis', 'Got the amount of wikis from memcached');
// return value
$ret = $data;
} else {
// Not cached → have to fetch it from the database
$dbr = wfGetDB(DB_SLAVE);
$res = $dbr->select('wiki_list', 'COUNT(*) AS count', array('wl_deleted' => 0), __METHOD__);
wfDebugLog('NumberOfWikis', 'Got the amount of wikis from DB');
foreach ($res as $row) {
// Store the count in cache...
// (86400 = seconds in a day)
$wgMemc->set($key, $row->count, 86400);
// ...and return the value to the user
$ret = $row->count;
}
}
}
return true;
}
示例5: updateMainEditsCount
/**
* Perform the queries necessary to update the social point counts and
* purge memcached entries.
*/
function updateMainEditsCount()
{
global $wgOut, $wgNamespacesForEditPoints;
$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__);
}
$wgOut->addHTML("<p>Updating {$row->rev_user_text} with {$editCount} edits</p>");
$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 = wfMemcKey('user', 'stats', $row->rev_user);
$wgMemc->delete($key);
}
}
示例6: __construct
/**
* Constructor
*
* @param $langobj The Language Object
* @param $maincode String: the main language code of this language
* @param $variants Array: the supported variants of this language
* @param $variantfallbacks Array: the fallback language of each variant
* @param $flags Array: defining the custom strings that maps to the flags
* @param $manualLevel Array: limit for supported variants
*/
public function __construct($langobj, $maincode, $variants = array(), $variantfallbacks = array(), $flags = array(), $manualLevel = array())
{
$this->mLangObj = $langobj;
$this->mMainLanguageCode = $maincode;
global $wgDisabledVariants;
$this->mVariants = array();
foreach ($variants as $variant) {
if (!in_array($variant, $wgDisabledVariants)) {
$this->mVariants[] = $variant;
}
}
$this->mVariantFallbacks = $variantfallbacks;
global $wgLanguageNames;
$this->mVariantNames = $wgLanguageNames;
$this->mCacheKey = wfMemcKey('conversiontables', $maincode);
$f = array('A' => 'A', 'T' => 'T', 'R' => 'R', 'D' => 'D', '-' => '-', 'H' => 'H', 'N' => 'N');
$this->mFlags = array_merge($f, $flags);
foreach ($this->mVariants as $v) {
if (array_key_exists($v, $manualLevel)) {
$this->mManualLevel[$v] = $manualLevel[$v];
} else {
$this->mManualLevel[$v] = 'bidirectional';
}
$this->mNamespaceTables[$v] = array();
$this->mFlags[$v] = $v;
}
}
示例7: wfProxyCheck
/**
* Forks processes to scan the originating IP for an open proxy server
* MemCached can be used to skip IPs that have already been scanned
*/
function wfProxyCheck()
{
global $wgBlockOpenProxies, $wgProxyPorts, $wgProxyScriptPath;
global $wgUseMemCached, $wgMemc, $wgProxyMemcExpiry;
global $wgProxyKey;
if (!$wgBlockOpenProxies) {
return;
}
$ip = wfGetIP();
# Get MemCached key
$skip = false;
if ($wgUseMemCached) {
$mcKey = wfMemcKey('proxy', 'ip', $ip);
$mcValue = $wgMemc->get($mcKey);
if ($mcValue) {
$skip = true;
}
}
# Fork the processes
if (!$skip) {
$title = Title::makeTitle(NS_SPECIAL, 'Blockme');
$iphash = md5($ip . $wgProxyKey);
$url = $title->getFullURL('ip=' . $iphash);
foreach ($wgProxyPorts as $port) {
$params = implode(' ', array(escapeshellarg($wgProxyScriptPath), escapeshellarg($ip), escapeshellarg($port), escapeshellarg($url)));
exec("php {$params} &>/dev/null &");
}
# Set MemCached key
if ($wgUseMemCached) {
$wgMemc->set($mcKey, 1, $wgProxyMemcExpiry);
}
}
}
示例8: getTodaysTotal
/**
* Get the total amount of money raised for today
* @param string $timeZoneOffset The timezone to request the total for
* @param string $today The current date in the requested time zone, e.g. '2011-12-16'
* @param int $fudgeFactor How much to adjust the total by
* @return integer
*/
private function getTodaysTotal($timeZoneOffset, $today, $fudgeFactor = 0)
{
global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout;
// Delete this block once there is timezone support in the populating script
$setTimeZone = date_default_timezone_set('UTC');
$today = date('Y-m-d');
// Get the current date in UTC
$timeZoneOffset = '+00:00';
$key = wfMemcKey('fundraiserdailytotal', $timeZoneOffset, $today, $fudgeFactor);
$cache = $wgMemc->get($key);
if ($cache != false && $cache != -1) {
return $cache;
}
// Use MediaWiki slave database
$dbr = wfGetDB(DB_SLAVE);
$result = $dbr->select('public_reporting_days', 'round( prd_total ) AS total', array('prd_date' => $today), __METHOD__);
$row = $dbr->fetchRow($result);
if ($row['total'] > 0) {
$total = $row['total'];
} else {
$total = 0;
}
// Make sure the fudge factor is a number
if (is_nan($fudgeFactor)) {
$fudgeFactor = 0;
}
// Add the fudge factor to the total
$total += $fudgeFactor;
$wgMemc->set($key, $total, $egFundraiserStatisticsCacheTimeout);
return $total;
}
示例9: memcacheKey
public static function memcacheKey()
{
// mech: bugfix for 19619 in getTemplateData method requires me to invalidate the cache,
// so I'm changing the memkey
$mKey = wfMemcKey('mOasisLatestPhotosKey' . self::MEMC_KEY_VER);
return $mKey;
}
示例10: set
static function set($title, $content)
{
global $wgRevisionCacheExpiry, $wgMemc;
if (!$wgRevisionCacheExpiry) {
// caching is not possible
return false;
}
// we need to assign a sequence to revision text, because
// Article::loadContent expects page.text_id to be an integer.
$seq_key = wfMemcKey('offline', 'textid_seq');
if (!$wgMemc->get($seq_key)) {
$wgMemc->set($seq_key, 1);
}
// and clear the cache??
$textid = $wgMemc->incr($seq_key);
// cache a lookup from title to fake textid
$titlekey = wfMemcKey('textid', 'titlehash', md5($title));
$wgMemc->set($titlekey, $textid, $wgRevisionCacheExpiry);
// TODO interfering with the cache is necessary to avoid a
// second query on Revision::newFromId. It would be much
// smarter to directly retrieve article markup, and optionally
// cache in the usual way.
$textkey = wfMemcKey('revisiontext', 'textid', $textid);
$wgMemc->delete($textkey);
$wgMemc->set($textkey, $content, $wgRevisionCacheExpiry);
//wfDebug('Stuffing the cache with '.strlen($content).' bytes, at id='.$textid."\n");
return $textid;
}
示例11: testFifoLineAndMemcClear
function testFifoLineAndMemcClear() {
global $wgMemc;
$startTime = 100;
$timeSample = 5;
$fifoLength = 60;
$key = wfMemcKey( "hp_stats_test", "stat_hp_fifo_week" );
$wgMemc->set( $key,array(),60);
$startTime += 1;
$out = HomePageStatisticCollector::fifoLine(1,$timeSample,$fifoLength,$key,$startTime);
$this->assertEquals( 1,$out);
$startTime += 15;
$out = HomePageStatisticCollector::fifoLine(2,$timeSample,$fifoLength,$key,$startTime);
$this->assertEquals( 3,$out);
$startTime += 105;
$out = HomePageStatisticCollector::fifoLine(3,$timeSample,$fifoLength,$key,$startTime);
$this->assertEquals( 5,$out);
$wgMemc->delete($key);
$title = "corporatepage-test-msg";
$text = "";
$key = wfMemcKey( "hp_msg_parser", $title, 'en' ) ;
$wgMemc->set($key,"test value",30);
$this->assertEquals("test value", $wgMemc->get($key));
CorporatePageHelper::clearMessageCache($title,$text);
$this->assertNull($wgMemc->get($key));
}
示例12: getInterfaceObjectFromType
protected function getInterfaceObjectFromType($type)
{
wfProfileIn(__METHOD__);
$apiUrl = $this->getApiUrl();
if (empty($this->videoId)) {
throw new EmptyResponseException($apiUrl);
}
$memcKey = wfMemcKey(static::$CACHE_KEY, $apiUrl, static::$CACHE_KEY_VERSION);
$processedResponse = F::app()->wg->memc->get($memcKey);
if (empty($processedResponse)) {
$req = MWHttpRequest::factory($apiUrl, array('noProxy' => true));
$req->setHeader('User-Agent', self::$REQUEST_USER_AGENT);
$status = $req->execute();
if ($status->isOK()) {
$response = $req->getContent();
$this->response = $response;
// Only for migration purposes
if (empty($response)) {
throw new EmptyResponseException($apiUrl);
} else {
if ($req->getStatus() == 301) {
throw new VideoNotFoundException($req->getStatus(), $this->videoId . ' Moved Permanently.', $apiUrl);
}
}
} else {
$this->checkForResponseErrors($req->status, $req->getContent(), $apiUrl);
}
$processedResponse = $this->processResponse($response, $type);
F::app()->wg->memc->set($memcKey, $processedResponse, static::$CACHE_EXPIRY);
}
wfProfileOut(__METHOD__);
return $processedResponse;
}
示例13: getInlineScript
/**
* Get contents of a javascript file for inline use.
*
* Roughly based MediaWiki core methods:
* - ResourceLoader::filter()
* - ResourceLoaderFileModule::readScriptFiles()
*
* @param string $name Path to file relative to /modules/inline/
* @return string Minified script
* @throws Exception If file doesn't exist
*/
protected static function getInlineScript($name)
{
// Get file
$filePath = __DIR__ . '/../../modules/inline/' . $name;
if (!file_exists($filePath)) {
throw new Exception(__METHOD__ . ": file not found: \"{$filePath}\"");
}
$contents = file_get_contents($filePath);
// Try minified from cache
$key = wfMemcKey('centralauth', 'minify-js', md5($contents));
$cache = wfGetCache(CACHE_ANYTHING);
$cacheEntry = $cache->get($key);
if (is_string($cacheEntry)) {
return $cacheEntry;
}
// Compute new value
$result = '';
try {
$result = JavaScriptMinifier::minify($contents) . "\n/* cache key: {$key} */";
$cache->set($key, $result);
} catch (Exception $e) {
MWExceptionHandler::logException($e);
wfDebugLog('CentralAuth', __METHOD__ . ": minification failed for {$name}: {$e}");
$result = ResourceLoader::formatException($e) . "\n" . $contents;
}
return $result;
}
示例14: onArticleSaveComplete
/**
* @param $article Article
* @param $user User
* @param $text
* @param $summary
* @param $minoredit
* @param $watchthis
* @param $sectionanchor
* @param $flags
* @param $revision
* @param $status
* @param $baseRevId
* @return bool
*/
static function onArticleSaveComplete(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId)
{
global $wgMemc;
$mKey = wfMemcKey('mOasisRelatedPages', $article->mTitle->getArticleId());
$wgMemc->delete($mKey);
return true;
}
示例15: getArticleQuality
/**
* Returns percentile quality of articleId or null if not found
* @return int|null
*/
public function getArticleQuality()
{
$cacheKey = wfMemcKey(__CLASS__, self::CACHE_BUSTER, $this->articleId);
$percentile = $this->app->wg->Memc->get($cacheKey);
if ($percentile === false) {
$title = Title::newFromID($this->articleId);
if ($title === null) {
return null;
}
$article = new Article($title);
$parserOutput = $article->getParserOutput();
if (!$parserOutput) {
//MAIN-3592
$this->error(__METHOD__, ['message' => 'Article::getParserOutput returned false', 'articleId' => $this->articleId]);
return null;
}
$inputs = ['outbound' => 0, 'inbound' => 0, 'length' => 0, 'sections' => 0, 'images' => 0];
/**
* $title->getLinksTo() and $title->getLinksFrom() function are
* too expensive to call it here as we want only the number of links
*/
$inputs['outbound'] = $this->countOutboundLinks($this->articleId);
$inputs['inbound'] = $this->countInboundLinks($this->articleId);
$inputs['sections'] = count($parserOutput->getSections());
$inputs['images'] = count($parserOutput->getImages());
$inputs['length'] = $this->getCharsCountFromHTML($parserOutput->getText());
$quality = $this->computeFormula($inputs);
$percentile = $this->searchPercentile($quality);
$this->app->wg->Memc->set($cacheKey, $percentile, self::MEMC_CACHE_TIME);
}
return $percentile;
}