Merge "mw.ui: button: Update focus state"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 5232413..ace52e0 100644 (file)
@@ -24,6 +24,9 @@ if ( !defined( 'MEDIAWIKI' ) ) {
        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
 
@@ -1271,7 +1274,16 @@ function wfLogProfilingData() {
        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();
 
@@ -1346,7 +1358,8 @@ function wfLogProfilingData() {
  * @return void
  */
 function wfIncrStats( $key, $count = 1 ) {
-       StatCounter::singleton()->incr( $key, $count );
+       $stats = RequestContext::getMain()->getStats();
+       $stats->updateCount( $key, $count );
 }
 
 /**
@@ -2660,13 +2673,19 @@ function wfIniGetBool( $setting ) {
  * 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 ) {
@@ -2757,6 +2776,8 @@ function wfShellExecDisabled() {
  * @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
  */
@@ -2775,6 +2796,7 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
        }
 
        $includeStderr = isset( $options['duplicateStderr'] ) && $options['duplicateStderr'];
+       $profileMethod = isset( $options['profileMethod'] ) ? $options['profileMethod'] : wfGetCaller();
 
        wfInitShellLocale();
 
@@ -2796,12 +2818,7 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
                }
        }
        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;
@@ -2848,6 +2865,7 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
                $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" );
@@ -2999,7 +3017,8 @@ function wfShellExec( $cmd, &$retval = null, $environ = array(),
  * @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() ) );
 }
 
 /**
@@ -3019,15 +3038,6 @@ function wfInitShellLocale() {
        }
 }
 
-/**
- * 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
@@ -3051,7 +3061,7 @@ function wfShellWikiCmd( $script, array $parameters = array(), array $options =
        }
        $cmd[] = $script;
        // Escape each parameter for shell
-       return implode( " ", array_map( 'wfEscapeShellArg', array_merge( $cmd, $parameters ) ) );
+       return wfEscapeShellArg( array_merge( $cmd, $parameters ) );
 }
 
 /**
@@ -3096,10 +3106,7 @@ function wfMerge( $old, $mine, $yours, &$result ) {
        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 ) ) {
@@ -3110,8 +3117,7 @@ function wfMerge( $old, $mine, $yours, &$result ) {
        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 {
@@ -3659,19 +3665,7 @@ function wfGetLBFactory() {
  * 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() ) {
@@ -4008,16 +4002,6 @@ function wfGetParserCacheStorage() {
        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
  *