コード例 #1
0
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
0
ファイル: ChangesFeed.php プロジェクト: rocLv/conference
 /**
  * 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
0
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
0
ファイル: NumberOfWikis.php プロジェクト: schwarer2006/wikia
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
0
 /**
  * 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
0
 /**
  * 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
0
ファイル: ProxyTools.php プロジェクト: puring0815/OpenKore
/**
 * 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
0
 /**
  * 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
0
 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
0
 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
0
	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
0
 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;
 }
 /**
  * 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
0
 /**
  * @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
0
 /**
  * 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;
 }
コード例 #16
0
 /**
  * @desc Related pages are lazy-loaded on article pages for mobile, oasis and monobook. However, there are extensions
  * dependent on this method where related pages module isn't lazy-loaded such as: FilePage (FilePageController.class.php)
  */
 public function section()
 {
     global $wgTitle, $wgContentNamespaces, $wgRequest, $wgMemc;
     // request params
     $altTitle = $this->request->getVal('altTitle', null);
     $relatedPages = RelatedPages::getInstance();
     $anyNs = $this->request->getVal('anyNS', false);
     $title = empty($altTitle) ? $wgTitle : $altTitle;
     $articleid = $title->getArticleId();
     if (!$anyNs) {
         $ignoreNS = !empty($wgTitle) && in_array($wgTitle->getNamespace(), $wgContentNamespaces);
     } else {
         $ignoreNS = false;
     }
     $this->skipRendering = Wikia::isMainPage() || $ignoreNS || count($relatedPages->getCategories($articleid)) == 0 || $wgRequest->getVal('action', 'view') != 'view' || $relatedPages->isRendered();
     if (!$this->skipRendering) {
         $mKey = wfMemcKey('mOasisRelatedPages', $articleid, self::MEMC_KEY_VER);
         $this->pages = $wgMemc->get($mKey);
         $this->srcAttrName = $this->app->checkSkin('monobook') ? 'src' : 'data-src';
         if (empty($this->pages)) {
             $this->pages = $relatedPages->get($articleid);
             if (count($this->pages) > 0) {
                 $wgMemc->set($mKey, $this->pages, 3 * 3600);
             } else {
                 $this->skipRendering = true;
             }
         }
     }
     $this->mobileSkin = false;
     $this->relatedPagesHeading = wfMessage('wikiarelatedpages-heading')->plain();
 }
コード例 #17
0
function purgeStaleMemcachedText() {
	global $wgMemc, $wgDBname;
	$db = wfGetDB( DB_MASTER );
	$maxTextId = $db->selectField( 'text', 'max(old_id)' );
	$latestReplicatedTextId = $db->selectField( array( 'recentchanges', 'revision' ), 'rev_text_id',
		array( 'rev_id = rc_this_oldid', "rc_timestamp < '20101225183000'"),  'purgeStaleMemcachedText',
		array( 'ORDER BY' => 'rc_timestamp DESC' ) );
	$latestReplicatedTextId -= 100; # A bit of paranoia

	echo "Going to purge text entries from $latestReplicatedTextId to $maxTextId in $wgDBname\n";

	for ( $i = $latestReplicatedTextId; $i < $maxTextId; $i++ ) {
		$keys = array();
		$keys[] = wfMemcKey( 'flaggedrevs', 'countPending', $i );
		$keys[] = wfMemcKey( 'flaggedrevs', 'includesSynced', $i );
		$keys[] = wfMemcKey( 'flaggedrevs', 'overrideRedirect', $i );
		$keys[] = wfMemcKey( 'unreviewedPages', 'underReview', $i );

		foreach ( $keys as $key ) {
			while (1) {
				if (! $wgMemc->delete( $key ) ) {
					echo "Memcache delete for $key returned false\n";
				}
				if ( $wgMemc->get( $key ) ) {
					echo "There's still content in $key!\n";
				} else {
					break;
				}
			}
		}
	}
}
コード例 #18
0
/**
 * 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 $wgMemc, $wgProxyMemcExpiry, $wgRequest;
    global $wgProxyKey;
    if (!$wgBlockOpenProxies) {
        return;
    }
    $ip = $wgRequest->getIP();
    # Get MemCached key
    $mcKey = wfMemcKey('proxy', 'ip', $ip);
    $mcValue = $wgMemc->get($mcKey);
    $skip = (bool) $mcValue;
    # Fork the processes
    if (!$skip) {
        $title = SpecialPage::getTitleFor('Blockme');
        $iphash = md5($ip . $wgProxyKey);
        $url = wfExpandUrl($title->getFullURL('ip=' . $iphash), PROTO_HTTP);
        foreach ($wgProxyPorts as $port) {
            $params = implode(' ', array(escapeshellarg($wgProxyScriptPath), escapeshellarg($ip), escapeshellarg($port), escapeshellarg($url)));
            exec("php {$params} >" . wfGetNull() . " 2>&1 &");
        }
        # Set MemCached key
        $wgMemc->set($mcKey, 1, $wgProxyMemcExpiry);
    }
}
コード例 #19
0
ファイル: QuizImport.php プロジェクト: biribogos/wikihow-src
 private function saveQuizAsBlob($name, $icon, $quiz)
 {
     if (empty($name) || empty($quiz)) {
         return;
     }
     $quiz_array = array('quiz_name' => $name, 'quiz_icon' => $icon, 'quiz_data' => json_encode($quiz), 'quiz_stamp' => wfTimestampNow());
     $dbr = wfGetDB(DB_SLAVE);
     $dbw = wfGetDB(DB_MASTER);
     //is that quiz already in there?
     $count = $dbr->selectField('quizzes', 'count(*) as count', array('quiz_name' => $name), __METHOD);
     if ($count > 0) {
         //it's there. update it...
         $res = $dbw->update('quizzes', $quiz_array, array('quiz_name' => $name), __METHOD__);
         self::$import_array[] = 'UPDATED: http://www.wikihow.com/Quiz/' . $name;
     } else {
         //brand spanking new (so to speak)
         $res = $dbw->insert('quizzes', $quiz_array, __METHOD__);
         self::$import_array[] = 'NEW: http://www.wikihow.com/Quiz/' . $name;
     }
     //delete any cached version of these exists just to be safe
     global $wgMemc;
     $memkey = wfMemcKey('quiz', $name);
     $wgMemc->delete($memkey);
     print 'QUIZ: ' . $name . "\n";
 }
 protected static function getMonthViews(Title $title)
 {
     global $wgMemc;
     $key = wfMemcKey('pvi', 'month', md5($title->getPrefixedText()));
     $data = $wgMemc->get($key);
     if ($data) {
         return $data;
     }
     $today = date('Ymd');
     $lastMonth = date('Ymd', time() - 60 * 60 * 24 * 30);
     $url = self::buildApiUrl($title, $lastMonth, $today);
     $req = MWHttpRequest::factory($url, ['timeout' => 10], __METHOD__);
     $status = $req->execute();
     if (!$status->isOK()) {
         LoggerFactory::getInstance('PageViewInfo')->error("Failed fetching {$url}: {$status->getWikiText()}", ['url' => $url, 'title' => $title->getPrefixedText()]);
         return false;
     }
     $data = FormatJson::decode($req->getContent(), true);
     // Add our start/end periods
     $data['start'] = $lastMonth;
     $data['end'] = $today;
     // Cache for an hour
     $wgMemc->set($key, $data, 60 * 60);
     return $data;
 }
コード例 #21
0
 public static function getBlackList()
 {
     $cache = \ObjectCache::getMainWANInstance();
     return $cache->getWithSetCallback(wfMemcKey('flowthread', 'spamblacklist'), 60, function () {
         return self::buildBlacklist();
     });
 }
コード例 #22
0
 /**
  * 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) {
             $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 = wfMemcKey('user', 'profile', 'system_gifts', "{$row2->stats_user_id}");
                     $wgMemc->delete($sg_key);
                     // Update counters (bug #27981)
                     UserSystemGifts::incGiftGivenCount($row->gift_id);
                     $wgOut->addHTML(wfMsg('ga-user-got-awards', $row2->stats_user_name, $row->gift_name) . '<br />');
                     $x++;
                 }
             }
         }
     }
     $wgOut->addHTML(wfMsgExt('ga-awards-given-out', 'parsemag', $x));
 }
コード例 #23
0
 /**
  *
  */
 public function getSimpleFormatForArticle(\Article $article)
 {
     $measurement = \Wikia\Measurements\Time::start([__CLASS__, __METHOD__]);
     $cacheKey = wfMemcKey("SimpleJson", $article->getPage()->getId(), self::SIMPLE_JSON_SCHEMA_VERSION);
     $jsonSimple = $this->app->wg->memc->get($cacheKey);
     if ($jsonSimple === false) {
         /**
          * Prevention from circular references, when parsing articles with tabs.
          *
          * E.g. when page contains tab, which is actually link to itself,
          * or if any tab contains tab, which referenced to given page.
          *
          * @see DivContainingHeadersVisitor::parseTabview
          */
         \Wikia\JsonFormat\HtmlParser::markAsVisited($article->getTitle()->getText());
         $jsonFormatRootNode = $this->getJsonFormatForArticle($article);
         // We have finished parsing of article, so we can clean array of visited articles
         \Wikia\JsonFormat\HtmlParser::clearVisited();
         $simplifier = new Wikia\JsonFormat\JsonFormatSimplifier();
         $jsonSimple = $simplifier->simplify($jsonFormatRootNode, $article->getTitle()->getText());
         $this->app->wg->memc->set($cacheKey, $jsonSimple, self::SIMPLE_JSON_CACHE_EXPIRATION);
     }
     $measurement->stop();
     return $jsonSimple;
 }
コード例 #24
0
ファイル: ApiQuery.php プロジェクト: seedbank/old-repo
 /**
  * @param $main ApiMain
  * @param $action string
  */
 public function __construct($main, $action)
 {
     parent::__construct($main, $action);
     // Allow custom modules to be added in LocalSettings.php
     global $wgAPIPropModules, $wgAPIListModules, $wgAPIMetaModules, $wgMemc, $wgAPICacheHelpTimeout;
     self::appendUserModules($this->mQueryPropModules, $wgAPIPropModules);
     self::appendUserModules($this->mQueryListModules, $wgAPIListModules);
     self::appendUserModules($this->mQueryMetaModules, $wgAPIMetaModules);
     $this->mPropModuleNames = array_keys($this->mQueryPropModules);
     $this->mListModuleNames = array_keys($this->mQueryListModules);
     $this->mMetaModuleNames = array_keys($this->mQueryMetaModules);
     // Get array of query generators from cache if present
     $key = wfMemcKey('apiquerygenerators', SpecialVersion::getVersion('nodb'));
     if ($wgAPICacheHelpTimeout > 0) {
         $cached = $wgMemc->get($key);
         if ($cached) {
             $this->mAllowedGenerators = $cached;
             return;
         }
     }
     $this->makeGeneratorList($this->mQueryPropModules);
     $this->makeGeneratorList($this->mQueryListModules);
     if ($wgAPICacheHelpTimeout > 0) {
         $wgMemc->set($key, $this->mAllowedGenerators, $wgAPICacheHelpTimeout);
     }
 }
コード例 #25
0
 /**
  * Gets the first time a user opened an edit page
  * @param $user User The User to check.
  * @return The timestamp of the first time the user opened an edit page.
  * false for an anonymous user, null for a user who has never opened an edit page.
  */
 public static function getFirstEditPage($user)
 {
     global $wgMemc;
     if (isset($user->mFirstEditPage)) {
         return $user->mFirstEditPage;
     }
     if ($user->isAnon()) {
         return false;
     }
     $cacheKey = wfMemcKey('first-edit-page', $user->getId());
     $cacheVal = $wgMemc->get($cacheKey);
     if ($cacheVal !== false) {
         $user->mFirstEditPage = $cacheVal;
         return $cacheVal;
     }
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('edit_page_tracking', 'ept_timestamp', array('ept_user' => $user->getID()), __METHOD__, array('ORDER BY' => 'ept_timestamp asc'));
     if ($dbr->numRows($res) == 0) {
         $user->mFirstEditPage = null;
         $wgMemc->set($cacheKey, null, 86400);
         return null;
     }
     $row = $dbr->fetchObject($res);
     $user->mFirstEditPage = wfTimestamp(TS_MW, $row->ept_timestamp);
     $wgMemc->set($cacheKey, $user->mFirstEditPage, 86400);
     return $user->mFirstEditPage;
 }
コード例 #26
0
ファイル: BlipTVVideo.php プロジェクト: Tjorriemorrie/app
 protected function extractVideoId($url)
 {
     global $wgMemc;
     // See if this is a valid url
     if (!preg_match('#/[a-zA-Z0-9\\-]+/[a-zA-Z0-9\\-]*-(\\d+)#', $url, $matches)) {
         return null;
     }
     $videoId = $matches[1];
     $cacheKey = wfMemcKey('video', 'bliptv', $videoId);
     $cachedEmbedId = $wgMemc->get($cacheKey);
     if ($cachedEmbedId !== false) {
         return $cachedEmbedId;
     }
     list($apiUrl) = explode('?', $url);
     $apiUrl .= '?skin=api';
     $apiContents = Http::get($apiUrl);
     if (empty($apiContents)) {
         return null;
     }
     $dom = new DOMDocument('1.0', 'UTF-8');
     $dom->loadXML($apiContents);
     $embedId = $dom->getElementsByTagName('embedLookup')->item(0)->textContent;
     $wgMemc->set($cacheKey, $embedId, 60 * 60 * 24);
     return $embedId;
 }
コード例 #27
0
 public function recordKeyword($keyword)
 {
     $keyword = strtolower($keyword);
     $memc = $this->app->wg->Memc;
     $cacheKey = wfMemcKey(self::CACHE_KEY);
     $data = $memc->get($cacheKey);
     if (empty($data)) {
         $data = $this->createData();
     } else {
         $data = json_decode($data);
     }
     $hash = 'K-' . md5($keyword);
     if (isset($data->keywords->{$hash})) {
         $data->keywords->{$hash}->c++;
         $data->keywords->{$hash}->ts = time();
     } else {
         $data->keywords->{$hash} = new stdClass();
         $data->keywords->{$hash}->c = 1;
         $data->keywords->{$hash}->k = $keyword;
         $data->keywords->{$hash}->ts = time();
     }
     $data->updateTs = time();
     //var_dump( json_encode( $data ) );
     //exit;
     $memc->set($cacheKey, json_encode($data), self::CACHE_TTL);
 }
コード例 #28
0
 function getPageWideStats($results)
 {
     global $wgMemc;
     wfProfileIn(__METHOD__);
     $key = wfMemcKey("rcbuddy_pagewidestats");
     $result = $wgMemc->get($key);
     if (is_array($result)) {
         wfProfileOut(__METHOD__);
         return array_merge($results, $result);
     }
     $dbr = wfGetDB(DB_SLAVE);
     $newstuff = array();
     $count = $dbr->selectField(array('recentchanges'), array('count(*) as c'), array('rc_patrolled=0'), __METHOD__);
     $newstuff['unpatrolled_total'] = $count;
     $t = gmdate("YmdHis", time() - 60 * 30);
     // thirty minutes ago
     $row = $dbr->selectRow(array('recentchanges'), array('count(distinct(rc_user)) as c'), array("rc_timestamp > {$t}", 'rc_user > 0'), __METHOD__);
     $count = $row->c;
     $newstuff['users_editing'] = $count;
     $nab_unpatrolled = Newarticleboost::getNABCount($dbr);
     $newstuff['nab_unpatrolled'] = $nab_unpatrolled;
     $wgMemc->set($key, $newstuff, 60);
     wfProfileOut(__METHOD__);
     return array_merge($newstuff, $results);
 }
コード例 #29
0
function wfSpecialYouTubeGetCategories() {
	global $wgMemc;
	$key = wfMemcKey('youtube', 'authsub', 'cats');
	$cats =  $wgMemc->get( $key );
	if (!$cats) {
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, "http://gdata.youtube.com/schemas/2007/categories.cat");
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_TIMEOUT, 4);
		$data =  curl_exec($ch);
		if (curl_errno($ch)) {
			print curl_error($ch);
		}
		else {
			curl_close($ch);
		}
		preg_match_all("/<atom:category term='([^']*)' label='([^']*)'>/", $data, $matches);
		$cats = "";
		for ($i = 0; $i < sizeof ($matches[1]) && $i < sizeof($matches[2]); $i++) {
			$cats .= "<OPTION VALUE='{$matches[1][$i]}'>{$matches[2][$i]}</OPTION>";
		}
		$wgMemc->set($key, $cats, 3600 * 24);
	}
	return $cats;
}
コード例 #30
0
 /**
  * get number of active threads (exclude deleted and removed threads)
  * @return integer activeThreads
  */
 public function getTotalActiveThreads($relatedPageId = 0, $db = DB_SLAVE)
 {
     wfProfileIn(__METHOD__);
     if (empty($relatedPageId)) {
         $memKey = wfMemcKey('forum_board_active_threads', $this->getId());
         if ($db == DB_SLAVE) {
             $activeThreads = $this->wg->Memc->get($memKey);
         }
     }
     if (!empty($relatedPageId) || $activeThreads === false) {
         $db = wfGetDB($db);
         if (!empty($relatedPageId)) {
             $filter = "comment_id in (select comment_id from wall_related_pages where page_id = {$relatedPageId})";
         } else {
             $filter = 'parent_page_id =' . (int) $this->getId();
         }
         $activeThreads = $db->selectField(array('comments_index'), array('count(*) cnt'), array($filter, 'parent_comment_id' => 0, 'deleted' => 0, 'removed' => 0, 'last_touched > curdate() - interval 7 day'), __METHOD__);
         $activeThreads = intval($activeThreads);
         if (empty($relatedPageId)) {
             $this->wg->Memc->set($memKey, $activeThreads, 60 * 60 * 12);
         }
     }
     wfProfileOut(__METHOD__);
     return $activeThreads;
 }