private static function getVariables() { ObjectCache::getInstance(); $site = Site::getInstance(); define('GUEST_ROLE_ID', (int) $site->getGuestRoleID()->getValue()); define('SITE_EMAIL', $site->getEmail()); define('SITE_TITLE', $site->getTitle()); date_default_timezone_set($site->getTimeZone()); if ($site->isInMaintenanceMode()) { if (!PermissionEngine::getInstance()->currentUserCanDo('bypasssMaintenanceMode')) { return; } } $blockEngine = BlockEngine::getInstance(); $user = CurrentUser::getUserSession(); $hookEngine = HookEngine::getInstance(); $router = Router::getInstance(); $hookEngine->runAction('addStaticRoutes'); $moduleInCharge = $router->whichModuleHandlesRequest(); $response = self::getResponse($moduleInCharge); http_response_code($response->getResponseCode()); $headers = $response->getHeaders(); foreach ($headers as $header => $value) { header($header . ": " . $value, true); } define('PAGE_TYPE', $response->getPageType()); $blocks = $blockEngine->getBlocks($site->getTheme(), PAGE_TYPE, $user->getRoleID()); if ($blocks === null) { $blocks = array(); } self::render($site, $response, $blocks); }
/** * Attempt to load a precomputed document tree for some given wikitext * from the cache. * * @param string $text * @param int $flags * @return PPNode_Hash_Tree|bool */ protected function cacheGetTree($text, $flags) { $config = RequestContext::getMain()->getConfig(); $length = strlen($text); $threshold = $config->get('PreprocessorCacheThreshold'); if ($threshold === false || $length < $threshold || $length > 1000000.0) { return false; } $cache = ObjectCache::getInstance($config->get('MainCacheType')); $key = wfMemcKey(defined('static::CACHE_PREFIX') ? static::CACHE_PREFIX : get_called_class(), md5($text), $flags); $value = $cache->get($key); if (!$value) { return false; } $version = intval(substr($value, 0, 8)); if ($version !== static::CACHE_VERSION) { return false; } LoggerFactory::getInstance('Preprocessor')->info("Loaded preprocessor output from cache (key: {$key})"); return substr($value, 8); }
private function buildMinifiedCSS() { $siteObject = Site::getInstance(); $minifiedSoFar = ""; $themesCssFiles = glob(EDUCASK_ROOT . "/site/themes/{$siteObject->getTheme()}/css/*.css"); foreach ($themesCssFiles as $cssFile) { if (!is_readable($cssFile)) { continue; } $rawFile = file_get_contents($cssFile); $rawFile = $this->minifyCssString($rawFile); $minifiedSoFar .= $rawFile; } $minifiedSoFar .= $this->getOtherCssFiles(); $minifiedSoFar .= $this->getRawCss(); $objectCache = ObjectCache::getInstance(); $objectCache->setObject('minifiedCSS', $minifiedSoFar, true); $response = Response::fiveHundred(); $response->setRawContent($minifiedSoFar); $response->setHeader('Content-Type', "text/css"); $response->setResponseCode(200); return $response; }
/** * @param array $options * - config: Config to fetch configuration from. Defaults to the default 'main' config. * - logger: LoggerInterface to use for logging. Defaults to the 'session' channel. * - store: BagOStuff to store session data in. */ public function __construct($options = array()) { if (isset($options['config'])) { $this->config = $options['config']; if (!$this->config instanceof Config) { throw new \InvalidArgumentException('$options[\'config\'] must be an instance of Config'); } } else { $this->config = \ConfigFactory::getDefaultInstance()->makeConfig('main'); } if (isset($options['logger'])) { if (!$options['logger'] instanceof LoggerInterface) { throw new \InvalidArgumentException('$options[\'logger\'] must be an instance of LoggerInterface'); } $this->setLogger($options['logger']); } else { $this->setLogger(\MediaWiki\Logger\LoggerFactory::getInstance('session')); } if (isset($options['store'])) { if (!$options['store'] instanceof BagOStuff) { throw new \InvalidArgumentException('$options[\'store\'] must be an instance of BagOStuff'); } $this->store = $options['store']; } else { $this->store = \ObjectCache::getInstance($this->config->get('SessionCacheType')); $this->store->setLogger($this->logger); } register_shutdown_function(array($this, 'shutdown')); }
/** * Load conversion tables either from the cache or the disk. * @private * @param bool $fromCache Load from memcached? Defaults to true. */ function loadTables($fromCache = true) { global $wgLanguageConverterCacheType; if ($this->mTablesLoaded) { return; } $this->mTablesLoaded = true; $this->mTables = false; $cache = ObjectCache::getInstance($wgLanguageConverterCacheType); if ($fromCache) { wfProfileIn(__METHOD__ . '-cache'); $this->mTables = $cache->get($this->mCacheKey); wfProfileOut(__METHOD__ . '-cache'); } if (!$this->mTables || !array_key_exists(self::CACHE_VERSION_KEY, $this->mTables)) { wfProfileIn(__METHOD__ . '-recache'); // not in cache, or we need a fresh reload. // We will first load the default tables // then update them using things in MediaWiki:Conversiontable/* $this->loadDefaultTables(); foreach ($this->mVariants as $var) { $cached = $this->parseCachedTable($var); $this->mTables[$var]->mergeArray($cached); } $this->postLoadTables(); $this->mTables[self::CACHE_VERSION_KEY] = true; $cache->set($this->mCacheKey, $this->mTables, 43200); wfProfileOut(__METHOD__ . '-recache'); } }
/** * Get the cache object used by the parser cache * * @return BagOStuff */ function wfGetParserCacheStorage() { global $wgParserCacheType; return ObjectCache::getInstance($wgParserCacheType); }
} else { $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n"; if ($wgDebugPrintHttpHeaders) { $debug .= "HTTP HEADERS:\n"; foreach ($wgRequest->getAllHeaders() as $name => $value) { $debug .= "{$name}: {$value}\n"; } } wfDebug($debug); } Profiler::instance()->scopedProfileOut($ps_misc); $ps_memcached = Profiler::instance()->scopedProfileIn($fname . '-memcached'); $wgMemc = wfGetMainCache(); $messageMemc = wfGetMessageCacheStorage(); $parserMemc = wfGetParserCacheStorage(); wfDebugLog('caches', 'cluster: ' . get_class($wgMemc) . ', WAN: ' . ($wgMainWANCache === CACHE_NONE ? 'CACHE_NONE' : $wgMainWANCache) . ', stash: ' . $wgMainStash . ', message: ' . get_class($messageMemc) . ', parser: ' . get_class($parserMemc) . ', session: ' . get_class(ObjectCache::getInstance($wgSessionCacheType))); Profiler::instance()->scopedProfileOut($ps_memcached); // Most of the config is out, some might want to run hooks here. Hooks::run('SetupAfterCache'); $ps_globals = Profiler::instance()->scopedProfileIn($fname . '-globals'); /** * @var Language $wgContLang */ $wgContLang = Language::factory($wgLanguageCode); $wgContLang->initContLang(); // Now that variant lists may be available... $wgRequest->interpolateTitle(); if (!is_object($wgAuth)) { $wgAuth = new MediaWiki\Auth\AuthManagerAuthPlugin(); Hooks::run('AuthPluginSetup', [&$wgAuth]); }
/** * Get the cache storage object to use for session storage */ static function getCache() { global $wgSessionCacheType; return ObjectCache::getInstance($wgSessionCacheType); }
public function execute() { $params = $this->extractRequestParams(); $title = Title::newFromText($params['title']); if (!$title) { $this->dieUsageMsg(array('invalidtitle', $params['title'])); } if ($params['session']) { $sessionId = $params['session']; } else { $sessionId = mt_rand(0, 0x7fffffff); } global $wgUser; $sessionKey = wfMemcKey('scribunto-console', $wgUser->getId(), $sessionId); $cache = ObjectCache::getInstance(CACHE_ANYTHING); $session = null; $sessionIsNew = false; if ($params['session']) { $session = $cache->get($sessionKey); } if (!isset($session['version'])) { $session = $this->newSession(); $sessionIsNew = true; } // Create a variable holding the session which will be stored if there // are no errors. If there are errors, we don't want to store the current // question to the state builder array, since that will cause subsequent // requests to fail. $newSession = $session; if (!empty($params['clear'])) { $newSession['size'] -= strlen(implode('', $newSession['questions'])); $newSession['questions'] = array(); $session['questions'] = array(); } if (strlen($params['question'])) { $newSession['size'] += strlen($params['question']); $newSession['questions'][] = $params['question']; } if ($params['content']) { $newSession['size'] += strlen($params['content']) - strlen($newSession['content']); $newSession['content'] = $params['content']; } if ($newSession['size'] > self::SC_MAX_SIZE) { $this->dieUsage($this->msg('scribunto-console-too-large')->text(), 'scribunto-console-too-large'); } $result = $this->runConsole(array('title' => $title, 'content' => $newSession['content'], 'prevQuestions' => $session['questions'], 'question' => $params['question'])); if ($result['type'] === 'error') { // Restore the questions array $newSession['questions'] = $session['questions']; } $cache->set($sessionKey, $newSession, self::SC_SESSION_EXPIRY); $result['session'] = $sessionId; $result['sessionSize'] = $newSession['size']; $result['sessionMaxSize'] = self::SC_MAX_SIZE; if ($sessionIsNew) { $result['sessionIsNew'] = ''; } foreach ($result as $key => $value) { $this->getResult()->addValue(null, $key, $value); } }
/** * Get the cache object used by the language converter * * @return BagOStuff */ function wfGetLangConverterCacheStorage() { global $wgLanguageConverterCacheType; return ObjectCache::getInstance($wgLanguageConverterCacheType); }
private static function setInstance(Site $object) { self::$instance = $object; $objectCache = ObjectCache::getInstance(); $objectCache->setEncryptedObject("EducaskSiteObject", $object, true); }
$wgDebugLogFile = ''; } // Backwards compatibility with old password limits if ($wgMinimalPasswordLength !== false) { $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength; } if ($wgMaximalPasswordLength !== false) { $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength; } // Backwards compatibility warning if (!$wgSessionsInObjectCache && !$wgSessionsInMemcached) { wfDeprecated('$wgSessionsInObjectCache = false', '1.27'); if ($wgSessionHandler) { wfDeprecated('$wgSessionsHandler', '1.27'); } $cacheType = get_class(ObjectCache::getInstance($wgSessionCacheType)); wfDebugLog("Session data will be stored in \"{$cacheType}\" cache with " . "expiry {$wgObjectCacheSessionExpiry} seconds"); } $wgSessionsInObjectCache = true; if ($wgPHPSessionHandling !== 'enable' && $wgPHPSessionHandling !== 'warn' && $wgPHPSessionHandling !== 'disable') { $wgPHPSessionHandling = 'warn'; } Profiler::instance()->scopedProfileOut($ps_default); // Disable MWDebug for command line mode, this prevents MWDebug from eating up // all the memory from logging SQL queries on maintenance scripts global $wgCommandLineMode; if ($wgDebugToolbar && !$wgCommandLineMode) { MWDebug::init(); } if (!class_exists('AutoLoader')) { require_once "{$IP}/includes/AutoLoader.php";
/** * Constructor, always call this from child classes. */ public function __construct() { global $wgMemc, $wgUser, $wgObjectCaches; $defaultConfig = new GlobalVarConfig(); // all the stuff from DefaultSettings.php $installerConfig = self::getInstallerConfig($defaultConfig); // Reset all services and inject config overrides MediaWiki\MediaWikiServices::resetGlobalInstance($installerConfig); // Don't attempt to load user language options (T126177) // This will be overridden in the web installer with the user-specified language RequestContext::getMain()->setLanguage('en'); // Disable the i18n cache // TODO: manage LocalisationCache singleton in MediaWikiServices Language::getLocalisationCache()->disableBackend(); // Disable all global services, since we don't have any configuration yet! MediaWiki\MediaWikiServices::disableStorageBackend(); // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and // SqlBagOStuff will then throw since we just disabled wfGetDB) $wgObjectCaches = MediaWikiServices::getInstance()->getMainConfig()->get('ObjectCaches'); $wgMemc = ObjectCache::getInstance(CACHE_NONE); // Having a user with id = 0 safeguards us from DB access via User::loadOptions(). $wgUser = User::newFromId(0); RequestContext::getMain()->setUser($wgUser); $this->settings = $this->internalDefaults; foreach ($this->defaultVarNames as $var) { $this->settings[$var] = $GLOBALS[$var]; } $this->doEnvironmentPreps(); $this->compiledDBs = []; foreach (self::getDBTypes() as $type) { $installer = $this->getDBInstaller($type); if (!$installer->isCompiled()) { continue; } $this->compiledDBs[] = $type; } $this->parserTitle = Title::newFromText('Installer'); $this->parserOptions = new ParserOptions($wgUser); // language will be wrong :( $this->parserOptions->setEditSection(false); }
/** * Prepares testing environment. */ protected function setUp() { $this->cache = ObjectCache::getInstance(); }