die( "This file is part of MediaWiki, it is not a valid entry point" );
}
+use Liuggio\StatsdClient\StatsdClient;
+use Liuggio\StatsdClient\Sender\SocketSender;
+
// Hide compatibility functions from Doxygen
/// @cond
$context['prefix'] = $wgDebugLogPrefix;
}
- $logger = MWLogger::getInstance( 'wfDebug' );
+ $logger = MWLoggerFactory::getInstance( 'wfDebug' );
$logger->debug( $text, $context );
}
MWDebug::debugMsg( "[{$logGroup}] {$text}\n" );
}
- $logger = MWLogger::getInstance( $logGroup );
+ $logger = MWLoggerFactory::getInstance( $logGroup );
$context['private'] = ( $dest === 'private' );
$logger->info( $text, $context );
}
* @param array $context Additional logging context data
*/
function wfLogDBError( $text, array $context = array() ) {
- $logger = MWLogger::getInstance( 'wfLogDBError' );
+ $logger = MWLoggerFactory::getInstance( 'wfLogDBError' );
$logger->error( trim( $text ), $context );
}
*/
function wfErrorLog( $text, $file, array $context = array() ) {
wfDeprecated( __METHOD__, '1.25' );
- $logger = MWLogger::getInstance( 'wfErrorLog' );
+ $logger = MWLoggerFactory::getInstance( 'wfErrorLog' );
$context['destination'] = $file;
$logger->info( trim( $text ), $context );
}
global $wgRequestTime, $wgDebugLogGroups, $wgDebugRawPage;
global $wgProfileLimit, $wgUser, $wgRequest;
- StatCounter::singleton()->flush();
+ $context = RequestContext::getMain();
+ $config = $context->getConfig();
+ if ( $config->has( 'StatsdServer' ) ) {
+ $statsdServer = explode( ':', $config->get( 'StatsdServer' ) );
+ $statsdHost = $statsdServer[0];
+ $statsdPort = isset( $statsdServer[1] ) ? $statsdServer[1] : 8125;
+ $statsdSender = new SocketSender( $statsdHost, $statsdPort );
+ $statsdClient = new StatsdClient( $statsdSender );
+ $statsdClient->send( $context->getStats()->getBuffer() );
+ }
$profiler = Profiler::instance();
$ctx['output'] = $profiler->getOutput();
- $log = MWLogger::getInstance( 'profileoutput' );
+ $log = MWLoggerFactory::getInstance( 'profileoutput' );
$log->info( "Elapsed: {elapsed}; URL: <{url}>\n{output}", $ctx );
}
* @return void
*/
function wfIncrStats( $key, $count = 1 ) {
- StatCounter::singleton()->incr( $key, $count );
+ $stats = RequestContext::getMain()->getStats();
+ $stats->updateCount( $key, $count );
}
/**
* Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to
* earlier distro releases of PHP)
*
- * @param string $args,...
+ * @param string ... strings to escape and glue together, or a single array of strings parameter
* @return string
*/
function wfEscapeShellArg( /*...*/ ) {
wfInitShellLocale();
$args = func_get_args();
+ if ( count( $args ) === 1 && is_array( reset( $args ) ) ) {
+ // If only one argument has been passed, and that argument is an array,
+ // treat it as a list of arguments
+ $args = reset( $args );
+ }
+
$first = true;
$retVal = '';
foreach ( $args as $arg ) {
* @param array $options Array of options:
* - duplicateStderr: Set this to true to duplicate stderr to stdout,
* including errors from limit.sh
+ * - profileMethod: By default this function will profile based on the calling
+ * method. Set this to a string for an alternative method to profile from
*
* @return string Collected stdout as a string
*/
}
$includeStderr = isset( $options['duplicateStderr'] ) && $options['duplicateStderr'];
+ $profileMethod = isset( $options['profileMethod'] ) ? $options['profileMethod'] : wfGetCaller();
wfInitShellLocale();
}
}
if ( is_array( $cmd ) ) {
- // Command line may be given as an array, escape each value and glue them together with a space
- $cmdVals = array();
- foreach ( $cmd as $val ) {
- $cmdVals[] = wfEscapeShellArg( $val );
- }
- $cmd = implode( ' ', $cmdVals );
+ $cmd = wfEscapeShellArg( $cmd );
}
$cmd = $envcmd . $cmd;
$desc[3] = array( 'pipe', 'w' );
}
$pipes = null;
+ $scoped = Profiler::instance()->scopedProfileIn( __FUNCTION__ . '-' . $profileMethod );
$proc = proc_open( $cmd, $desc, $pipes );
if ( !$proc ) {
wfDebugLog( 'exec', "proc_open() failed: $cmd" );
* @return string Collected stdout and stderr as a string
*/
function wfShellExecWithStderr( $cmd, &$retval = null, $environ = array(), $limits = array() ) {
- return wfShellExec( $cmd, $retval, $environ, $limits, array( 'duplicateStderr' => true ) );
+ return wfShellExec( $cmd, $retval, $environ, $limits,
+ array( 'duplicateStderr' => true, 'profileMethod' => wfGetCaller() ) );
}
/**
}
}
-/**
- * Alias to wfShellWikiCmd()
- *
- * @see wfShellWikiCmd()
- */
-function wfShellMaintenanceCmd( $script, array $parameters = array(), array $options = array() ) {
- return wfShellWikiCmd( $script, $parameters, $options );
-}
-
/**
* Generate a shell-escaped command line string to run a MediaWiki cli script.
* Note that $parameters should be a flat array and an option with an argument
}
$cmd[] = $script;
// Escape each parameter for shell
- return implode( " ", array_map( 'wfEscapeShellArg', array_merge( $cmd, $parameters ) ) );
+ return wfEscapeShellArg( array_merge( $cmd, $parameters ) );
}
/**
fclose( $yourtextFile );
# Check for a conflict
- $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a --overlap-only ' .
- wfEscapeShellArg( $mytextName ) . ' ' .
- wfEscapeShellArg( $oldtextName ) . ' ' .
- wfEscapeShellArg( $yourtextName );
+ $cmd = wfEscapeShellArg( $wgDiff3, '-a', '--overlap-only', $mytextName, $oldtextName, $yourtextName );
$handle = popen( $cmd, 'r' );
if ( fgets( $handle, 1024 ) ) {
pclose( $handle );
# Merge differences
- $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a -e --merge ' .
- wfEscapeShellArg( $mytextName, $oldtextName, $yourtextName );
+ $cmd = wfEscapeShellArg( $wgDiff3, '-a', '-e', '--merge', $mytextName, $oldtextName, $yourtextName );
$handle = popen( $cmd, 'r' );
$result = '';
do {
* Shortcut for RepoGroup::singleton()->findFile()
*
* @param string $title String or Title object
- * @param array $options Associative array of options:
- * time: requested time for an archived image, or false for the
- * current version. An image object will be returned which was
- * created at the specified time.
- *
- * ignoreRedirect: If true, do not follow file redirects
- *
- * private: If true, return restricted (deleted) files if the current
- * user is allowed to view them. Otherwise, such files will not
- * be found.
- *
- * bypassCache: If true, do not use the process-local cache of File objects
- *
+ * @param array $options Associative array of options (see RepoGroup::findFile)
* @return File|bool File, or false if the file does not exist
*/
function wfFindFile( $title, $options = array() ) {
return ObjectCache::getInstance( $wgParserCacheType );
}
-/**
- * Get the cache object used by the language converter
- *
- * @return BagOStuff
- */
-function wfGetLangConverterCacheStorage() {
- global $wgLanguageConverterCacheType;
- return ObjectCache::getInstance( $wgLanguageConverterCacheType );
-}
-
/**
* Call hook functions defined in $wgHooks
*
* @param string|null $deprecatedVersion Optionally mark hook as deprecated with version number
*
* @return bool True if no handler aborted the hook
- * @deprecated 1.25
+ * @deprecated 1.25 - use Hooks::run
*/
function wfRunHooks( $event, array $args = array(), $deprecatedVersion = null ) {
return Hooks::run( $event, $args, $deprecatedVersion );
wfDeprecated( __METHOD__, '1.24' );
return IP::isConfiguredProxy( $ip );
}
+
+/**
+ * Returns true if these thumbnail parameters match one that MediaWiki
+ * requests from file description pages and/or parser output.
+ *
+ * $params is considered non-standard if they involve a non-standard
+ * width or any non-default parameters aside from width and page number.
+ * The number of possible files with standard parameters is far less than
+ * that of all combinations; rate-limiting for them can thus be more generious.
+ *
+ * @param File $file
+ * @param array $params
+ * @return bool
+ * @since 1.24 Moved from thumb.php to GlobalFunctions in 1.25
+ */
+function wfThumbIsStandard( File $file, array $params ) {
+ global $wgThumbLimits, $wgImageLimits, $wgResponsiveImages;
+
+ $multipliers = array( 1 );
+ if ( $wgResponsiveImages ) {
+ // These available sizes are hardcoded currently elsewhere in MediaWiki.
+ // @see Linker::processResponsiveImages
+ $multipliers[] = 1.5;
+ $multipliers[] = 2;
+ }
+
+ $handler = $file->getHandler();
+ if ( !$handler || !isset( $params['width'] ) ) {
+ return false;
+ }
+
+ $basicParams = array();
+ if ( isset( $params['page'] ) ) {
+ $basicParams['page'] = $params['page'];
+ }
+
+ $thumbLimits = array();
+ $imageLimits = array();
+ // Expand limits to account for multipliers
+ foreach ( $multipliers as $multiplier ) {
+ $thumbLimits = array_merge( $thumbLimits, array_map(
+ function ( $width ) use ( $multiplier ) {
+ return round( $width * $multiplier );
+ }, $wgThumbLimits )
+ );
+ $imageLimits = array_merge( $imageLimits, array_map(
+ function ( $pair ) use ( $multiplier ) {
+ return array(
+ round( $pair[0] * $multiplier ),
+ round( $pair[1] * $multiplier ),
+ );
+ }, $wgImageLimits )
+ );
+ }
+
+ // Check if the width matches one of $wgThumbLimits
+ if ( in_array( $params['width'], $thumbLimits ) ) {
+ $normalParams = $basicParams + array( 'width' => $params['width'] );
+ // Append any default values to the map (e.g. "lossy", "lossless", ...)
+ $handler->normaliseParams( $file, $normalParams );
+ } else {
+ // If not, then check if the width matchs one of $wgImageLimits
+ $match = false;
+ foreach ( $imageLimits as $pair ) {
+ $normalParams = $basicParams + array( 'width' => $pair[0], 'height' => $pair[1] );
+ // Decide whether the thumbnail should be scaled on width or height.
+ // Also append any default values to the map (e.g. "lossy", "lossless", ...)
+ $handler->normaliseParams( $file, $normalParams );
+ // Check if this standard thumbnail size maps to the given width
+ if ( $normalParams['width'] == $params['width'] ) {
+ $match = true;
+ break;
+ }
+ }
+ if ( !$match ) {
+ return false; // not standard for description pages
+ }
+ }
+
+ // Check that the given values for non-page, non-width, params are just defaults
+ foreach ( $params as $key => $value ) {
+ if ( !isset( $normalParams[$key] ) || $normalParams[$key] != $value ) {
+ return false;
+ }
+ }
+
+ return true;
+}