/** * @since 1.21 * @deprecated 1.25 Construct a SiteStore instance directly instead. * * @param ORMTable|null $sitesTable * @param BagOStuff|null $cache * * @return SiteStore */ public static function newInstance(ORMTable $sitesTable = null, BagOStuff $cache = null) { if ($cache === null) { $cache = wfGetCache(wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING); } $siteStore = new DBSiteStore(); return new static($siteStore, $cache); }
/** * Returns true if uploads are enabled. * Can be override by subclasses. * @return bool */ public static function isEnabled() { global $wgEnableUploads; if (!$wgEnableUploads) { return false; } # Check php's file_uploads setting return wfIsHHVM() || wfIniGetBool('file_uploads'); }
/** * Determine if there is a usable tidy. */ public function __construct($useConfiguration = false) { global $IP, $wgUseTidy, $wgTidyBin, $wgTidyInternal, $wgTidyConfig, $wgTidyConf, $wgTidyOpts; $this->enabled = true; if ($useConfiguration) { if ($wgTidyConfig !== null) { $this->config = $wgTidyConfig; } elseif ($wgUseTidy) { $this->config = ['tidyConfigFile' => $wgTidyConf, 'debugComment' => false, 'tidyBin' => $wgTidyBin, 'tidyCommandLine' => $wgTidyOpts]; if ($wgTidyInternal) { $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP'; } else { $this->config['driver'] = 'RaggettExternal'; } } else { $this->enabled = false; } } else { $this->config = ['tidyConfigFile' => "{$IP}/includes/tidy/tidy.conf", 'tidyCommandLine' => '']; if (extension_loaded('tidy') && class_exists('tidy')) { $this->config['driver'] = wfIsHHVM() ? 'RaggettInternalHHVM' : 'RaggettInternalPHP'; } else { if (is_executable($wgTidyBin)) { $this->config['driver'] = 'RaggettExternal'; $this->config['tidyBin'] = $wgTidyBin; } else { $path = Installer::locateExecutableInDefaultPaths($wgTidyBin); if ($path !== false) { $this->config['driver'] = 'RaggettExternal'; $this->config['tidyBin'] = $wgTidyBin; } else { $this->enabled = false; } } } } if (!$this->enabled) { $this->config = ['driver' => 'disabled']; } }
protected static function singleton() { global $wgUseTidy, $wgTidyInternal, $wgTidyConf, $wgDebugTidy, $wgTidyConfig, $wgTidyBin, $wgTidyOpts; if (self::$instance === null) { if ($wgTidyConfig !== null) { $config = $wgTidyConfig; } elseif ($wgUseTidy) { // b/c configuration $config = array('tidyConfigFile' => $wgTidyConf, 'debugComment' => $wgDebugTidy, 'tidyBin' => $wgTidyBin, 'tidyCommandLine' => $wgTidyOpts); if ($wgTidyInternal) { if (wfIsHHVM()) { $config['driver'] = 'RaggettInternalHHVM'; } else { $config['driver'] = 'RaggettInternalPHP'; } } else { $config['driver'] = 'RaggettExternal'; } } else { return false; } switch ($config['driver']) { case 'RaggettInternalHHVM': self::$instance = new MediaWiki\Tidy\RaggettInternalHHVM($config); break; case 'RaggettInternalPHP': self::$instance = new MediaWiki\Tidy\RaggettInternalPHP($config); break; case 'RaggettExternal': self::$instance = new MediaWiki\Tidy\RaggettExternal($config); break; case 'Html5Depurate': self::$instance = new MediaWiki\Tidy\Html5Depurate($config); break; default: throw new MWException("Invalid tidy driver: \"{$config['driver']}\""); } } return self::$instance; }
/** * Returns the HTML to add to the page for the toolbar * * @param IContextSource $context * @return array */ public static function getDebugInfo(IContextSource $context) { if (!self::$enabled) { return array(); } global $wgVersion, $wgRequestTime; $request = $context->getRequest(); // HHVM's reported memory usage from memory_get_peak_usage() // is not useful when passing false, but we continue passing // false for consistency of historical data in zend. // see: https://github.com/facebook/hhvm/issues/2257#issuecomment-39362246 $realMemoryUsage = wfIsHHVM(); return array('mwVersion' => $wgVersion, 'phpEngine' => wfIsHHVM() ? 'HHVM' : 'PHP', 'phpVersion' => wfIsHHVM() ? HHVM_VERSION : PHP_VERSION, 'gitRevision' => GitInfo::headSHA1(), 'gitBranch' => GitInfo::currentBranch(), 'gitViewUrl' => GitInfo::headViewUrl(), 'time' => microtime(true) - $wgRequestTime, 'log' => self::$log, 'debugLog' => self::$debug, 'queries' => self::$query, 'request' => array('method' => $request->getMethod(), 'url' => $request->getRequestURL(), 'headers' => $request->getAllHeaders(), 'params' => $request->getValues()), 'memory' => $context->getLanguage()->formatSize(memory_get_usage($realMemoryUsage)), 'memoryPeak' => $context->getLanguage()->formatSize(memory_get_peak_usage($realMemoryUsage)), 'includes' => self::getFilesIncluded($context)); }
} $e = null; // PHP exception while (($line = Maintenance::readconsole()) !== false) { if ($e && !preg_match('/^(exit|die);?$/', $line)) { // Internal state may be corrupted or fatals may occur later due // to some object not being set. Don't drop out of eval in case // lines were being pasted in (which would then get dumped to the shell). // Instead, just absorb the remaning commands. Let "exit" through per DWIM. echo "Exception was thrown before; please restart eval.php\n"; continue; } if ($useReadline) { readline_add_history($line); readline_write_history($historyFile); } try { $val = eval($line . ";"); } catch (Exception $e) { echo "Caught exception " . get_class($e) . ": {$e->getMessage()}\n" . $e->getTraceAsString() . "\n"; continue; } if (wfIsHHVM() || is_null($val)) { echo "\n"; } elseif (is_string($val) || is_numeric($val)) { echo "{$val}\n"; } else { var_dump($val); } } print "\n";
/** * Use the HTML tidy extension to use the tidy library in-process, * saving the overhead of spawning a new process. * * @param string $text HTML to check * @param bool $stderr Whether to read result from error status instead of output * @param int &$retval Exit code (-1 on internal error) * @return string|null */ private static function phpClean($text, $stderr = false, &$retval = null) { global $wgTidyConf, $wgDebugTidy; if (!wfIsHHVM() && !class_exists('tidy') || wfIsHHVM() && !function_exists('tidy_repair_string')) { wfWarn("Unable to load internal tidy class."); $retval = -1; return null; } $tidy = new tidy(); $tidy->parseString($text, $wgTidyConf, 'utf8'); if ($stderr) { $retval = $tidy->getStatus(); return $tidy->errorBuffer; } $tidy->cleanRepair(); $retval = $tidy->getStatus(); if ($retval == 2) { // 2 is magic number for fatal error // http://www.php.net/manual/en/function.tidy-get-status.php $cleansource = null; } else { $cleansource = tidy_get_output($tidy); if ($wgDebugTidy && $retval > 0) { $cleansource .= "<!--\nTidy reports:\n" . str_replace('-->', '-->', $tidy->errorBuffer) . "\n-->"; } } return $cleansource; }
/** * Returns wiki text showing the third party software versions (apache, php, mysql). * * @return string */ public static function softwareInformation() { $dbr = wfGetDB(DB_REPLICA); // Put the software in an array of form 'name' => 'version'. All messages should // be loaded here, so feel free to use wfMessage in the 'name'. Raw HTML or // wikimarkup can be used. $software = []; $software['[https://www.mediawiki.org/ MediaWiki]'] = self::getVersionLinked(); if (wfIsHHVM()) { $software['[http://hhvm.com/ HHVM]'] = HHVM_VERSION . " (" . PHP_SAPI . ")"; } else { $software['[https://php.net/ PHP]'] = PHP_VERSION . " (" . PHP_SAPI . ")"; } $software[$dbr->getSoftwareLink()] = $dbr->getServerInfo(); if (IcuCollation::getICUVersion()) { $software['[http://site.icu-project.org/ ICU]'] = IcuCollation::getICUVersion(); } // Allow a hook to add/remove items. Hooks::run('SoftwareInfo', [&$software]); $out = Xml::element('h2', ['id' => 'mw-version-software'], wfMessage('version-software')->text()) . Xml::openElement('table', ['class' => 'wikitable plainlinks', 'id' => 'sv-software']) . "<tr>\n\t\t\t\t\t<th>" . wfMessage('version-software-product')->text() . "</th>\n\t\t\t\t\t<th>" . wfMessage('version-software-version')->text() . "</th>\n\t\t\t\t</tr>\n"; foreach ($software as $name => $version) { $out .= "<tr>\n\t\t\t\t\t<td>" . $name . "</td>\n\t\t\t\t\t<td dir=\"ltr\">" . $version . "</td>\n\t\t\t\t</tr>\n"; } return $out . Xml::closeElement('table'); }
/** * Do initial checks of the PHP environment. Set variables according to * the observed environment. * * It's possible that this may be called under the CLI SAPI, not the SAPI * that the wiki will primarily run under. In that case, the subclass should * initialise variables such as wgScriptPath, before calling this function. * * Under the web subclass, it can already be assumed that PHP 5+ is in use * and that sessions are working. * * @return Status */ public function doEnvironmentChecks() { // Php version has already been checked by entry scripts // Show message here for information purposes if (wfIsHHVM()) { $this->showMessage('config-env-hhvm', HHVM_VERSION); } else { $this->showMessage('config-env-php', PHP_VERSION); } $good = true; // Must go here because an old version of PCRE can prevent other checks from completing list($pcreVersion) = explode(' ', PCRE_VERSION, 2); if (version_compare($pcreVersion, self::MINIMUM_PCRE_VERSION, '<')) { $this->showError('config-pcre-old', self::MINIMUM_PCRE_VERSION, $pcreVersion); $good = false; } else { foreach ($this->envChecks as $check) { $status = $this->{$check}(); if ($status === false) { $good = false; } } } $this->setVar('_Environment', $good); return $good ? Status::newGood() : Status::newFatal('config-env-bad'); }
/** * Execute a shell command, with time and memory limits mirrored from the PHP * configuration if supported. * @param string $cmd Command line, properly escaped for shell. * @param &$retval null|Mixed optional, will receive the program's exit code. * (non-zero is usually failure). If there is an error from * read, select, or proc_open(), this will be set to -1. * @param array $environ optional environment variables which should be * added to the executed command environment. * @param array $limits optional array with limits(filesize, memory, time, walltime) * this overwrites the global wgMaxShell* limits. * @param array $options Array of options: * - duplicateStderr: Set this to true to duplicate stderr to stdout, * including errors from limit.sh * * @return string collected stdout as a string */ function wfShellExec($cmd, &$retval = null, $environ = array(), $limits = array(), $options = array()) { global $IP, $wgMaxShellMemory, $wgMaxShellFileSize, $wgMaxShellTime, $wgMaxShellWallClockTime, $wgShellCgroup; $disabled = wfShellExecDisabled(); if ($disabled) { $retval = 1; return $disabled == 'safemode' ? 'Unable to run external programs in safe mode.' : 'Unable to run external programs, proc_open() is disabled.'; } $includeStderr = isset($options['duplicateStderr']) && $options['duplicateStderr']; wfInitShellLocale(); $envcmd = ''; foreach ($environ as $k => $v) { if (wfIsWindows()) { /* Surrounding a set in quotes (method used by wfEscapeShellArg) makes the quotes themselves * appear in the environment variable, so we must use carat escaping as documented in * http://technet.microsoft.com/en-us/library/cc723564.aspx * Note however that the quote isn't listed there, but is needed, and the parentheses * are listed there but doesn't appear to need it. */ $envcmd .= "set {$k}=" . preg_replace('/([&|()<>^"])/', '^\\1', $v) . '&& '; } else { /* Assume this is a POSIX shell, thus required to accept variable assignments before the command * http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_09_01 */ $envcmd .= "{$k}=" . escapeshellarg($v) . ' '; } } $cmd = $envcmd . $cmd; $useLogPipe = false; if (php_uname('s') == 'Linux') { $time = intval(isset($limits['time']) ? $limits['time'] : $wgMaxShellTime); if (isset($limits['walltime'])) { $wallTime = intval($limits['walltime']); } elseif (isset($limits['time'])) { $wallTime = $time; } else { $wallTime = intval($wgMaxShellWallClockTime); } $mem = intval(isset($limits['memory']) ? $limits['memory'] : $wgMaxShellMemory); $filesize = intval(isset($limits['filesize']) ? $limits['filesize'] : $wgMaxShellFileSize); if ($time > 0 || $mem > 0 || $filesize > 0 || $wallTime > 0) { $cmd = '/bin/bash ' . escapeshellarg("{$IP}/includes/limit.sh") . ' ' . escapeshellarg($cmd) . ' ' . escapeshellarg("MW_INCLUDE_STDERR=" . ($includeStderr ? '1' : '') . ';' . "MW_CPU_LIMIT={$time}; " . 'MW_CGROUP=' . escapeshellarg($wgShellCgroup) . '; ' . "MW_MEM_LIMIT={$mem}; " . "MW_FILE_SIZE_LIMIT={$filesize}; " . "MW_WALL_CLOCK_LIMIT={$wallTime}; " . "MW_USE_LOG_PIPE=yes"); $useLogPipe = true; } elseif ($includeStderr) { $cmd .= ' 2>&1'; } } elseif ($includeStderr) { $cmd .= ' 2>&1'; } wfDebug("wfShellExec: {$cmd}\n"); $desc = array(0 => array('file', 'php://stdin', 'r'), 1 => array('pipe', 'w'), 2 => array('file', 'php://stderr', 'w')); if ($useLogPipe) { $desc[3] = array('pipe', 'w'); } # TODO/FIXME: This is a bad hack to workaround an HHVM bug that prevents # proc_open() from opening stdin/stdout, so use /dev/null *for now* # See bug 56597 / https://github.com/facebook/hhvm/issues/1247 for more info if (wfIsHHVM()) { $desc[0] = array('file', '/dev/null', 'r'); $desc[2] = array('file', '/dev/null', 'w'); } $pipes = null; $proc = proc_open($cmd, $desc, $pipes); if (!$proc) { wfDebugLog('exec', "proc_open() failed: {$cmd}"); $retval = -1; return ''; } $outBuffer = $logBuffer = ''; $emptyArray = array(); $status = false; $logMsg = false; // According to the documentation, it is possible for stream_select() // to fail due to EINTR. I haven't managed to induce this in testing // despite sending various signals. If it did happen, the error // message would take the form: // // stream_select(): unable to select [4]: Interrupted system call (max_fd=5) // // where [4] is the value of the macro EINTR and "Interrupted system // call" is string which according to the Linux manual is "possibly" // localised according to LC_MESSAGES. $eintr = defined('SOCKET_EINTR') ? SOCKET_EINTR : 4; $eintrMessage = "stream_select(): unable to select [{$eintr}]"; // Build a table mapping resource IDs to pipe FDs to work around a // PHP 5.3 issue in which stream_select() does not preserve array keys // <https://bugs.php.net/bug.php?id=53427>. $fds = array(); foreach ($pipes as $fd => $pipe) { $fds[(int) $pipe] = $fd; } while (true) { $status = proc_get_status($proc); if (!$status['running']) { break; } $status = false; $readyPipes = $pipes; // Clear last error @trigger_error(''); if (@stream_select($readyPipes, $emptyArray, $emptyArray, null) === false) { $error = error_get_last(); if (strncmp($error['message'], $eintrMessage, strlen($eintrMessage)) == 0) { continue; } else { trigger_error($error['message'], E_USER_WARNING); $logMsg = $error['message']; break; } } foreach ($readyPipes as $pipe) { $block = fread($pipe, 65536); $fd = $fds[(int) $pipe]; if ($block === '') { // End of file fclose($pipes[$fd]); unset($pipes[$fd]); if (!$pipes) { break 2; } } elseif ($block === false) { // Read error $logMsg = "Error reading from pipe"; break 2; } elseif ($fd == 1) { // From stdout $outBuffer .= $block; } elseif ($fd == 3) { // From log FD $logBuffer .= $block; if (strpos($block, "\n") !== false) { $lines = explode("\n", $logBuffer); $logBuffer = array_pop($lines); foreach ($lines as $line) { wfDebugLog('exec', $line); } } } } } foreach ($pipes as $pipe) { fclose($pipe); } // Use the status previously collected if possible, since proc_get_status() // just calls waitpid() which will not return anything useful the second time. if ($status === false) { $status = proc_get_status($proc); } if ($logMsg !== false) { // Read/select error $retval = -1; proc_close($proc); } elseif ($status['signaled']) { $logMsg = "Exited with signal {$status['termsig']}"; $retval = 128 + $status['termsig']; proc_close($proc); } else { if ($status['running']) { $retval = proc_close($proc); } else { $retval = $status['exitcode']; proc_close($proc); } if ($retval == 127) { $logMsg = "Possibly missing executable file"; } elseif ($retval >= 129 && $retval <= 192) { $logMsg = "Probably exited with signal " . ($retval - 128); } } if ($logMsg !== false) { wfDebugLog('exec', "{$logMsg}: {$cmd}"); } return $outBuffer; }
* Thiswas sourced from TranslateWiki (https://github.com/wikimedia/translatewiki/blob/0b7ba4665ab3e599516d2c2774e2541495a9d7a4/TranslatewikiSettings.php#L478) */ $wgHooks['GetBetaFeaturePreferences'][] = function ($user, &$prefs) { $prefs['hhvm-beta'] = array('label-message' => 'hhvm-beta-label', 'desc-message' => 'hhvm-beta-desc', 'info-link' => 'http://www.hhvm.com/', 'discussion-link' => 'https://meta.orain.org/wiki/Forum:HHVM'); }; $wgHooks['BeforePageDisplay'][] = function (OutputPage $out) { $req = $out->getRequest(); $user = $out->getUser(); $hasCookie = $req->getCookie('hhvm', ''); $wantsCookie = BetaFeatures::isFeatureEnabled($user, 'hhvm-beta'); if (!$hasCookie && $wantsCookie) { $req->response()->setcookie('hhvm', '1', 0, array('prefix' => '')); } if ($hasCookie && !$wantsCookie) { $req->response()->setcookie('hhvm', '0', -1, array('prefix' => '')); } }; $wgHooks['RecentChange_save'][] = function (RecentChange $rc) { if (wfIsHHVM()) { ChangeTags::addTags('HHVM', $rc->getAttribute('rc_id')); } return true; }; $wgHooks['LocalisationCacheRecache'][] = function ($cache, $code, &$cachedData) { if ($code === 'en') { $cachedData['messages']['hhvm-beta-label'] = 'HHVM'; $cachedData['messages']['hhvm-beta-desc'] = 'HHVM is a new and faster PHP runtime.'; $cachedData['messages']['tag-HHVM'] = '[[m:Forum:HHVM|HHVM]]'; $cachedData['messages']['tag-HHVM-description'] = 'Changes made using HHVM. These are tagged for analysis purposes'; } };
return ['DBLoadBalancerFactory' => function (MediaWikiServices $services) { $config = $services->getMainConfig()->get('LBFactoryConf'); $class = LBFactory::getLBFactoryClass($config); if (!isset($config['readOnlyReason'])) { // TODO: replace the global wfConfiguredReadOnlyReason() with a service. $config['readOnlyReason'] = wfConfiguredReadOnlyReason(); } return new $class($config); }, 'DBLoadBalancer' => function (MediaWikiServices $services) { // just return the default LB from the DBLoadBalancerFactory service return $services->getDBLoadBalancerFactory()->getMainLB(); }, 'SiteStore' => function (MediaWikiServices $services) { $rawSiteStore = new DBSiteStore($services->getDBLoadBalancer()); // TODO: replace wfGetCache with a CacheFactory service. // TODO: replace wfIsHHVM with a capabilities service. $cache = wfGetCache(wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING); return new CachingSiteStore($rawSiteStore, $cache); }, 'SiteLookup' => function (MediaWikiServices $services) { // Use the default SiteStore as the SiteLookup implementation for now return $services->getSiteStore(); }, 'ConfigFactory' => function (MediaWikiServices $services) { // Use the bootstrap config to initialize the ConfigFactory. $registry = $services->getBootstrapConfig()->get('ConfigRegistry'); $factory = new ConfigFactory(); foreach ($registry as $name => $callback) { $factory->register($name, $callback); } return $factory; }, 'MainConfig' => function (MediaWikiServices $services) { // Use the 'main' config from the ConfigFactory service. return $services->getConfigFactory()->makeConfig('main');
/** * Run JavaScript or CSS data through a filter, caching the filtered result for future calls. * * Available filters are: * * - minify-js \see JavaScriptMinifier::minify * - minify-css \see CSSMin::minify * * If $data is empty, only contains whitespace or the filter was unknown, * $data is returned unmodified. * * @param string $filter Name of filter to run * @param string $data Text to filter, such as JavaScript or CSS text * @param array $options For back-compat, can also be the boolean value for "cacheReport". Keys: * - (bool) cache: Whether to allow caching this data. Default: true. * - (bool) cacheReport: Whether to include the "cache key" report comment. Default: true. * @return string Filtered data, or a comment containing an error message */ public function filter($filter, $data, $options = array()) { // Back-compat if (is_bool($options)) { $options = array('cacheReport' => $options); } // Defaults $options += array('cache' => true, 'cacheReport' => true); // Don't filter empty content if (trim($data) === '') { return $data; } if (!in_array($filter, array('minify-js', 'minify-css'))) { $this->logger->warning('Invalid filter {filter}', array('filter' => $filter)); return $data; } if (!$options['cache']) { $result = $this->applyFilter($filter, $data); } else { $key = wfMemcKey('resourceloader', 'filter', $filter, self::$filterCacheVersion, md5($data)); $cache = wfGetCache(wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING); $cacheEntry = $cache->get($key); if (is_string($cacheEntry)) { wfIncrStats("resourceloader_cache.{$filter}.hit"); return $cacheEntry; } $result = ''; try { wfIncrStats("resourceloader_cache.{$filter}.miss"); $result = $this->applyFilter($filter, $data); if ($options['cacheReport']) { $result .= "\n/* cache key: {$key} */"; } $cache->set($key, $result); } catch (Exception $e) { MWExceptionHandler::logException($e); $this->logger->warning('Minification failed: {exception}', array('exception' => $e)); $this->errors[] = self::formatExceptionNoComment($e); } } return $result; }
public function __construct() { $this->worker = new SitesModuleWorker(Settings::singleton(), SiteSQLStore::newInstance(), wfGetCache(wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING)); }
/** * Get the descriptor of the fieldset that contains the file source * selection. The section is 'source' * * @return array Descriptor array */ protected function getSourceSection() { if ($this->mSessionKey) { return array('SessionKey' => array('type' => 'hidden', 'default' => $this->mSessionKey), 'SourceType' => array('type' => 'hidden', 'default' => 'Stash')); } $canUploadByUrl = UploadFromUrl::isEnabled() && UploadFromUrl::isAllowed($this->getUser()) === true && $this->getConfig()->get('CopyUploadsFromSpecialUpload'); $radio = $canUploadByUrl; $selectedSourceType = strtolower($this->getRequest()->getText('wpSourceType', 'File')); $descriptor = array(); if ($this->mTextTop) { $descriptor['UploadFormTextTop'] = array('type' => 'info', 'section' => 'source', 'default' => $this->mTextTop, 'raw' => true); } $this->mMaxUploadSize['file'] = UploadBase::getMaxUploadSize('file'); # Limit to upload_max_filesize unless we are running under HipHop and # that setting doesn't exist if (!wfIsHHVM()) { $this->mMaxUploadSize['file'] = min($this->mMaxUploadSize['file'], wfShorthandToInteger(ini_get('upload_max_filesize')), wfShorthandToInteger(ini_get('post_max_size'))); } $help = $this->msg('upload-maxfilesize', $this->getContext()->getLanguage()->formatSize($this->mMaxUploadSize['file']))->parse(); // If the user can also upload by URL, there are 2 different file size limits. // This extra message helps stress which limit corresponds to what. if ($canUploadByUrl) { $help .= $this->msg('word-separator')->escaped(); $help .= $this->msg('upload_source_file')->parse(); } $descriptor['UploadFile'] = array('class' => 'UploadSourceField', 'section' => 'source', 'type' => 'file', 'id' => 'wpUploadFile', 'radio-id' => 'wpSourceTypeFile', 'label-message' => 'sourcefilename', 'upload-type' => 'File', 'radio' => &$radio, 'help' => $help, 'checked' => $selectedSourceType == 'file'); if ($canUploadByUrl) { $this->mMaxUploadSize['url'] = UploadBase::getMaxUploadSize('url'); $descriptor['UploadFileURL'] = array('class' => 'UploadSourceField', 'section' => 'source', 'id' => 'wpUploadFileURL', 'radio-id' => 'wpSourceTypeurl', 'label-message' => 'sourceurl', 'upload-type' => 'url', 'radio' => &$radio, 'help' => $this->msg('upload-maxfilesize', $this->getContext()->getLanguage()->formatSize($this->mMaxUploadSize['url']))->parse() . $this->msg('word-separator')->escaped() . $this->msg('upload_source_url')->parse(), 'checked' => $selectedSourceType == 'url'); } Hooks::run('UploadFormSourceDescriptors', array(&$descriptor, &$radio, $selectedSourceType)); $descriptor['Extensions'] = array('type' => 'info', 'section' => 'source', 'default' => $this->getExtensionsMessage(), 'raw' => true); return $descriptor; }
/** * Environment check for compiled object cache types. */ protected function envCheckCache() { $caches = array(); foreach ($this->objectCaches as $name => $function) { if (function_exists($function)) { if ($name == 'xcache' && !wfIniGetBool('xcache.var_size')) { continue; } $caches[$name] = true; } } if (!$caches) { $key = 'config-no-cache'; // PHP >=5.5 is called APCu, earlier versions use APC (T61998). if (!wfIsHHVM() && version_compare(PHP_VERSION, '5.5', '>=')) { // config-no-cache-apcu $key .= '-apcu'; } $this->showMessage($key); } $this->setVar('_Caches', $caches); }
/** * Run JavaScript or CSS data through a filter, caching the filtered result for future calls. * * Available filters are: * * - minify-js \see JavaScriptMinifier::minify * - minify-css \see CSSMin::minify * * If $data is empty, only contains whitespace or the filter was unknown, * $data is returned unmodified. * * @param string $filter Name of filter to run * @param string $data Text to filter, such as JavaScript or CSS text * @param array $options For back-compat, can also be the boolean value for "cacheReport". Keys: * - (bool) cache: Whether to allow caching this data. Default: true. * - (bool) cacheReport: Whether to include the "cache key" report comment. Default: false. * @return string Filtered data, or a comment containing an error message */ public function filter($filter, $data, $options = array()) { // Back-compat if (is_bool($options)) { $options = array('cacheReport' => $options); } // Defaults $options += array('cache' => true, 'cacheReport' => false); $stats = RequestContext::getMain()->getStats(); // Don't filter empty content if (trim($data) === '') { return $data; } if (!in_array($filter, array('minify-js', 'minify-css'))) { $this->logger->warning('Invalid filter {filter}', array('filter' => $filter)); return $data; } if (!$options['cache']) { $result = self::applyFilter($filter, $data, $this->config); } else { $key = wfGlobalCacheKey('resourceloader', 'filter', $filter, self::$filterCacheVersion, md5($data)); $cache = wfGetCache(wfIsHHVM() ? CACHE_ACCEL : CACHE_ANYTHING); $cacheEntry = $cache->get($key); if (is_string($cacheEntry)) { $stats->increment("resourceloader_cache.{$filter}.hit"); return $cacheEntry; } $result = ''; try { $statStart = microtime(true); $result = self::applyFilter($filter, $data, $this->config); $statTiming = microtime(true) - $statStart; $stats->increment("resourceloader_cache.{$filter}.miss"); $stats->timing("resourceloader_cache.{$filter}.timing", 1000 * $statTiming); if ($options['cacheReport']) { $result .= "\n/* cache key: {$key} */"; } // Set a TTL since HHVM's APC doesn't have any limitation or eviction logic. $cache->set($key, $result, 24 * 3600); } catch (Exception $e) { MWExceptionHandler::logException($e); $this->logger->warning('Minification failed: {exception}', array('exception' => $e)); $this->errors[] = self::formatExceptionNoComment($e); } } return $result; }
/** * Returns true if we are running under HipHop, whether in compiled or * interpreted mode. * * @deprecated since 1.22 * @return bool */ static function isHipHop() { return wfIsHHVM(); }