diff --git a/core/API/DataTableGenericFilter.php b/core/API/DataTableGenericFilter.php
index 02e2b31a246958738b7d85e7c4e260146b62a6cc..39dbba045c89d4e778c0eb477c297df340af74b3 100644
--- a/core/API/DataTableGenericFilter.php
+++ b/core/API/DataTableGenericFilter.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik
diff --git a/core/API/DataTableManipulator/LabelFilter.php b/core/API/DataTableManipulator/LabelFilter.php
index 68305118953f5ebf45c9b35b9d9d5b25292fd80c..1d6ca323d9239632b85b12a10bbb734f379433a2 100644
--- a/core/API/DataTableManipulator/LabelFilter.php
+++ b/core/API/DataTableManipulator/LabelFilter.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * This class is responsible for handling the label parameter that can be
diff --git a/core/API/DocumentationGenerator.php b/core/API/DocumentationGenerator.php
index f4a8cd387f71be62f737438cce9a8ddab643a0b8..e36023af01d1a8f1ae1ae94d7d45a542d4a2feba 100644
--- a/core/API/DocumentationGenerator.php
+++ b/core/API/DocumentationGenerator.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik
diff --git a/core/API/Proxy.php b/core/API/Proxy.php
index 8bb16832ac6c9384baf7cec58adec2458c4d57ef..16a0f6dd3225899bb7b5e018f0086eaa24544fbc 100644
--- a/core/API/Proxy.php
+++ b/core/API/Proxy.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * To differentiate between "no value" and default value of null
diff --git a/core/API/Request.php b/core/API/Request.php
index 56d12ecba70cc5a5fe68ccd1822c7f111f832622..19bf6634ca145f382d12e5b8ee69308241fa4c7b 100644
--- a/core/API/Request.php
+++ b/core/API/Request.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * An API request is the object used to make a call to the API and get the result.
diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php
index bdac6a6488f9d63aec23ac4857e0588c1ac0cc89..d4082226d1de6acd92b251830d4ec5981ebdf17a 100644
--- a/core/API/ResponseBuilder.php
+++ b/core/API/ResponseBuilder.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik
diff --git a/core/Access.php b/core/Access.php
index cab3a766e91f0886d90fbe043bbca0492ddb1d15..52ef921ebabf67ec9e6f02c845316bb812be2bec 100644
--- a/core/Access.php
+++ b/core/Access.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Class to handle User Access:
diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php
index 0d27b890590853e6339aed05cd8b85dd058f9606..e1a1b2004b35ccf7a5aa3d46b8f37f22e5343abc 100644
--- a/core/ArchiveProcessor/Rules.php
+++ b/core/ArchiveProcessor/Rules.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * This class contains Archiving rules/logic which are used in several places
diff --git a/core/AssetManager.php b/core/AssetManager.php
index 87dee1a8d25496f6f18873903d9b756727a2df0f..6a62cb176fe1a202ae30ee1c3a37df7e948569d3 100644
--- a/core/AssetManager.php
+++ b/core/AssetManager.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see libs/jsmin/jsmin.php
diff --git a/core/CacheFile.php b/core/CacheFile.php
index faa2b594058ad54074377f80014bbc062a2d5bf5..a7697084cd6e1d0549a326f08ec2149fe4462a31 100644
--- a/core/CacheFile.php
+++ b/core/CacheFile.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Code originally inspired from OpenX
diff --git a/core/Common.php b/core/Common.php
index d9c9371c69a456118ff286f095604670e6adec9f..36c3c97db4d7bc66cc2637c58825223b0d43d6cc 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -1,1597 +1,1608 @@
 <?php
-/**
- * Piwik - Open source web analytics
- *
- * @link http://piwik.org
- * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
- *
- * @category Piwik
- * @package Piwik
- */
-use Piwik\Core\Config;
-
-/**
- * Static class providing functions used by both the CORE of Piwik and the visitor Tracking engine.
- *
- * This is the only external class loaded by the /piwik.php file.
- * This class should contain only the functions that are used in
- * both the CORE and the piwik.php statistics logging engine.
- *
- * @package Piwik
- */
-class Piwik_Common
-{
-    const CLASSES_PREFIX = 'Piwik_';
-    
-    /**
-     * Const used to map the referer type to an integer in the log_visit table
-     */
-    const REFERER_TYPE_DIRECT_ENTRY = 1;
-    const REFERER_TYPE_SEARCH_ENGINE = 2;
-    const REFERER_TYPE_WEBSITE = 3;
-    const REFERER_TYPE_CAMPAIGN = 6;
-
-    /**
-     * Flag used with htmlspecialchar
-     * See php.net/htmlspecialchars
-     */
-    const HTML_ENCODING_QUOTE_STYLE = ENT_QUOTES;
-
-    /*
-     * Database
-     */
-
-    /**
-     * Hashes a string into an integer which should be very low collision risks
-     * @param string $string  String to hash
-     * @return int  Resulting int hash
-     */
-    public static function hashStringToInt($string)
-    {
-        $stringHash = substr(md5($string), 0, 8);
-        return base_convert($stringHash, 16, 10);
-    }
-
-    public static $cachedTablePrefix = null;
+namespace Piwik\Core {
+    use Exception;
+    use Piwik_IP;
+    use Piwik_PluginsManager;
+    use Piwik_Tracker;
+    use Piwik_Tracker_Cache;
+    use Piwik_UserCountry_LocationProvider_Default;
 
     /**
-     * Returns the table name prefixed by the table prefix.
-     * Works in both Tracker and UI mode.
+     * Static class providing functions used by both the CORE of Piwik and the visitor Tracking engine.
      *
-     * @param string $table  The table name to prefix, ie "log_visit"
-     * @return string  The table name prefixed, ie "piwik-production_log_visit"
-     */
-    public static function prefixTable($table)
-    {
-        $prefix = Config::getInstance()->database['tables_prefix'];
-        return $prefix . $table;
-    }
-
-    /**
-     * Returns an array containing the prefixed table names of every passed argument.
-     *
-     * @param string ... The table names to prefix, ie "log_visit"
-     * @return array The prefixed names in an array.
-     */
-    public static function prefixTables()
-    {
-        $result = array();
-        foreach (func_get_args() as $table) {
-            $result[] = self::prefixTable($table);
-        }
-        return $result;
-    }
-
-    /**
-     * Returns the table name, after removing the table prefix
+     * This is the only external class loaded by the /piwik.php file.
+     * This class should contain only the functions that are used in
+     * both the CORE and the piwik.php statistics logging engine.
      *
-     * @param string $table
-     * @return string
+     * @package Piwik
      */
-    public static function unprefixTable($table)
+    class Piwik_Common
     {
-        static $prefixTable = null;
-        if (is_null($prefixTable)) {
-            $prefixTable = Config::getInstance()->database['tables_prefix'];
-        }
-        if (empty($prefixTable)
-            || strpos($table, $prefixTable) !== 0
-        ) {
-            return $table;
-        }
-        $count = 1;
-        return str_replace($prefixTable, '', $table, $count);
-    }
-
-    /*
-     * Tracker
-     */
-    public static function isGoalPluginEnabled()
-    {
-        return Piwik_PluginsManager::getInstance()->isPluginActivated('Goals');
-    }
-
-    /*
-     * URLs
-     */
-
-    /**
-     * Returns the path and query part from a URL.
-     * Eg. http://piwik.org/test/index.php?module=CoreHome will return /test/index.php?module=CoreHome
-     *
-     * @param string $url  either http://piwik.org/test or /
-     * @return string
-     */
-    public static function getPathAndQueryFromUrl($url)
-    {
-        $parsedUrl = parse_url($url);
-        $result = '';
-        if (isset($parsedUrl['path'])) {
-            $result .= substr($parsedUrl['path'], 1);
-        }
-        if (isset($parsedUrl['query'])) {
-            $result .= '?' . $parsedUrl['query'];
-        }
-        return $result;
-    }
-
-    /**
-     * Returns the value of a GET parameter $parameter in an URL query $urlQuery
-     *
-     * @param string $urlQuery  result of parse_url()['query'] and htmlentitied (& is &amp;) eg. module=test&amp;action=toto or ?page=test
-     * @param string $parameter
-     * @return string|bool  Parameter value if found (can be the empty string!), null if not found
-     */
-    public static function getParameterFromQueryString($urlQuery, $parameter)
-    {
-        $nameToValue = self::getArrayFromQueryString($urlQuery);
-        if (isset($nameToValue[$parameter])) {
-            return $nameToValue[$parameter];
-        }
-        return null;
-    }
-
-    /**
-     * Returns an URL query string in an array format
-     *
-     * @param string $urlQuery
-     * @return array  array( param1=> value1, param2=>value2)
-     */
-    public static function getArrayFromQueryString($urlQuery)
-    {
-        if (strlen($urlQuery) == 0) {
-            return array();
-        }
-        if ($urlQuery[0] == '?') {
-            $urlQuery = substr($urlQuery, 1);
+        const CLASSES_PREFIX = 'Piwik_';
+
+        /**
+         * Const used to map the referer type to an integer in the log_visit table
+         */
+        const REFERER_TYPE_DIRECT_ENTRY = 1;
+        const REFERER_TYPE_SEARCH_ENGINE = 2;
+        const REFERER_TYPE_WEBSITE = 3;
+        const REFERER_TYPE_CAMPAIGN = 6;
+
+        /**
+         * Flag used with htmlspecialchar
+         * See php.net/htmlspecialchars
+         */
+        const HTML_ENCODING_QUOTE_STYLE = ENT_QUOTES;
+
+        /*
+         * Database
+         */
+
+        /**
+         * Hashes a string into an integer which should be very low collision risks
+         * @param string $string  String to hash
+         * @return int  Resulting int hash
+         */
+        public static function hashStringToInt($string)
+        {
+            $stringHash = substr(md5($string), 0, 8);
+            return base_convert($stringHash, 16, 10);
+        }
+
+        public static $cachedTablePrefix = null;
+
+        /**
+         * Returns the table name prefixed by the table prefix.
+         * Works in both Tracker and UI mode.
+         *
+         * @param string $table  The table name to prefix, ie "log_visit"
+         * @return string  The table name prefixed, ie "piwik-production_log_visit"
+         */
+        public static function prefixTable($table)
+        {
+            $prefix = Config::getInstance()->database['tables_prefix'];
+            return $prefix . $table;
+        }
+
+        /**
+         * Returns an array containing the prefixed table names of every passed argument.
+         *
+         * @param string ... The table names to prefix, ie "log_visit"
+         * @return array The prefixed names in an array.
+         */
+        public static function prefixTables()
+        {
+            $result = array();
+            foreach (func_get_args() as $table) {
+                $result[] = \Piwik\Core\self::prefixTable($table);
+            }
+            return $result;
         }
-        $separator = '&';
-
-        $urlQuery = $separator . $urlQuery;
-        //		$urlQuery = str_replace(array('%20'), ' ', $urlQuery);
-        $refererQuery = trim($urlQuery);
-
-        $values = explode($separator, $refererQuery);
-
-        $nameToValue = array();
 
-        foreach ($values as $value) {
-            $pos = strpos($value, '=');
-            if ($pos !== false) {
-                $name = substr($value, 0, $pos);
-                $value = substr($value, $pos + 1);
-                if ($value === false) {
-                    $value = '';
-                }
-            } else {
-                $name = $value;
-                $value = false;
+        /**
+         * Returns the table name, after removing the table prefix
+         *
+         * @param string $table
+         * @return string
+         */
+        public static function unprefixTable($table)
+        {
+            static $prefixTable = null;
+            if (is_null($prefixTable)) {
+                $prefixTable = Config::getInstance()->database['tables_prefix'];
             }
-            if (!empty($name)) {
-                $name = Piwik_Common::sanitizeInputValue($name);
+            if (empty($prefixTable)
+                || strpos($table, $prefixTable) !== 0
+            ) {
+                return $table;
             }
-            if (!empty($value)) {
-                $value = Piwik_Common::sanitizeInputValue($value);
+            $count = 1;
+            return str_replace($prefixTable, '', $table, $count);
+        }
+
+        /*
+         * Tracker
+         */
+        public static function isGoalPluginEnabled()
+        {
+            return Piwik_PluginsManager::getInstance()->isPluginActivated('Goals');
+        }
+
+        /*
+         * URLs
+         */
+
+        /**
+         * Returns the path and query part from a URL.
+         * Eg. http://piwik.org/test/index.php?module=CoreHome will return /test/index.php?module=CoreHome
+         *
+         * @param string $url  either http://piwik.org/test or /
+         * @return string
+         */
+        public static function getPathAndQueryFromUrl($url)
+        {
+            $parsedUrl = parse_url($url);
+            $result = '';
+            if (isset($parsedUrl['path'])) {
+                $result .= substr($parsedUrl['path'], 1);
             }
-
-            // if array without indexes
-            $count = 0;
-            $tmp = preg_replace('/(\[|%5b)(]|%5d)$/i', '', $name, -1, $count);
-            if (!empty($tmp) && $count) {
-                $name = $tmp;
-                if (isset($nameToValue[$name]) == false || is_array($nameToValue[$name]) == false) {
-                    $nameToValue[$name] = array();
-                }
-                array_push($nameToValue[$name], $value);
-            } else if (!empty($name)) {
-                $nameToValue[$name] = $value;
+            if (isset($parsedUrl['query'])) {
+                $result .= '?' . $parsedUrl['query'];
             }
+            return $result;
         }
-        return $nameToValue;
-    }
-
-    /**
-     * Builds a URL from the result of parse_url function
-     * Copied from the PHP comments at http://php.net/parse_url
-     * @param array $parsed
-     * @return bool|string
-     */
-    public static function getParseUrlReverse($parsed)
-    {
-        if (!is_array($parsed)) {
-            return false;
-        }
-
-        $uri = !empty($parsed['scheme']) ? $parsed['scheme'] . ':' . (!strcasecmp($parsed['scheme'], 'mailto') ? '' : '//') : '';
-        $uri .= !empty($parsed['user']) ? $parsed['user'] . (!empty($parsed['pass']) ? ':' . $parsed['pass'] : '') . '@' : '';
-        $uri .= !empty($parsed['host']) ? $parsed['host'] : '';
-        $uri .= !empty($parsed['port']) ? ':' . $parsed['port'] : '';
-
-        if (!empty($parsed['path'])) {
-            $uri .= (!strncmp($parsed['path'], '/', 1))
-                ? $parsed['path']
-                : ((!empty($uri) ? '/' : '') . $parsed['path']);
-        }
-
-        $uri .= !empty($parsed['query']) ? '?' . $parsed['query'] : '';
-        $uri .= !empty($parsed['fragment']) ? '#' . $parsed['fragment'] : '';
-        return $uri;
-    }
-
-    /**
-     * Returns true if the string passed may be a URL.
-     * We don't need a precise test here because the value comes from the website
-     * tracked source code and the URLs may look very strange.
-     *
-     * @param string $url
-     * @return bool
-     */
-    public static function isLookLikeUrl($url)
-    {
-        return preg_match('~^(ftp|news|http|https)?://(.*)$~D', $url, $matches) !== 0
-            && strlen($matches[2]) > 0;
-    }
-
-    /*
-     * File operations
-     */
-
-    /**
-     * ending WITHOUT slash
-     *
-     * @return string
-     */
-    public static function getPathToPiwikRoot()
-    {
-        return realpath(dirname(__FILE__) . "/..");
-    }
-
-    /**
-     * Create directory if permitted
-     *
-     * @param string $path
-     * @param bool $denyAccess
-     */
-    public static function mkdir($path, $denyAccess = true)
-    {
-        if (!is_dir($path)) {
-            // the mode in mkdir is modified by the current umask
-            @mkdir($path, $mode = 0755, $recursive = true);
-        }
-
-        // try to overcome restrictive umask (mis-)configuration
-        if (!is_writable($path)) {
-            @chmod($path, 0755);
-            if (!is_writable($path)) {
-                @chmod($path, 0775);
 
-                // enough! we're not going to make the directory world-writeable
+        /**
+         * Returns the value of a GET parameter $parameter in an URL query $urlQuery
+         *
+         * @param string $urlQuery  result of parse_url()['query'] and htmlentitied (& is &amp;) eg. module=test&amp;action=toto or ?page=test
+         * @param string $parameter
+         * @return string|bool  Parameter value if found (can be the empty string!), null if not found
+         */
+        public static function getParameterFromQueryString($urlQuery, $parameter)
+        {
+            $nameToValue = \Piwik\Core\self::getArrayFromQueryString($urlQuery);
+            if (isset($nameToValue[$parameter])) {
+                return $nameToValue[$parameter];
             }
-        }
-
-        if ($denyAccess) {
-            self::createHtAccess($path, $overwrite = false);
-        }
-    }
-
-    /**
-     * Create .htaccess file in specified directory
-     *
-     * Apache-specific; for IIS @see web.config
-     *
-     * @param string $path     without trailing slash
-     * @param bool $overwrite whether to overwrite an existing file or not
-     * @param string $content
-     */
-    public static function createHtAccess($path, $overwrite = true, $content = "<Files \"*\">\n<IfModule mod_access.c>\nDeny from all\n</IfModule>\n<IfModule !mod_access_compat>\n<IfModule mod_authz_host.c>\nDeny from all\n</IfModule>\n</IfModule>\n<IfModule mod_access_compat>\nDeny from all\n</IfModule>\n</Files>\n")
-    {
-        if (self::isApache()) {
-            $file = $path . '/.htaccess';
-            if ($overwrite || !file_exists($file)) {
-                @file_put_contents($file, $content);
+            return null;
+        }
+
+        /**
+         * Returns an URL query string in an array format
+         *
+         * @param string $urlQuery
+         * @return array  array( param1=> value1, param2=>value2)
+         */
+        public static function getArrayFromQueryString($urlQuery)
+        {
+            if (strlen($urlQuery) == 0) {
+                return array();
             }
-        }
-    }
-
-    /**
-     * Get canonicalized absolute path
-     * See http://php.net/realpath
-     *
-     * @param string $path
-     * @return string  canonicalized absolute path
-     */
-    public static function realpath($path)
-    {
-        if (file_exists($path)) {
-            return realpath($path);
-        }
-        return $path;
-    }
-
-    /**
-     * Returns true if the string is a valid filename
-     * File names that start with a-Z or 0-9 and contain a-Z, 0-9, underscore(_), dash(-), and dot(.) will be accepted.
-     * File names beginning with anything but a-Z or 0-9 will be rejected (including .htaccess for example).
-     * File names containing anything other than above mentioned will also be rejected (file names with spaces won't be accepted).
-     *
-     * @param string $filename
-     * @return bool
-     *
-     */
-    public static function isValidFilename($filename)
-    {
-        return (0 !== preg_match('/(^[a-zA-Z0-9]+([a-zA-Z_0-9.-]*))$/D', $filename));
-    }
-
-    /*
-     * String operations
-     */
-
-    /**
-     * byte-oriented substr() - ASCII
-     *
-     * @param string $string
-     * @param int $start
-     * @param int     ...      optional length
-     * @return string
-     */
-    public static function substr($string, $start)
-    {
-        // in case mbstring overloads substr function
-        $substr = function_exists('mb_orig_substr') ? 'mb_orig_substr' : 'substr';
-
-        $length = func_num_args() > 2
-            ? func_get_arg(2)
-            : self::strlen($string);
-
-        return $substr($string, $start, $length);
-    }
-
-    /**
-     * byte-oriented strlen() - ASCII
-     *
-     * @param string $string
-     * @return int
-     */
-    public static function strlen($string)
-    {
-        // in case mbstring overloads strlen function
-        $strlen = function_exists('mb_orig_strlen') ? 'mb_orig_strlen' : 'strlen';
-        return $strlen($string);
-    }
-
-    /**
-     * multi-byte substr() - UTF-8
-     *
-     * @param string $string
-     * @param int $start
-     * @param int     ...      optional length
-     * @return string
-     */
-    public static function mb_substr($string, $start)
-    {
-        $length = func_num_args() > 2
-            ? func_get_arg(2)
-            : self::mb_strlen($string);
-
-        if (function_exists('mb_substr')) {
-            return mb_substr($string, $start, $length, 'UTF-8');
-        }
-
-        return substr($string, $start, $length);
-    }
-
-    /**
-     * multi-byte strlen() - UTF-8
-     *
-     * @param string $string
-     * @return int
-     */
-    public static function mb_strlen($string)
-    {
-        if (function_exists('mb_strlen')) {
-            return mb_strlen($string, 'UTF-8');
-        }
-
-        return strlen($string);
-    }
+            if ($urlQuery[0] == '?') {
+                $urlQuery = substr($urlQuery, 1);
+            }
+            $separator = '&';
 
-    /**
-     * multi-byte strtolower() - UTF-8
-     *
-     * @param string $string
-     * @return string
-     */
-    public static function mb_strtolower($string)
-    {
-        if (function_exists('mb_strtolower')) {
-            return mb_strtolower($string, 'UTF-8');
-        }
+            $urlQuery = $separator . $urlQuery;
+            //		$urlQuery = str_replace(array('%20'), ' ', $urlQuery);
+            $refererQuery = trim($urlQuery);
 
-        return strtolower($string);
-    }
+            $values = explode($separator, $refererQuery);
 
-    /*
-     * Escaping input
-     */
+            $nameToValue = array();
 
-    /**
-     * Returns the variable after cleaning operations.
-     * NB: The variable still has to be escaped before going into a SQL Query!
-     *
-     * If an array is passed the cleaning is done recursively on all the sub-arrays.
-     * The array's keys are filtered as well!
-     *
-     * How this method works:
-     * - The variable returned has been htmlspecialchars to avoid the XSS security problem.
-     * - The single quotes are not protected so "Piwik's amazing" will still be "Piwik's amazing".
-     *
-     * - Transformations are:
-     *         - '&' (ampersand) becomes '&amp;'
-     *         - '"'(double quote) becomes '&quot;'
-     *         - '<' (less than) becomes '&lt;'
-     *         - '>' (greater than) becomes '&gt;'
-     * - It handles the magic_quotes setting.
-     * - A non string value is returned without modification
-     *
-     * @param mixed $value The variable to be cleaned
-     * @param bool $alreadyStripslashed
-     * @throws Exception
-     * @return mixed  The variable after cleaning
-     */
-    public static function sanitizeInputValues($value, $alreadyStripslashed = false)
-    {
-        if (is_numeric($value)) {
-            return $value;
-        } elseif (is_string($value)) {
-            $value = self::sanitizeInputValue($value);
-
-            if (!$alreadyStripslashed) // a JSON array was already stripslashed, don't do it again for each value
-            {
-                $value = self::undoMagicQuotes($value);
-            }
-        } elseif (is_array($value)) {
-            foreach (array_keys($value) as $key) {
-                $newKey = $key;
-                $newKey = self::sanitizeInputValues($newKey, $alreadyStripslashed);
-                if ($key != $newKey) {
-                    $value[$newKey] = $value[$key];
-                    unset($value[$key]);
+            foreach ($values as $value) {
+                $pos = strpos($value, '=');
+                if ($pos !== false) {
+                    $name = substr($value, 0, $pos);
+                    $value = substr($value, $pos + 1);
+                    if ($value === false) {
+                        $value = '';
+                    }
+                } else {
+                    $name = $value;
+                    $value = false;
+                }
+                if (!empty($name)) {
+                    $name = \Piwik\Core\Piwik_Common::sanitizeInputValue($name);
+                }
+                if (!empty($value)) {
+                    $value = \Piwik\Core\Piwik_Common::sanitizeInputValue($value);
                 }
 
-                $value[$newKey] = self::sanitizeInputValues($value[$newKey], $alreadyStripslashed);
+                // if array without indexes
+                $count = 0;
+                $tmp = preg_replace('/(\[|%5b)(]|%5d)$/i', '', $name, -1, $count);
+                if (!empty($tmp) && $count) {
+                    $name = $tmp;
+                    if (isset($nameToValue[$name]) == false || is_array($nameToValue[$name]) == false) {
+                        $nameToValue[$name] = array();
+                    }
+                    array_push($nameToValue[$name], $value);
+                } else if (!empty($name)) {
+                    $nameToValue[$name] = $value;
+                }
             }
-        } elseif (!is_null($value)
-            && !is_bool($value)
-        ) {
-            throw new Exception("The value to escape has not a supported type. Value = " . var_export($value, true));
-        }
-        return $value;
-    }
-
-    /**
-     * Sanitize a single input value
-     *
-     * @param string $value
-     * @return string  sanitized input
-     */
-    public static function sanitizeInputValue($value)
-    {
-        // $_GET and $_REQUEST already urldecode()'d
-        // decode
-        // note: before php 5.2.7, htmlspecialchars() double encodes &#x hex items
-        $value = html_entity_decode($value, Piwik_Common::HTML_ENCODING_QUOTE_STYLE, 'UTF-8');
-
-        // filter
-        $value = str_replace(array("\n", "\r", "\0"), '', $value);
-
-        // escape
-        $tmp = @htmlspecialchars($value, self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8');
-
-        // note: php 5.2.5 and above, htmlspecialchars is destructive if input is not UTF-8
-        if ($value != '' && $tmp == '') {
-            // convert and escape
-            $value = utf8_encode($value);
-            $tmp = htmlspecialchars($value, self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8');
-        }
-        return $tmp;
-    }
-
-    /**
-     * Unsanitize a single input value
-     *
-     * @param string $value
-     * @return string  unsanitized input
-     */
-    public static function unsanitizeInputValue($value)
-    {
-        return htmlspecialchars_decode($value, self::HTML_ENCODING_QUOTE_STYLE);
-    }
-
-    /**
-     * Unsanitize one or more values.
-     *
-     * @param string|array $value
-     * @return string|array  unsanitized input
-     */
-    public static function unsanitizeInputValues($value)
-    {
-        if (is_array($value)) {
-            $result = array();
-            foreach ($value as $key => $arrayValue) {
-                $result[$key] = self::unsanitizeInputValues($arrayValue);
+            return $nameToValue;
+        }
+
+        /**
+         * Builds a URL from the result of parse_url function
+         * Copied from the PHP comments at http://php.net/parse_url
+         * @param array $parsed
+         * @return bool|string
+         */
+        public static function getParseUrlReverse($parsed)
+        {
+            if (!is_array($parsed)) {
+                return false;
             }
-            return $result;
-        } else {
-            return self::unsanitizeInputValue($value);
-        }
-    }
 
-    /**
-     * Undo the damage caused by magic_quotes; deprecated in php 5.3 but not removed until php 5.4
-     *
-     * @param string
-     * @return string  modified or not
-     */
-    public static function undoMagicQuotes($value)
-    {
-        return version_compare(PHP_VERSION, '5.4', '<')
-            && get_magic_quotes_gpc()
-            ? stripslashes($value)
-            : $value;
-    }
+            $uri = !empty($parsed['scheme']) ? $parsed['scheme'] . ':' . (!strcasecmp($parsed['scheme'], 'mailto') ? '' : '//') : '';
+            $uri .= !empty($parsed['user']) ? $parsed['user'] . (!empty($parsed['pass']) ? ':' . $parsed['pass'] : '') . '@' : '';
+            $uri .= !empty($parsed['host']) ? $parsed['host'] : '';
+            $uri .= !empty($parsed['port']) ? ':' . $parsed['port'] : '';
 
-    /**
-     * Returns a sanitized variable value from the $_GET and $_POST superglobal.
-     * If the variable doesn't have a value or an empty value, returns the defaultValue if specified.
-     * If the variable doesn't have neither a value nor a default value provided, an exception is raised.
-     *
-     * @see sanitizeInputValues() for the applied sanitization
-     *
-     * @param string $varName            name of the variable
-     * @param string $varDefault         default value. If '', and if the type doesn't match, exit() !
-     * @param string $varType            Expected type, the value must be one of the following: array, int, integer, string, json
-     * @param array $requestArrayToUse
-     *
-     * @throws Exception  if the variable type is not known
-     *                    or if the variable we want to read doesn't have neither a value nor a default value specified
-     *
-     * @return mixed The variable after cleaning
-     */
-    public static function getRequestVar($varName, $varDefault = null, $varType = null, $requestArrayToUse = null)
-    {
-        if (is_null($requestArrayToUse)) {
-            $requestArrayToUse = $_GET + $_POST;
-        }
-        $varDefault = self::sanitizeInputValues($varDefault);
-        if ($varType === 'int') {
-            // settype accepts only integer
-            // 'int' is simply a shortcut for 'integer'
-            $varType = 'integer';
-        }
-
-        // there is no value $varName in the REQUEST so we try to use the default value
-        if (empty($varName)
-            || !isset($requestArrayToUse[$varName])
-            || (!is_array($requestArrayToUse[$varName])
-                && strlen($requestArrayToUse[$varName]) === 0
-            )
-        ) {
-            if (is_null($varDefault)) {
-                throw new Exception("The parameter '$varName' isn't set in the Request, and a default value wasn't provided.");
-            } else {
-                if (!is_null($varType)
-                    && in_array($varType, array('string', 'integer', 'array'))
-                ) {
-                    settype($varDefault, $varType);
-                }
-                return $varDefault;
+            if (!empty($parsed['path'])) {
+                $uri .= (!strncmp($parsed['path'], '/', 1))
+                    ? $parsed['path']
+                    : ((!empty($uri) ? '/' : '') . $parsed['path']);
             }
-        }
 
-        // Normal case, there is a value available in REQUEST for the requested varName:
-
-        // we deal w/ json differently
-        if ($varType == 'json') {
-            $value = self::undoMagicQuotes($requestArrayToUse[$varName]);
-            $value = Piwik_Common::json_decode($value, $assoc = true);
-            return self::sanitizeInputValues($value, $alreadyStripslashed = true);
+            $uri .= !empty($parsed['query']) ? '?' . $parsed['query'] : '';
+            $uri .= !empty($parsed['fragment']) ? '#' . $parsed['fragment'] : '';
+            return $uri;
+        }
+
+        /**
+         * Returns true if the string passed may be a URL.
+         * We don't need a precise test here because the value comes from the website
+         * tracked source code and the URLs may look very strange.
+         *
+         * @param string $url
+         * @return bool
+         */
+        public static function isLookLikeUrl($url)
+        {
+            return preg_match('~^(ftp|news|http|https)?://(.*)$~D', $url, $matches) !== 0
+            && strlen($matches[2]) > 0;
         }
 
-        $value = self::sanitizeInputValues($requestArrayToUse[$varName]);
-        if (!is_null($varType)) {
-            $ok = false;
-
-            if ($varType === 'string') {
-                if (is_string($value)) $ok = true;
-            } elseif ($varType === 'integer') {
-                if ($value == (string)(int)$value) $ok = true;
-            } elseif ($varType === 'float') {
-                if ($value == (string)(float)$value) $ok = true;
-            } elseif ($varType === 'array') {
-                if (is_array($value)) $ok = true;
-            } else {
-                throw new Exception("\$varType specified is not known. It should be one of the following: array, int, integer, float, string");
-            }
-
-            // The type is not correct
-            if ($ok === false) {
-                if ($varDefault === null) {
-                    throw new Exception("The parameter '$varName' doesn't have a correct type, and a default value wasn't provided.");
-                } // we return the default value with the good type set
-                else {
-                    settype($varDefault, $varType);
-                    return $varDefault;
-                }
+        /*
+         * File operations
+         */
+
+        /**
+         * ending WITHOUT slash
+         *
+         * @return string
+         */
+        public static function getPathToPiwikRoot()
+        {
+            return realpath(dirname(__FILE__) . "/..");
+        }
+
+        /**
+         * Create directory if permitted
+         *
+         * @param string $path
+         * @param bool $denyAccess
+         */
+        public static function mkdir($path, $denyAccess = true)
+        {
+            if (!is_dir($path)) {
+                // the mode in mkdir is modified by the current umask
+                @mkdir($path, $mode = 0755, $recursive = true);
             }
-            settype($value, $varType);
-        }
-        return $value;
-    }
-
-    /*
-     * Generating unique strings
-     */
 
-    /**
-     * Returns a 32 characters long uniq ID
-     *
-     * @return string 32 chars
-     */
-    public static function generateUniqId()
-    {
-        return md5(uniqid(rand(), true));
-    }
-
-    /**
-     * Get salt from [superuser] section
-     *
-     * @return string
-     */
-    public static function getSalt()
-    {
-        static $salt = null;
-        if (is_null($salt)) {
-            $salt = @Config::getInstance()->superuser['salt'];
-        }
-        return $salt;
-    }
-
-    /**
-     * Configureable hash() algorithm (defaults to md5)
-     *
-     * @param string $str String to be hashed
-     * @param bool $raw_output
-     * @return string Hash string
-     */
-    public static function hash($str, $raw_output = false)
-    {
-        static $hashAlgorithm = null;
-        if (is_null($hashAlgorithm)) {
-            $hashAlgorithm = @Config::getInstance()->General['hash_algorithm'];
-        }
-
-        if ($hashAlgorithm) {
-            $hash = @hash($hashAlgorithm, $str, $raw_output);
-            if ($hash !== false)
-                return $hash;
-        }
-
-        return md5($str, $raw_output);
-    }
-
-    /**
-     * Generate random string
-     *
-     * @param int $length string length
-     * @param string $alphabet characters allowed in random string
-     * @return string  random string with given length
-     */
-    public static function getRandomString($length = 16, $alphabet = "abcdefghijklmnoprstuvwxyz0123456789")
-    {
-        $chars = $alphabet;
-        $str = '';
-
-        list($usec, $sec) = explode(" ", microtime());
-        $seed = ((float)$sec + (float)$usec) * 100000;
-        mt_srand($seed);
-
-        for ($i = 0; $i < $length; $i++) {
-            $rand_key = mt_rand(0, strlen($chars) - 1);
-            $str .= substr($chars, $rand_key, 1);
-        }
-        return str_shuffle($str);
-    }
-
-    /*
-     * Conversions
-     */
-
-    /**
-     * Convert hexadecimal representation into binary data.
-     * !! Will emit warning if input string is not hex!!
-     *
-     * @see http://php.net/bin2hex
-     *
-     * @param string $str  Hexadecimal representation
-     * @return string
-     */
-    public static function hex2bin($str)
-    {
-        return pack("H*", $str);
-    }
-
-    /**
-     * This function will convert the input string to the binary representation of the ID
-     * but it will throw an Exception if the specified input ID is not correct
-     *
-     * This is used when building segments containing visitorId which could be an invalid string
-     * therefore throwing Unexpected PHP error [pack(): Type H: illegal hex digit i] severity [E_WARNING]
-     *
-     * It would be simply to silent fail the pack() call above but in all other cases, we don't expect an error,
-     * so better be safe and get the php error when something unexpected is happening
-     * @param string $id
-     * @throws Exception
-     * @return string  binary string
-     */
-    public static function convertVisitorIdToBin($id)
-    {
-        if (strlen($id) !== Piwik_Tracker::LENGTH_HEX_ID_STRING
-            || @bin2hex(self::hex2bin($id)) != $id
-        ) {
-            throw new Exception("visitorId is expected to be a " . Piwik_Tracker::LENGTH_HEX_ID_STRING . " hex char string");
-        }
-        return self::hex2bin($id);
-    }
-
-    /**
-     * Convert IP address (in network address format) to presentation format.
-     * This is a backward compatibility function for code that only expects
-     * IPv4 addresses (i.e., doesn't support IPv6).
-     *
-     * @see Piwik_IP::N2P()
-     *
-     * This function does not support the long (or its string representation)
-     * returned by the built-in ip2long() function, from Piwik 1.3 and earlier.
-     *
-     * @deprecated 1.4
-     *
-     * @param string $ip  IP address in network address format
-     * @return string
-     */
-    public static function long2ip($ip)
-    {
-        return Piwik_IP::long2ip($ip);
-    }
-
-    /**
-     * Should we use the replacement json_encode/json_decode functions?
-     *
-     * @return bool  True if broken; false otherwise
-     */
-    private static function useJsonLibrary()
-    {
-        static $useLib;
-
-        if (!isset($useLib)) {
-            /*
-             * 5.1.x - doesn't have json extension; we use lib/upgradephp instead
-             * 5.2 to 5.2.4 - broken in various ways, including:
-             *
-             * @see https://bugs.php.net/bug.php?id=38680 'json_decode cannot decode basic types'
-             * @see https://bugs.php.net/bug.php?id=41403 'json_decode cannot decode floats'
-             * @see https://bugs.php.net/bug.php?id=42785 'json_encode outputs numbers according to locale'
-             */
-            $useLib = false;
-            if (version_compare(PHP_VERSION, '5.2.1') < 0) {
-                $useLib = true;
-            } else if (version_compare(PHP_VERSION, '5.2.5') < 0) {
-                $info = localeconv();
-                $useLib = $info['decimal_point'] != '.';
-            }
-        }
-
-        return $useLib;
-    }
-
-    /**
-     * JSON encode wrapper
-     * - missing or broken in some php 5.x versions
-     *
-     * @param mixed $value
-     * @return string
-     */
-    public static function json_encode($value)
-    {
-        if (self::useJsonLibrary()) {
-            return _json_encode($value);
-        }
-
-        return @json_encode($value);
-    }
-
-    /**
-     * JSON decode wrapper
-     * - missing or broken in some php 5.x versions
-     *
-     * @param string $json
-     * @param bool $assoc
-     * @return mixed
-     */
-    public static function json_decode($json, $assoc = false)
-    {
-        if (self::useJsonLibrary()) {
-            return _json_decode($json, $assoc);
-        }
-
-        return json_decode($json, $assoc);
-    }
-
-    /*
-     * DataFiles
-     */
-
-    /**
-     * Returns list of continent codes
-     *
-     * @see core/DataFiles/Countries.php
-     *
-     * @return array  Array of 3 letter continent codes
-     */
-    public static function getContinentsList()
-    {
-        require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php';
-
-        $continentsList = $GLOBALS['Piwik_ContinentList'];
-        return $continentsList;
-    }
-
-    /**
-     * Returns list of valid country codes
-     *
-     * @see core/DataFiles/Countries.php
-     *
-     * @param bool $includeInternalCodes
-     * @return array  Array of (2 letter ISO codes => 3 letter continent code)
-     */
-    public static function getCountriesList($includeInternalCodes = false)
-    {
-        require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php';
-
-        $countriesList = $GLOBALS['Piwik_CountryList'];
-        $extras = $GLOBALS['Piwik_CountryList_Extras'];
-
-        if ($includeInternalCodes) {
-            return array_merge($countriesList, $extras);
-        }
-        return $countriesList;
-    }
-
-    /**
-     * Returns list of valid language codes
-     *
-     * @see core/DataFiles/Languages.php
-     *
-     * @return array  Array of 2 letter ISO codes => Language name (in English)
-     */
-    public static function getLanguagesList()
-    {
-        require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Languages.php';
-
-        $languagesList = $GLOBALS['Piwik_LanguageList'];
-        return $languagesList;
-    }
-
-    /**
-     * Returns list of language to country mappings
-     *
-     * @see core/DataFiles/LanguageToCountry.php
-     *
-     * @return array  Array of ( 2 letter ISO language codes => 2 letter ISO country codes )
-     */
-    public static function getLanguageToCountryList()
-    {
-        require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/LanguageToCountry.php';
-
-        $languagesList = $GLOBALS['Piwik_LanguageToCountry'];
-        return $languagesList;
-    }
-
-    /**
-     * Returns list of search engines by URL
-     *
-     * @see core/DataFiles/SearchEngines.php
-     *
-     * @return array  Array of ( URL => array( searchEngineName, keywordParameter, path, charset ) )
-     */
-    public static function getSearchEngineUrls()
-    {
-        require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php';
-
-        $searchEngines = $GLOBALS['Piwik_SearchEngines'];
-        return $searchEngines;
-    }
-
-    /**
-     * Returns list of search engines by name
-     *
-     * @see core/DataFiles/SearchEngines.php
-     *
-     * @return array  Array of ( searchEngineName => URL )
-     */
-    public static function getSearchEngineNames()
-    {
-        require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php';
-
-        $searchEngines = $GLOBALS['Piwik_SearchEngines_NameToUrl'];
-        return $searchEngines;
-    }
-
-    /**
-     * Returns list of provider names
-     *
-     * @see core/DataFiles/Providers.php
-     *
-     * @return array  Array of ( dnsName => providerName )
-     */
-    public static function getProviderNames()
-    {
-        require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Providers.php';
-
-        $providers = $GLOBALS['Piwik_ProviderNames'];
-        return $providers;
-    }
-
-    /*
-     * Language, country, continent
-     */
-
-    /**
-     * Returns the browser language code, eg. "en-gb,en;q=0.5"
-     *
-     * @param string|null $browserLang  Optional browser language, otherwise taken from the request header
-     * @return string
-     */
-    public static function getBrowserLanguage($browserLang = NULL)
-    {
-        static $replacementPatterns = array(
-            // extraneous bits of RFC 3282 that we ignore
-            '/(\\\\.)/', // quoted-pairs
-            '/(\s+)/', // CFWcS white space
-            '/(\([^)]*\))/', // CFWS comments
-            '/(;q=[0-9.]+)/', // quality
+            // try to overcome restrictive umask (mis-)configuration
+            if (!is_writable($path)) {
+                @chmod($path, 0755);
+                if (!is_writable($path)) {
+                    @chmod($path, 0775);
 
-            // found in the LANG environment variable
-            '/\.(.*)/', // charset (e.g., en_CA.UTF-8)
-            '/^C$/', // POSIX 'C' locale
-        );
+                    // enough! we're not going to make the directory world-writeable
+                }
+            }
 
-        if (is_null($browserLang)) {
-            $browserLang = self::sanitizeInputValues(@$_SERVER['HTTP_ACCEPT_LANGUAGE']);
-            if (empty($browserLang) && self::isPhpCliMode()) {
-                $browserLang = @getenv('LANG');
+            if ($denyAccess) {
+                \Piwik\Core\self::createHtAccess($path, $overwrite = false);
             }
         }
 
-        if (is_null($browserLang)) {
-            // a fallback might be to infer the language in HTTP_USER_AGENT (i.e., localized build)
-            $browserLang = "";
-        } else {
-            // language tags are case-insensitive per HTTP/1.1 s3.10 but the region may be capitalized per ISO3166-1;
-            // underscores are not permitted per RFC 4646 or 4647 (which obsolete RFC 1766 and 3066),
-            // but we guard against a bad user agent which naively uses its locale
-            $browserLang = strtolower(str_replace('_', '-', $browserLang));
-
-            // filters
-            $browserLang = preg_replace($replacementPatterns, '', $browserLang);
-
-            $browserLang = preg_replace('/((^|,)chrome:.*)/', '', $browserLang, 1); // Firefox bug
-            $browserLang = preg_replace('/(,)(?:en-securid,)|(?:(^|,)en-securid(,|$))/', '$1', $browserLang, 1); // unregistered language tag
-
-            $browserLang = str_replace('sr-sp', 'sr-rs', $browserLang); // unofficial (proposed) code in the wild
+        /**
+         * Create .htaccess file in specified directory
+         *
+         * Apache-specific; for IIS @see web.config
+         *
+         * @param string $path     without trailing slash
+         * @param bool $overwrite whether to overwrite an existing file or not
+         * @param string $content
+         */
+        public static function createHtAccess($path, $overwrite = true, $content = "<Files \"*\">\n<IfModule mod_access.c>\nDeny from all\n</IfModule>\n<IfModule !mod_access_compat>\n<IfModule mod_authz_host.c>\nDeny from all\n</IfModule>\n</IfModule>\n<IfModule mod_access_compat>\nDeny from all\n</IfModule>\n</Files>\n")
+        {
+            if (\Piwik\Core\self::isApache()) {
+                $file = $path . '/.htaccess';
+                if ($overwrite || !file_exists($file)) {
+                    @file_put_contents($file, $content);
+                }
+            }
         }
 
-        return $browserLang;
-    }
+        /**
+         * Get canonicalized absolute path
+         * See http://php.net/realpath
+         *
+         * @param string $path
+         * @return string  canonicalized absolute path
+         */
+        public static function realpath($path)
+        {
+            if (file_exists($path)) {
+                return realpath($path);
+            }
+            return $path;
+        }
+
+        /**
+         * Returns true if the string is a valid filename
+         * File names that start with a-Z or 0-9 and contain a-Z, 0-9, underscore(_), dash(-), and dot(.) will be accepted.
+         * File names beginning with anything but a-Z or 0-9 will be rejected (including .htaccess for example).
+         * File names containing anything other than above mentioned will also be rejected (file names with spaces won't be accepted).
+         *
+         * @param string $filename
+         * @return bool
+         *
+         */
+        public static function isValidFilename($filename)
+        {
+            return (0 !== preg_match('/(^[a-zA-Z0-9]+([a-zA-Z_0-9.-]*))$/D', $filename));
+        }
+
+        /*
+         * String operations
+         */
+
+        /**
+         * byte-oriented substr() - ASCII
+         *
+         * @param string $string
+         * @param int $start
+         * @param int     ...      optional length
+         * @return string
+         */
+        public static function substr($string, $start)
+        {
+            // in case mbstring overloads substr function
+            $substr = function_exists('mb_orig_substr') ? 'mb_orig_substr' : 'substr';
+
+            $length = func_num_args() > 2
+                ? func_get_arg(2)
+                : \Piwik\Core\self::strlen($string);
+
+            return $substr($string, $start, $length);
+        }
+
+        /**
+         * byte-oriented strlen() - ASCII
+         *
+         * @param string $string
+         * @return int
+         */
+        public static function strlen($string)
+        {
+            // in case mbstring overloads strlen function
+            $strlen = function_exists('mb_orig_strlen') ? 'mb_orig_strlen' : 'strlen';
+            return $strlen($string);
+        }
+
+        /**
+         * multi-byte substr() - UTF-8
+         *
+         * @param string $string
+         * @param int $start
+         * @param int     ...      optional length
+         * @return string
+         */
+        public static function mb_substr($string, $start)
+        {
+            $length = func_num_args() > 2
+                ? func_get_arg(2)
+                : \Piwik\Core\self::mb_strlen($string);
+
+            if (function_exists('mb_substr')) {
+                return mb_substr($string, $start, $length, 'UTF-8');
+            }
 
-    /**
-     * Returns the visitor country based on the Browser 'accepted language'
-     * information, but provides a hook for geolocation via IP address.
-     *
-     * @param string $lang                          browser lang
-     * @param bool $enableLanguageToCountryGuess  If set to true, some assumption will be made and detection guessed more often, but accuracy could be affected
-     * @param string $ip
-     * @return string  2 letter ISO code
-     */
-    public static function getCountry($lang, $enableLanguageToCountryGuess, $ip)
-    {
-        $country = null;
-        Piwik_PostEvent('Common.getCountry', array(&$country, $ip));
-        if (!empty($country)) {
-            return strtolower($country);
+            return substr($string, $start, $length);
         }
 
-        if (empty($lang) || strlen($lang) < 2 || $lang == 'xx') {
-            return 'xx';
+        /**
+         * multi-byte strlen() - UTF-8
+         *
+         * @param string $string
+         * @return int
+         */
+        public static function mb_strlen($string)
+        {
+            if (function_exists('mb_strlen')) {
+                return mb_strlen($string, 'UTF-8');
+            }
+
+            return strlen($string);
         }
 
-        $validCountries = self::getCountriesList();
-        return self::extractCountryCodeFromBrowserLanguage($lang, $validCountries, $enableLanguageToCountryGuess);
-    }
+        /**
+         * multi-byte strtolower() - UTF-8
+         *
+         * @param string $string
+         * @return string
+         */
+        public static function mb_strtolower($string)
+        {
+            if (function_exists('mb_strtolower')) {
+                return mb_strtolower($string, 'UTF-8');
+            }
 
-    /**
-     * Returns list of valid country codes
-     *
-     * @param string $browserLanguage
-     * @param array $validCountries                 Array of valid countries
-     * @param bool $enableLanguageToCountryGuess  (if true, will guess country based on language that lacks region information)
-     * @return array Array of 2 letter ISO codes
-     */
-    public static function extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $enableLanguageToCountryGuess)
-    {
-        $langToCountry = self::getLanguageToCountryList();
+            return strtolower($string);
+        }
+
+        /*
+         * Escaping input
+         */
+
+        /**
+         * Returns the variable after cleaning operations.
+         * NB: The variable still has to be escaped before going into a SQL Query!
+         *
+         * If an array is passed the cleaning is done recursively on all the sub-arrays.
+         * The array's keys are filtered as well!
+         *
+         * How this method works:
+         * - The variable returned has been htmlspecialchars to avoid the XSS security problem.
+         * - The single quotes are not protected so "Piwik's amazing" will still be "Piwik's amazing".
+         *
+         * - Transformations are:
+         *         - '&' (ampersand) becomes '&amp;'
+         *         - '"'(double quote) becomes '&quot;'
+         *         - '<' (less than) becomes '&lt;'
+         *         - '>' (greater than) becomes '&gt;'
+         * - It handles the magic_quotes setting.
+         * - A non string value is returned without modification
+         *
+         * @param mixed $value The variable to be cleaned
+         * @param bool $alreadyStripslashed
+         * @throws Exception
+         * @return mixed  The variable after cleaning
+         */
+        public static function sanitizeInputValues($value, $alreadyStripslashed = false)
+        {
+            if (is_numeric($value)) {
+                return $value;
+            } elseif (is_string($value)) {
+                $value = \Piwik\Core\self::sanitizeInputValue($value);
+
+                if (!$alreadyStripslashed) // a JSON array was already stripslashed, don't do it again for each value
+                {
+                    $value = \Piwik\Core\self::undoMagicQuotes($value);
+                }
+            } elseif (is_array($value)) {
+                foreach (array_keys($value) as $key) {
+                    $newKey = $key;
+                    $newKey = \Piwik\Core\self::sanitizeInputValues($newKey, $alreadyStripslashed);
+                    if ($key != $newKey) {
+                        $value[$newKey] = $value[$key];
+                        unset($value[$key]);
+                    }
 
-        if ($enableLanguageToCountryGuess) {
-            if (preg_match('/^([a-z]{2,3})(?:,|;|$)/', $browserLanguage, $matches)) {
-                // match language (without region) to infer the country of origin
-                if (array_key_exists($matches[1], $langToCountry)) {
-                    return $langToCountry[$matches[1]];
+                    $value[$newKey] = \Piwik\Core\self::sanitizeInputValues($value[$newKey], $alreadyStripslashed);
                 }
+            } elseif (!is_null($value)
+                && !is_bool($value)
+            ) {
+                throw new Exception("The value to escape has not a supported type. Value = " . var_export($value, true));
             }
+            return $value;
         }
 
-        if (!empty($validCountries) && preg_match_all('/[-]([a-z]{2})/', $browserLanguage, $matches, PREG_SET_ORDER)) {
-            foreach ($matches as $parts) {
-                // match location; we don't make any inferences from the language
-                if (array_key_exists($parts[1], $validCountries)) {
-                    return $parts[1];
+        /**
+         * Sanitize a single input value
+         *
+         * @param string $value
+         * @return string  sanitized input
+         */
+        public static function sanitizeInputValue($value)
+        {
+            // $_GET and $_REQUEST already urldecode()'d
+            // decode
+            // note: before php 5.2.7, htmlspecialchars() double encodes &#x hex items
+            $value = html_entity_decode($value, \Piwik\Core\Piwik_Common::HTML_ENCODING_QUOTE_STYLE, 'UTF-8');
+
+            // filter
+            $value = str_replace(array("\n", "\r", "\0"), '', $value);
+
+            // escape
+            $tmp = @htmlspecialchars($value, \Piwik\Core\self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8');
+
+            // note: php 5.2.5 and above, htmlspecialchars is destructive if input is not UTF-8
+            if ($value != '' && $tmp == '') {
+                // convert and escape
+                $value = utf8_encode($value);
+                $tmp = htmlspecialchars($value, \Piwik\Core\self::HTML_ENCODING_QUOTE_STYLE, 'UTF-8');
+            }
+            return $tmp;
+        }
+
+        /**
+         * Unsanitize a single input value
+         *
+         * @param string $value
+         * @return string  unsanitized input
+         */
+        public static function unsanitizeInputValue($value)
+        {
+            return htmlspecialchars_decode($value, \Piwik\Core\self::HTML_ENCODING_QUOTE_STYLE);
+        }
+
+        /**
+         * Unsanitize one or more values.
+         *
+         * @param string|array $value
+         * @return string|array  unsanitized input
+         */
+        public static function unsanitizeInputValues($value)
+        {
+            if (is_array($value)) {
+                $result = array();
+                foreach ($value as $key => $arrayValue) {
+                    $result[$key] = \Piwik\Core\self::unsanitizeInputValues($arrayValue);
                 }
+                return $result;
+            } else {
+                return \Piwik\Core\self::unsanitizeInputValue($value);
             }
         }
-        return 'xx';
-    }
 
-    /**
-     * Returns the visitor language based only on the Browser 'accepted language' information
-     *
-     * @param string $browserLanguage  Browser's accepted langauge header
-     * @param array  $validLanguages   array of valid language codes
-     * @return string  2 letter ISO 639 code
-     */
-    public static function extractLanguageCodeFromBrowserLanguage($browserLanguage, $validLanguages)
-    {
-        // assumes language preference is sorted;
-        // does not handle language-script-region tags or language range (*)
-        if (!empty($validLanguages) && preg_match_all('/(?:^|,)([a-z]{2,3})([-][a-z]{2})?/', $browserLanguage, $matches, PREG_SET_ORDER)) {
-            foreach ($matches as $parts) {
-                if (count($parts) == 3) {
-                    // match locale (language and location)
-                    if (in_array($parts[1] . $parts[2], $validLanguages)) {
-                        return $parts[1] . $parts[2];
+        /**
+         * Undo the damage caused by magic_quotes; deprecated in php 5.3 but not removed until php 5.4
+         *
+         * @param string
+         * @return string  modified or not
+         */
+        public static function undoMagicQuotes($value)
+        {
+            return version_compare(PHP_VERSION, '5.4', '<')
+            && get_magic_quotes_gpc()
+                ? stripslashes($value)
+                : $value;
+        }
+
+        /**
+         * Returns a sanitized variable value from the $_GET and $_POST superglobal.
+         * If the variable doesn't have a value or an empty value, returns the defaultValue if specified.
+         * If the variable doesn't have neither a value nor a default value provided, an exception is raised.
+         *
+         * @see sanitizeInputValues() for the applied sanitization
+         *
+         * @param string $varName            name of the variable
+         * @param string $varDefault         default value. If '', and if the type doesn't match, exit() !
+         * @param string $varType            Expected type, the value must be one of the following: array, int, integer, string, json
+         * @param array $requestArrayToUse
+         *
+         * @throws Exception  if the variable type is not known
+         *                    or if the variable we want to read doesn't have neither a value nor a default value specified
+         *
+         * @return mixed The variable after cleaning
+         */
+        public static function getRequestVar($varName, $varDefault = null, $varType = null, $requestArrayToUse = null)
+        {
+            if (is_null($requestArrayToUse)) {
+                $requestArrayToUse = $_GET + $_POST;
+            }
+            $varDefault = \Piwik\Core\self::sanitizeInputValues($varDefault);
+            if ($varType === 'int') {
+                // settype accepts only integer
+                // 'int' is simply a shortcut for 'integer'
+                $varType = 'integer';
+            }
+
+            // there is no value $varName in the REQUEST so we try to use the default value
+            if (empty($varName)
+                || !isset($requestArrayToUse[$varName])
+                || (!is_array($requestArrayToUse[$varName])
+                    && strlen($requestArrayToUse[$varName]) === 0
+                )
+            ) {
+                if (is_null($varDefault)) {
+                    throw new Exception("The parameter '$varName' isn't set in the Request, and a default value wasn't provided.");
+                } else {
+                    if (!is_null($varType)
+                        && in_array($varType, array('string', 'integer', 'array'))
+                    ) {
+                        settype($varDefault, $varType);
                     }
+                    return $varDefault;
+                }
+            }
+
+            // Normal case, there is a value available in REQUEST for the requested varName:
+
+            // we deal w/ json differently
+            if ($varType == 'json') {
+                $value = \Piwik\Core\self::undoMagicQuotes($requestArrayToUse[$varName]);
+                $value = \Piwik\Core\Piwik_Common::json_decode($value, $assoc = true);
+                return \Piwik\Core\self::sanitizeInputValues($value, $alreadyStripslashed = true);
+            }
+
+            $value = \Piwik\Core\self::sanitizeInputValues($requestArrayToUse[$varName]);
+            if (!is_null($varType)) {
+                $ok = false;
+
+                if ($varType === 'string') {
+                    if (is_string($value)) $ok = true;
+                } elseif ($varType === 'integer') {
+                    if ($value == (string)(int)$value) $ok = true;
+                } elseif ($varType === 'float') {
+                    if ($value == (string)(float)$value) $ok = true;
+                } elseif ($varType === 'array') {
+                    if (is_array($value)) $ok = true;
+                } else {
+                    throw new Exception("\$varType specified is not known. It should be one of the following: array, int, integer, float, string");
                 }
-                // match language only (where no region provided)
-                if (in_array($parts[1], $validLanguages)) {
-                    return $parts[1];
+
+                // The type is not correct
+                if ($ok === false) {
+                    if ($varDefault === null) {
+                        throw new Exception("The parameter '$varName' doesn't have a correct type, and a default value wasn't provided.");
+                    } // we return the default value with the good type set
+                    else {
+                        settype($varDefault, $varType);
+                        return $varDefault;
+                    }
                 }
+                settype($value, $varType);
             }
+            return $value;
         }
-        return 'xx';
-    }
 
-    /**
-     * Returns the continent of a given country
-     *
-     * @param string $country  2 letters isocode
-     *
-     * @return string  Continent (3 letters code : afr, asi, eur, amn, ams, oce)
-     */
-    public static function getContinent($country)
-    {
-        $countryList = self::getCountriesList();
-        if (isset($countryList[$country])) {
-            return $countryList[$country];
+        /*
+         * Generating unique strings
+         */
+
+        /**
+         * Returns a 32 characters long uniq ID
+         *
+         * @return string 32 chars
+         */
+        public static function generateUniqId()
+        {
+            return md5(uniqid(rand(), true));
+        }
+
+        /**
+         * Get salt from [superuser] section
+         *
+         * @return string
+         */
+        public static function getSalt()
+        {
+            static $salt = null;
+            if (is_null($salt)) {
+                $salt = @Config::getInstance()->superuser['salt'];
+            }
+            return $salt;
+        }
+
+        /**
+         * Configureable hash() algorithm (defaults to md5)
+         *
+         * @param string $str String to be hashed
+         * @param bool $raw_output
+         * @return string Hash string
+         */
+        public static function hash($str, $raw_output = false)
+        {
+            static $hashAlgorithm = null;
+            if (is_null($hashAlgorithm)) {
+                $hashAlgorithm = @Config::getInstance()->General['hash_algorithm'];
+            }
+
+            if ($hashAlgorithm) {
+                $hash = @hash($hashAlgorithm, $str, $raw_output);
+                if ($hash !== false)
+                    return $hash;
+            }
+
+            return md5($str, $raw_output);
         }
-        return 'unk';
-    }
 
-    /*
-     * Campaign
-     */
+        /**
+         * Generate random string
+         *
+         * @param int $length string length
+         * @param string $alphabet characters allowed in random string
+         * @return string  random string with given length
+         */
+        public static function getRandomString($length = 16, $alphabet = "abcdefghijklmnoprstuvwxyz0123456789")
+        {
+            $chars = $alphabet;
+            $str = '';
 
-    /**
-     * Returns the list of Campaign parameter names that will be read to classify
-     * a visit as coming from a Campaign
-     *
-     * @return array array(
-     *            0 => array( ... ) // campaign names parameters
-     *            1 => array( ... ) // campaign keyword parameters
-     * );
-     */
-    public static function getCampaignParameters()
-    {
-        $return = array(
-            Config::getInstance()->Tracker['campaign_var_name'],
-            Config::getInstance()->Tracker['campaign_keyword_var_name'],
-        );
-
-        foreach ($return as &$list) {
-            if (strpos($list, ',') !== false) {
-                $list = explode(',', $list);
-            } else {
-                $list = array($list);
+            list($usec, $sec) = explode(" ", microtime());
+            $seed = ((float)$sec + (float)$usec) * 100000;
+            mt_srand($seed);
+
+            for ($i = 0; $i < $length; $i++) {
+                $rand_key = mt_rand(0, strlen($chars) - 1);
+                $str .= substr($chars, $rand_key, 1);
+            }
+            return str_shuffle($str);
+        }
+
+        /*
+         * Conversions
+         */
+
+        /**
+         * Convert hexadecimal representation into binary data.
+         * !! Will emit warning if input string is not hex!!
+         *
+         * @see http://php.net/bin2hex
+         *
+         * @param string $str  Hexadecimal representation
+         * @return string
+         */
+        public static function hex2bin($str)
+        {
+            return pack("H*", $str);
+        }
+
+        /**
+         * This function will convert the input string to the binary representation of the ID
+         * but it will throw an Exception if the specified input ID is not correct
+         *
+         * This is used when building segments containing visitorId which could be an invalid string
+         * therefore throwing Unexpected PHP error [pack(): Type H: illegal hex digit i] severity [E_WARNING]
+         *
+         * It would be simply to silent fail the pack() call above but in all other cases, we don't expect an error,
+         * so better be safe and get the php error when something unexpected is happening
+         * @param string $id
+         * @throws Exception
+         * @return string  binary string
+         */
+        public static function convertVisitorIdToBin($id)
+        {
+            if (strlen($id) !== Piwik_Tracker::LENGTH_HEX_ID_STRING
+                || @bin2hex(\Piwik\Core\self::hex2bin($id)) != $id
+            ) {
+                throw new Exception("visitorId is expected to be a " . Piwik_Tracker::LENGTH_HEX_ID_STRING . " hex char string");
+            }
+            return \Piwik\Core\self::hex2bin($id);
+        }
+
+        /**
+         * Convert IP address (in network address format) to presentation format.
+         * This is a backward compatibility function for code that only expects
+         * IPv4 addresses (i.e., doesn't support IPv6).
+         *
+         * @see Piwik_IP::N2P()
+         *
+         * This function does not support the long (or its string representation)
+         * returned by the built-in ip2long() function, from Piwik 1.3 and earlier.
+         *
+         * @deprecated 1.4
+         *
+         * @param string $ip  IP address in network address format
+         * @return string
+         */
+        public static function long2ip($ip)
+        {
+            return Piwik_IP::long2ip($ip);
+        }
+
+        /**
+         * Should we use the replacement json_encode/json_decode functions?
+         *
+         * @return bool  True if broken; false otherwise
+         */
+        private static function useJsonLibrary()
+        {
+            static $useLib;
+
+            if (!isset($useLib)) {
+                /*
+                 * 5.1.x - doesn't have json extension; we use lib/upgradephp instead
+                 * 5.2 to 5.2.4 - broken in various ways, including:
+                 *
+                 * @see https://bugs.php.net/bug.php?id=38680 'json_decode cannot decode basic types'
+                 * @see https://bugs.php.net/bug.php?id=41403 'json_decode cannot decode floats'
+                 * @see https://bugs.php.net/bug.php?id=42785 'json_encode outputs numbers according to locale'
+                 */
+                $useLib = false;
+                if (version_compare(PHP_VERSION, '5.2.1') < 0) {
+                    $useLib = true;
+                } else if (version_compare(PHP_VERSION, '5.2.5') < 0) {
+                    $info = localeconv();
+                    $useLib = $info['decimal_point'] != '.';
+                }
             }
+
+            return $useLib;
         }
 
-        array_walk_recursive($return, 'trim');
-        return $return;
-    }
+        /**
+         * JSON encode wrapper
+         * - missing or broken in some php 5.x versions
+         *
+         * @param mixed $value
+         * @return string
+         */
+        public static function json_encode($value)
+        {
+            if (\Piwik\Core\self::useJsonLibrary()) {
+                return _json_encode($value);
+            }
 
-    /*
-     * Referrer
-     */
+            return @json_encode($value);
+        }
+
+        /**
+         * JSON decode wrapper
+         * - missing or broken in some php 5.x versions
+         *
+         * @param string $json
+         * @param bool $assoc
+         * @return mixed
+         */
+        public static function json_decode($json, $assoc = false)
+        {
+            if (\Piwik\Core\self::useJsonLibrary()) {
+                return _json_decode($json, $assoc);
+            }
 
-    /**
-     * Reduce URL to more minimal form.  2 letter country codes are
-     * replaced by '{}', while other parts are simply removed.
-     *
-     * Examples:
-     *   www.example.com -> example.com
-     *   search.example.com -> example.com
-     *   m.example.com -> example.com
-     *   de.example.com -> {}.example.com
-     *   example.de -> example.{}
-     *   example.co.uk -> example.{}
-     *
-     * @param string $url
-     * @return string
-     */
-    public static function getLossyUrl($url)
-    {
-        static $countries;
-        if (!isset($countries)) {
-            $countries = implode('|', array_keys(self::getCountriesList(true)));
-        }
-
-        return preg_replace(
-            array(
-                 '/^(w+[0-9]*|search)\./',
-                 '/(^|\.)m\./',
-                 '/(\.(com|org|net|co|it|edu))?\.(' . $countries . ')(\/|$)/',
-                 '/(^|\.)(' . $countries . ')\./',
-            ),
-            array(
-                 '',
-                 '$1',
-                 '.{}$4',
-                 '$1{}.',
-            ),
-            $url);
-    }
+            return json_decode($json, $assoc);
+        }
+
+        /*
+         * DataFiles
+         */
+
+        /**
+         * Returns list of continent codes
+         *
+         * @see core/DataFiles/Countries.php
+         *
+         * @return array  Array of 3 letter continent codes
+         */
+        public static function getContinentsList()
+        {
+            require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php';
+
+            $continentsList = $GLOBALS['Piwik_ContinentList'];
+            return $continentsList;
+        }
+
+        /**
+         * Returns list of valid country codes
+         *
+         * @see core/DataFiles/Countries.php
+         *
+         * @param bool $includeInternalCodes
+         * @return array  Array of (2 letter ISO codes => 3 letter continent code)
+         */
+        public static function getCountriesList($includeInternalCodes = false)
+        {
+            require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Countries.php';
+
+            $countriesList = $GLOBALS['Piwik_CountryList'];
+            $extras = $GLOBALS['Piwik_CountryList_Extras'];
+
+            if ($includeInternalCodes) {
+                return array_merge($countriesList, $extras);
+            }
+            return $countriesList;
+        }
+
+        /**
+         * Returns list of valid language codes
+         *
+         * @see core/DataFiles/Languages.php
+         *
+         * @return array  Array of 2 letter ISO codes => Language name (in English)
+         */
+        public static function getLanguagesList()
+        {
+            require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Languages.php';
+
+            $languagesList = $GLOBALS['Piwik_LanguageList'];
+            return $languagesList;
+        }
+
+        /**
+         * Returns list of language to country mappings
+         *
+         * @see core/DataFiles/LanguageToCountry.php
+         *
+         * @return array  Array of ( 2 letter ISO language codes => 2 letter ISO country codes )
+         */
+        public static function getLanguageToCountryList()
+        {
+            require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/LanguageToCountry.php';
+
+            $languagesList = $GLOBALS['Piwik_LanguageToCountry'];
+            return $languagesList;
+        }
+
+        /**
+         * Returns list of search engines by URL
+         *
+         * @see core/DataFiles/SearchEngines.php
+         *
+         * @return array  Array of ( URL => array( searchEngineName, keywordParameter, path, charset ) )
+         */
+        public static function getSearchEngineUrls()
+        {
+            require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php';
+
+            $searchEngines = $GLOBALS['Piwik_SearchEngines'];
+            return $searchEngines;
+        }
+
+        /**
+         * Returns list of search engines by name
+         *
+         * @see core/DataFiles/SearchEngines.php
+         *
+         * @return array  Array of ( searchEngineName => URL )
+         */
+        public static function getSearchEngineNames()
+        {
+            require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/SearchEngines.php';
+
+            $searchEngines = $GLOBALS['Piwik_SearchEngines_NameToUrl'];
+            return $searchEngines;
+        }
+
+        /**
+         * Returns list of provider names
+         *
+         * @see core/DataFiles/Providers.php
+         *
+         * @return array  Array of ( dnsName => providerName )
+         */
+        public static function getProviderNames()
+        {
+            require_once PIWIK_INCLUDE_PATH . '/core/DataFiles/Providers.php';
+
+            $providers = $GLOBALS['Piwik_ProviderNames'];
+            return $providers;
+        }
+
+        /*
+         * Language, country, continent
+         */
+
+        /**
+         * Returns the browser language code, eg. "en-gb,en;q=0.5"
+         *
+         * @param string|null $browserLang  Optional browser language, otherwise taken from the request header
+         * @return string
+         */
+        public static function getBrowserLanguage($browserLang = NULL)
+        {
+            static $replacementPatterns = array(
+                // extraneous bits of RFC 3282 that we ignore
+                '/(\\\\.)/', // quoted-pairs
+                '/(\s+)/', // CFWcS white space
+                '/(\([^)]*\))/', // CFWS comments
+                '/(;q=[0-9.]+)/', // quality
+
+                // found in the LANG environment variable
+                '/\.(.*)/', // charset (e.g., en_CA.UTF-8)
+                '/^C$/', // POSIX 'C' locale
+            );
+
+            if (is_null($browserLang)) {
+                $browserLang = \Piwik\Core\self::sanitizeInputValues(@$_SERVER['HTTP_ACCEPT_LANGUAGE']);
+                if (empty($browserLang) && \Piwik\Core\self::isPhpCliMode()) {
+                    $browserLang = @getenv('LANG');
+                }
+            }
 
-    /**
-     * Extracts a keyword from a raw not encoded URL.
-     * Will only extract keyword if a known search engine has been detected.
-     * Returns the keyword:
-     * - in UTF8: automatically converted from other charsets when applicable
-     * - strtolowered: "QUErY test!" will return "query test!"
-     * - trimmed: extra spaces before and after are removed
-     *
-     * Lists of supported search engines can be found in /core/DataFiles/SearchEngines.php
-     * The function returns false when a keyword couldn't be found.
-     *     eg. if the url is "http://www.google.com/partners.html" this will return false,
-     *       as the google keyword parameter couldn't be found.
-     *
-     * @see unit tests in /tests/core/Common.test.php
-     * @param string $referrerUrl  URL referer URL, eg. $_SERVER['HTTP_REFERER']
-     * @return array|false false if a keyword couldn't be extracted,
-     *                        or array(
-     *                            'name' => 'Google',
-     *                            'keywords' => 'my searched keywords')
-     */
-    public static function extractSearchEngineInformationFromUrl($referrerUrl)
-    {
-        $refererParsed = @parse_url($referrerUrl);
-        $refererHost = '';
-        if (isset($refererParsed['host'])) {
-            $refererHost = $refererParsed['host'];
-        }
-        if (empty($refererHost)) {
-            return false;
-        }
-        // some search engines (eg. Bing Images) use the same domain
-        // as an existing search engine (eg. Bing), we must also use the url path
-        $refererPath = '';
-        if (isset($refererParsed['path'])) {
-            $refererPath = $refererParsed['path'];
-        }
-
-        // no search query
-        if (!isset($refererParsed['query'])) {
-            $refererParsed['query'] = '';
-        }
-        $query = $refererParsed['query'];
-
-        // Google Referrers URLs sometimes have the fragment which contains the keyword
-        if (!empty($refererParsed['fragment'])) {
-            $query .= '&' . $refererParsed['fragment'];
-        }
-
-        $searchEngines = self::getSearchEngineUrls();
-
-        $hostPattern = self::getLossyUrl($refererHost);
-        if (array_key_exists($refererHost . $refererPath, $searchEngines)) {
-            $refererHost = $refererHost . $refererPath;
-        } elseif (array_key_exists($hostPattern . $refererPath, $searchEngines)) {
-            $refererHost = $hostPattern . $refererPath;
-        } elseif (array_key_exists($hostPattern, $searchEngines)) {
-            $refererHost = $hostPattern;
-        } elseif (!array_key_exists($refererHost, $searchEngines)) {
-            if (!strncmp($query, 'cx=partner-pub-', 15)) {
-                // Google custom search engine
-                $refererHost = 'google.com/cse';
-            } elseif (!strncmp($refererPath, '/pemonitorhosted/ws/results/', 28)) {
-                // private-label search powered by InfoSpace Metasearch
-                $refererHost = 'wsdsold.infospace.com';
-            } elseif (strpos($refererHost, '.images.search.yahoo.com') != false) {
-                // Yahoo! Images
-                $refererHost = 'images.search.yahoo.com';
-            } elseif (strpos($refererHost, '.search.yahoo.com') != false) {
-                // Yahoo!
-                $refererHost = 'search.yahoo.com';
+            if (is_null($browserLang)) {
+                // a fallback might be to infer the language in HTTP_USER_AGENT (i.e., localized build)
+                $browserLang = "";
             } else {
-                return false;
+                // language tags are case-insensitive per HTTP/1.1 s3.10 but the region may be capitalized per ISO3166-1;
+                // underscores are not permitted per RFC 4646 or 4647 (which obsolete RFC 1766 and 3066),
+                // but we guard against a bad user agent which naively uses its locale
+                $browserLang = strtolower(str_replace('_', '-', $browserLang));
+
+                // filters
+                $browserLang = preg_replace($replacementPatterns, '', $browserLang);
+
+                $browserLang = preg_replace('/((^|,)chrome:.*)/', '', $browserLang, 1); // Firefox bug
+                $browserLang = preg_replace('/(,)(?:en-securid,)|(?:(^|,)en-securid(,|$))/', '$1', $browserLang, 1); // unregistered language tag
+
+                $browserLang = str_replace('sr-sp', 'sr-rs', $browserLang); // unofficial (proposed) code in the wild
             }
+
+            return $browserLang;
+        }
+
+        /**
+         * Returns the visitor country based on the Browser 'accepted language'
+         * information, but provides a hook for geolocation via IP address.
+         *
+         * @param string $lang                          browser lang
+         * @param bool $enableLanguageToCountryGuess  If set to true, some assumption will be made and detection guessed more often, but accuracy could be affected
+         * @param string $ip
+         * @return string  2 letter ISO code
+         */
+        public static function getCountry($lang, $enableLanguageToCountryGuess, $ip)
+        {
+            $country = null;
+            Piwik_PostEvent('Common.getCountry', array(&$country, $ip));
+            if (!empty($country)) {
+                return strtolower($country);
+            }
+
+            if (empty($lang) || strlen($lang) < 2 || $lang == 'xx') {
+                return 'xx';
+            }
+
+            $validCountries = \Piwik\Core\self::getCountriesList();
+            return \Piwik\Core\self::extractCountryCodeFromBrowserLanguage($lang, $validCountries, $enableLanguageToCountryGuess);
+        }
+
+        /**
+         * Returns list of valid country codes
+         *
+         * @param string $browserLanguage
+         * @param array $validCountries                 Array of valid countries
+         * @param bool $enableLanguageToCountryGuess  (if true, will guess country based on language that lacks region information)
+         * @return array Array of 2 letter ISO codes
+         */
+        public static function extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $enableLanguageToCountryGuess)
+        {
+            $langToCountry = \Piwik\Core\self::getLanguageToCountryList();
+
+            if ($enableLanguageToCountryGuess) {
+                if (preg_match('/^([a-z]{2,3})(?:,|;|$)/', $browserLanguage, $matches)) {
+                    // match language (without region) to infer the country of origin
+                    if (array_key_exists($matches[1], $langToCountry)) {
+                        return $langToCountry[$matches[1]];
+                    }
+                }
+            }
+
+            if (!empty($validCountries) && preg_match_all('/[-]([a-z]{2})/', $browserLanguage, $matches, PREG_SET_ORDER)) {
+                foreach ($matches as $parts) {
+                    // match location; we don't make any inferences from the language
+                    if (array_key_exists($parts[1], $validCountries)) {
+                        return $parts[1];
+                    }
+                }
+            }
+            return 'xx';
         }
-        $searchEngineName = $searchEngines[$refererHost][0];
-        $variableNames = null;
-        if (isset($searchEngines[$refererHost][1])) {
-            $variableNames = $searchEngines[$refererHost][1];
-        }
-        if (!$variableNames) {
-            $searchEngineNames = self::getSearchEngineNames();
-            $url = $searchEngineNames[$searchEngineName];
-            $variableNames = $searchEngines[$url][1];
-        }
-        if (!is_array($variableNames)) {
-            $variableNames = array($variableNames);
+
+        /**
+         * Returns the visitor language based only on the Browser 'accepted language' information
+         *
+         * @param string $browserLanguage  Browser's accepted langauge header
+         * @param array $validLanguages   array of valid language codes
+         * @return string  2 letter ISO 639 code
+         */
+        public static function extractLanguageCodeFromBrowserLanguage($browserLanguage, $validLanguages)
+        {
+            // assumes language preference is sorted;
+            // does not handle language-script-region tags or language range (*)
+            if (!empty($validLanguages) && preg_match_all('/(?:^|,)([a-z]{2,3})([-][a-z]{2})?/', $browserLanguage, $matches, PREG_SET_ORDER)) {
+                foreach ($matches as $parts) {
+                    if (count($parts) == 3) {
+                        // match locale (language and location)
+                        if (in_array($parts[1] . $parts[2], $validLanguages)) {
+                            return $parts[1] . $parts[2];
+                        }
+                    }
+                    // match language only (where no region provided)
+                    if (in_array($parts[1], $validLanguages)) {
+                        return $parts[1];
+                    }
+                }
+            }
+            return 'xx';
         }
 
-        $key = null;
-        if ($searchEngineName === 'Google Images'
-            || ($searchEngineName === 'Google' && strpos($referrerUrl, '/imgres') !== false)
-        ) {
-            if (strpos($query, '&prev') !== false) {
-                $query = urldecode(trim(self::getParameterFromQueryString($query, 'prev')));
-                $query = str_replace('&', '&amp;', strstr($query, '?'));
+        /**
+         * Returns the continent of a given country
+         *
+         * @param string $country  2 letters isocode
+         *
+         * @return string  Continent (3 letters code : afr, asi, eur, amn, ams, oce)
+         */
+        public static function getContinent($country)
+        {
+            $countryList = \Piwik\Core\self::getCountriesList();
+            if (isset($countryList[$country])) {
+                return $countryList[$country];
             }
-            $searchEngineName = 'Google Images';
-        } else if ($searchEngineName === 'Google'
-            && (strpos($query, '&as_') !== false || strpos($query, 'as_') === 0)
-        ) {
-            $keys = array();
-            $key = self::getParameterFromQueryString($query, 'as_q');
-            if (!empty($key)) {
-                array_push($keys, $key);
+            return 'unk';
+        }
+
+        /*
+         * Campaign
+         */
+
+        /**
+         * Returns the list of Campaign parameter names that will be read to classify
+         * a visit as coming from a Campaign
+         *
+         * @return array array(
+         *            0 => array( ... ) // campaign names parameters
+         *            1 => array( ... ) // campaign keyword parameters
+         * );
+         */
+        public static function getCampaignParameters()
+        {
+            $return = array(
+                Config::getInstance()->Tracker['campaign_var_name'],
+                Config::getInstance()->Tracker['campaign_keyword_var_name'],
+            );
+
+            foreach ($return as &$list) {
+                if (strpos($list, ',') !== false) {
+                    $list = explode(',', $list);
+                } else {
+                    $list = array($list);
+                }
             }
-            $key = self::getParameterFromQueryString($query, 'as_oq');
-            if (!empty($key)) {
-                array_push($keys, str_replace('+', ' OR ', $key));
+
+            array_walk_recursive($return, 'trim');
+            return $return;
+        }
+
+        /*
+         * Referrer
+         */
+
+        /**
+         * Reduce URL to more minimal form.  2 letter country codes are
+         * replaced by '{}', while other parts are simply removed.
+         *
+         * Examples:
+         *   www.example.com -> example.com
+         *   search.example.com -> example.com
+         *   m.example.com -> example.com
+         *   de.example.com -> {}.example.com
+         *   example.de -> example.{}
+         *   example.co.uk -> example.{}
+         *
+         * @param string $url
+         * @return string
+         */
+        public static function getLossyUrl($url)
+        {
+            static $countries;
+            if (!isset($countries)) {
+                $countries = implode('|', array_keys(\Piwik\Core\self::getCountriesList(true)));
             }
-            $key = self::getParameterFromQueryString($query, 'as_epq');
-            if (!empty($key)) {
-                array_push($keys, "\"$key\"");
+
+            return preg_replace(
+                array(
+                    '/^(w+[0-9]*|search)\./',
+                    '/(^|\.)m\./',
+                    '/(\.(com|org|net|co|it|edu))?\.(' . $countries . ')(\/|$)/',
+                    '/(^|\.)(' . $countries . ')\./',
+                ),
+                array(
+                    '',
+                    '$1',
+                    '.{}$4',
+                    '$1{}.',
+                ),
+                $url);
+        }
+
+        /**
+         * Extracts a keyword from a raw not encoded URL.
+         * Will only extract keyword if a known search engine has been detected.
+         * Returns the keyword:
+         * - in UTF8: automatically converted from other charsets when applicable
+         * - strtolowered: "QUErY test!" will return "query test!"
+         * - trimmed: extra spaces before and after are removed
+         *
+         * Lists of supported search engines can be found in /core/DataFiles/SearchEngines.php
+         * The function returns false when a keyword couldn't be found.
+         *     eg. if the url is "http://www.google.com/partners.html" this will return false,
+         *       as the google keyword parameter couldn't be found.
+         *
+         * @see unit tests in /tests/core/Common.test.php
+         * @param string $referrerUrl  URL referer URL, eg. $_SERVER['HTTP_REFERER']
+         * @return array|false false if a keyword couldn't be extracted,
+         *                        or array(
+         *                            'name' => 'Google',
+         *                            'keywords' => 'my searched keywords')
+         */
+        public static function extractSearchEngineInformationFromUrl($referrerUrl)
+        {
+            $refererParsed = @parse_url($referrerUrl);
+            $refererHost = '';
+            if (isset($refererParsed['host'])) {
+                $refererHost = $refererParsed['host'];
             }
-            $key = self::getParameterFromQueryString($query, 'as_eq');
-            if (!empty($key)) {
-                array_push($keys, "-$key");
+            if (empty($refererHost)) {
+                return false;
+            }
+            // some search engines (eg. Bing Images) use the same domain
+            // as an existing search engine (eg. Bing), we must also use the url path
+            $refererPath = '';
+            if (isset($refererParsed['path'])) {
+                $refererPath = $refererParsed['path'];
             }
-            $key = trim(urldecode(implode(' ', $keys)));
-        }
 
-        if ($searchEngineName === 'Google') {
-            // top bar menu
-            $tbm = self::getParameterFromQueryString($query, 'tbm');
-            switch ($tbm) {
-                case 'isch':
-                    $searchEngineName = 'Google Images';
-                    break;
-                case 'vid':
-                    $searchEngineName = 'Google Video';
-                    break;
-                case 'shop':
-                    $searchEngineName = 'Google Shopping';
-                    break;
+            // no search query
+            if (!isset($refererParsed['query'])) {
+                $refererParsed['query'] = '';
             }
-        }
+            $query = $refererParsed['query'];
 
-        if (empty($key)) {
-            foreach ($variableNames as $variableName) {
-                if ($variableName[0] == '/') {
-                    // regular expression match
-                    if (preg_match($variableName, $referrerUrl, $matches)) {
-                        $key = trim(urldecode($matches[1]));
-                        break;
-                    }
+            // Google Referrers URLs sometimes have the fragment which contains the keyword
+            if (!empty($refererParsed['fragment'])) {
+                $query .= '&' . $refererParsed['fragment'];
+            }
+
+            $searchEngines = \Piwik\Core\self::getSearchEngineUrls();
+
+            $hostPattern = \Piwik\Core\self::getLossyUrl($refererHost);
+            if (array_key_exists($refererHost . $refererPath, $searchEngines)) {
+                $refererHost = $refererHost . $refererPath;
+            } elseif (array_key_exists($hostPattern . $refererPath, $searchEngines)) {
+                $refererHost = $hostPattern . $refererPath;
+            } elseif (array_key_exists($hostPattern, $searchEngines)) {
+                $refererHost = $hostPattern;
+            } elseif (!array_key_exists($refererHost, $searchEngines)) {
+                if (!strncmp($query, 'cx=partner-pub-', 15)) {
+                    // Google custom search engine
+                    $refererHost = 'google.com/cse';
+                } elseif (!strncmp($refererPath, '/pemonitorhosted/ws/results/', 28)) {
+                    // private-label search powered by InfoSpace Metasearch
+                    $refererHost = 'wsdsold.infospace.com';
+                } elseif (strpos($refererHost, '.images.search.yahoo.com') != false) {
+                    // Yahoo! Images
+                    $refererHost = 'images.search.yahoo.com';
+                } elseif (strpos($refererHost, '.search.yahoo.com') != false) {
+                    // Yahoo!
+                    $refererHost = 'search.yahoo.com';
                 } else {
-                    // search for keywords now &vname=keyword
-                    $key = self::getParameterFromQueryString($query, $variableName);
-                    $key = trim(urldecode($key));
-
-                    // Special case: Google & empty q parameter
-                    if (empty($key)
-                        && $variableName == 'q'
-
-                        && (
-                            // Google search with no keyword
-                            ($searchEngineName == 'Google'
-                                && ( // First, they started putting an empty q= parameter
-                                    strpos($query, '&q=') !== false
+                    return false;
+                }
+            }
+            $searchEngineName = $searchEngines[$refererHost][0];
+            $variableNames = null;
+            if (isset($searchEngines[$refererHost][1])) {
+                $variableNames = $searchEngines[$refererHost][1];
+            }
+            if (!$variableNames) {
+                $searchEngineNames = \Piwik\Core\self::getSearchEngineNames();
+                $url = $searchEngineNames[$searchEngineName];
+                $variableNames = $searchEngines[$url][1];
+            }
+            if (!is_array($variableNames)) {
+                $variableNames = array($variableNames);
+            }
+
+            $key = null;
+            if ($searchEngineName === 'Google Images'
+                || ($searchEngineName === 'Google' && strpos($referrerUrl, '/imgres') !== false)
+            ) {
+                if (strpos($query, '&prev') !== false) {
+                    $query = urldecode(trim(\Piwik\Core\self::getParameterFromQueryString($query, 'prev')));
+                    $query = str_replace('&', '&amp;', strstr($query, '?'));
+                }
+                $searchEngineName = 'Google Images';
+            } else if ($searchEngineName === 'Google'
+                && (strpos($query, '&as_') !== false || strpos($query, 'as_') === 0)
+            ) {
+                $keys = array();
+                $key = \Piwik\Core\self::getParameterFromQueryString($query, 'as_q');
+                if (!empty($key)) {
+                    array_push($keys, $key);
+                }
+                $key = \Piwik\Core\self::getParameterFromQueryString($query, 'as_oq');
+                if (!empty($key)) {
+                    array_push($keys, str_replace('+', ' OR ', $key));
+                }
+                $key = \Piwik\Core\self::getParameterFromQueryString($query, 'as_epq');
+                if (!empty($key)) {
+                    array_push($keys, "\"$key\"");
+                }
+                $key = \Piwik\Core\self::getParameterFromQueryString($query, 'as_eq');
+                if (!empty($key)) {
+                    array_push($keys, "-$key");
+                }
+                $key = trim(urldecode(implode(' ', $keys)));
+            }
+
+            if ($searchEngineName === 'Google') {
+                // top bar menu
+                $tbm = \Piwik\Core\self::getParameterFromQueryString($query, 'tbm');
+                switch ($tbm) {
+                    case 'isch':
+                        $searchEngineName = 'Google Images';
+                        break;
+                    case 'vid':
+                        $searchEngineName = 'Google Video';
+                        break;
+                    case 'shop':
+                        $searchEngineName = 'Google Shopping';
+                        break;
+                }
+            }
+
+            if (empty($key)) {
+                foreach ($variableNames as $variableName) {
+                    if ($variableName[0] == '/') {
+                        // regular expression match
+                        if (preg_match($variableName, $referrerUrl, $matches)) {
+                            $key = trim(urldecode($matches[1]));
+                            break;
+                        }
+                    } else {
+                        // search for keywords now &vname=keyword
+                        $key = \Piwik\Core\self::getParameterFromQueryString($query, $variableName);
+                        $key = trim(urldecode($key));
+
+                        // Special case: Google & empty q parameter
+                        if (empty($key)
+                            && $variableName == 'q'
+
+                            && (
+                                // Google search with no keyword
+                                ($searchEngineName == 'Google'
+                                    && ( // First, they started putting an empty q= parameter
+                                        strpos($query, '&q=') !== false
                                         || strpos($query, '?q=') !== false
                                         // then they started sending the full host only (no path/query string)
                                         || (empty($query) && (empty($refererPath) || $refererPath == '/') && empty($refererParsed['fragment']))
+                                    )
                                 )
-                            )
                                 // search engines with no keyword
                                 || $searchEngineName == 'Google Images'
                                 || $searchEngineName == 'DuckDuckGo')
-                    ) {
-                        $key = false;
-                    }
-                    if (!empty($key)
-                        || $key === false
-                    ) {
-                        break;
+                        ) {
+                            $key = false;
+                        }
+                        if (!empty($key)
+                            || $key === false
+                        ) {
+                            break;
+                        }
                     }
                 }
             }
-        }
-
-        // $key === false is the special case "No keyword provided" which is a Search engine match
-        if ($key === null
-            || $key === ''
-        ) {
-            return false;
-        }
 
-        if (!empty($key)) {
-            if (function_exists('iconv')
-                && isset($searchEngines[$refererHost][3])
+            // $key === false is the special case "No keyword provided" which is a Search engine match
+            if ($key === null
+                || $key === ''
             ) {
-                // accepts string, array, or comma-separated list string in preferred order
-                $charsets = $searchEngines[$refererHost][3];
-                if (!is_array($charsets)) {
-                    $charsets = explode(',', $charsets);
-                }
+                return false;
+            }
 
-                if (!empty($charsets)) {
-                    $charset = $charsets[0];
-                    if (count($charsets) > 1
-                        && function_exists('mb_detect_encoding')
-                    ) {
-                        $charset = mb_detect_encoding($key, $charsets);
-                        if ($charset === false) {
-                            $charset = $charsets[0];
-                        }
+            if (!empty($key)) {
+                if (function_exists('iconv')
+                    && isset($searchEngines[$refererHost][3])
+                ) {
+                    // accepts string, array, or comma-separated list string in preferred order
+                    $charsets = $searchEngines[$refererHost][3];
+                    if (!is_array($charsets)) {
+                        $charsets = explode(',', $charsets);
                     }
 
-                    $newkey = @iconv($charset, 'UTF-8//IGNORE', $key);
-                    if (!empty($newkey)) {
-                        $key = $newkey;
+                    if (!empty($charsets)) {
+                        $charset = $charsets[0];
+                        if (count($charsets) > 1
+                            && function_exists('mb_detect_encoding')
+                        ) {
+                            $charset = mb_detect_encoding($key, $charsets);
+                            if ($charset === false) {
+                                $charset = $charsets[0];
+                            }
+                        }
+
+                        $newkey = @iconv($charset, 'UTF-8//IGNORE', $key);
+                        if (!empty($newkey)) {
+                            $key = $newkey;
+                        }
                     }
                 }
-            }
-
-            $key = self::mb_strtolower($key);
-        }
 
-        return array(
-            'name'     => $searchEngineName,
-            'keywords' => $key,
-        );
-    }
-
-    /*
-     * System environment
-     */
+                $key = \Piwik\Core\self::mb_strtolower($key);
+            }
 
-    /**
-     * Returns true if PHP was invoked from command-line interface (shell)
-     *
-     * @since added in 0.4.4
-     * @return bool true if PHP invoked as a CGI or from CLI
-     */
-    public static function isPhpCliMode()
-    {
-        $remoteAddr = @$_SERVER['REMOTE_ADDR'];
-        return PHP_SAPI == 'cli' ||
+            return array(
+                'name' => $searchEngineName,
+                'keywords' => $key,
+            );
+        }
+
+        /*
+         * System environment
+         */
+
+        /**
+         * Returns true if PHP was invoked from command-line interface (shell)
+         *
+         * @since added in 0.4.4
+         * @return bool true if PHP invoked as a CGI or from CLI
+         */
+        public static function isPhpCliMode()
+        {
+            $remoteAddr = @$_SERVER['REMOTE_ADDR'];
+            return PHP_SAPI == 'cli' ||
             (!strncmp(PHP_SAPI, 'cgi', 3) && empty($remoteAddr));
-    }
+        }
 
-    /**
-     * Is the current script execution triggered by misc/cron/archive.php ?
-     *
-     * Helpful for error handling: directly throw error without HTML (eg. when DB is down)
-     * @return bool
-     */
-    public static function isArchivePhpTriggered()
-    {
-        return !empty($_GET['trigger'])
+        /**
+         * Is the current script execution triggered by misc/cron/archive.php ?
+         *
+         * Helpful for error handling: directly throw error without HTML (eg. when DB is down)
+         * @return bool
+         */
+        public static function isArchivePhpTriggered()
+        {
+            return !empty($_GET['trigger'])
             && $_GET['trigger'] == 'archivephp';
-    }
+        }
 
-    /**
-     * Assign CLI parameters as if they were REQUEST or GET parameters.
-     * You can trigger Piwik from the command line by
-     * # /usr/bin/php5 /path/to/piwik/index.php -- "module=API&method=Actions.getActions&idSite=1&period=day&date=previous8&format=php"
-     */
-    public static function assignCliParametersToRequest()
-    {
-        if (isset($_SERVER['argc'])
-            && $_SERVER['argc'] > 0
-        ) {
-            for ($i = 1; $i < $_SERVER['argc']; $i++) {
-                parse_str($_SERVER['argv'][$i], $tmp);
-                $_GET = array_merge($_GET, $tmp);
+        /**
+         * Assign CLI parameters as if they were REQUEST or GET parameters.
+         * You can trigger Piwik from the command line by
+         * # /usr/bin/php5 /path/to/piwik/index.php -- "module=API&method=Actions.getActions&idSite=1&period=day&date=previous8&format=php"
+         */
+        public static function assignCliParametersToRequest()
+        {
+            if (isset($_SERVER['argc'])
+                && $_SERVER['argc'] > 0
+            ) {
+                for ($i = 1; $i < $_SERVER['argc']; $i++) {
+                    parse_str($_SERVER['argv'][$i], $tmp);
+                    $_GET = array_merge($_GET, $tmp);
+                }
             }
         }
-    }
-
-    /**
-     * Returns true if running on a Windows operating system
-     *
-     * @since 0.6.5
-     * @return bool true if PHP detects it is running on Windows; else false
-     */
-    public static function isWindows()
-    {
-        return DIRECTORY_SEPARATOR === '\\';
-    }
-
-    /**
-     * Returns true if running on MacOS
-     *
-     * @return bool true if PHP detects it is running on MacOS; else false
-     */
-    public static function isMacOS()
-    {
-        return PHP_OS === 'Darwin';
-    }
-
-    /**
-     * Returns true if running on an Apache web server
-     *
-     * @return bool
-     */
-    public static function isApache()
-    {
-        $apache = isset($_SERVER['SERVER_SOFTWARE']) &&
-            !strncmp($_SERVER['SERVER_SOFTWARE'], 'Apache', 6);
-
-        return $apache;
-    }
-
-    /**
-     * Returns true if running on Microsoft IIS 7 (or above)
-     *
-     * @return bool
-     */
-    public static function isIIS()
-    {
-        $iis = isset($_SERVER['SERVER_SOFTWARE']) &&
-            preg_match('/^Microsoft-IIS\/(.+)/', $_SERVER['SERVER_SOFTWARE'], $matches) &&
-            version_compare($matches[1], '7') >= 0;
-
-        return $iis;
-    }
 
-    /**
-     * Takes a list of fields defining numeric values and returns the corresponding
-     * unnamed parameters to be bound to the field names in the where clause of a SQL query
-     *
-     * @param array|string $fields  array( fieldName1, fieldName2, fieldName3)  Names of the mysql table fields to load
-     * @return string "?, ?, ?"
-     */
-    public static function getSqlStringFieldsArray($fields)
-    {
-        if (is_string($fields)) {
-            $fields = array($fields);
+        /**
+         * Returns true if running on a Windows operating system
+         *
+         * @since 0.6.5
+         * @return bool true if PHP detects it is running on Windows; else false
+         */
+        public static function isWindows()
+        {
+            return DIRECTORY_SEPARATOR === '\\';
+        }
+
+        /**
+         * Returns true if running on MacOS
+         *
+         * @return bool true if PHP detects it is running on MacOS; else false
+         */
+        public static function isMacOS()
+        {
+            return PHP_OS === 'Darwin';
+        }
+
+        /**
+         * Returns true if running on an Apache web server
+         *
+         * @return bool
+         */
+        public static function isApache()
+        {
+            $apache = isset($_SERVER['SERVER_SOFTWARE']) &&
+                !strncmp($_SERVER['SERVER_SOFTWARE'], 'Apache', 6);
+
+            return $apache;
+        }
+
+        /**
+         * Returns true if running on Microsoft IIS 7 (or above)
+         *
+         * @return bool
+         */
+        public static function isIIS()
+        {
+            $iis = isset($_SERVER['SERVER_SOFTWARE']) &&
+                preg_match('/^Microsoft-IIS\/(.+)/', $_SERVER['SERVER_SOFTWARE'], $matches) &&
+                version_compare($matches[1], '7') >= 0;
+
+            return $iis;
+        }
+
+        /**
+         * Takes a list of fields defining numeric values and returns the corresponding
+         * unnamed parameters to be bound to the field names in the where clause of a SQL query
+         *
+         * @param array|string $fields  array( fieldName1, fieldName2, fieldName3)  Names of the mysql table fields to load
+         * @return string "?, ?, ?"
+         */
+        public static function getSqlStringFieldsArray($fields)
+        {
+            if (is_string($fields)) {
+                $fields = array($fields);
+            }
+            $count = count($fields);
+            if ($count == 0) {
+                return "''";
+            }
+            return '?' . str_repeat(',?', $count - 1);
+        }
+
+        /**
+         * Sets outgoing header.
+         *
+         * @param string $header The header.
+         * @param bool $replace Whether to replace existing or not.
+         */
+        public static function sendHeader($header, $replace = true)
+        {
+            if (isset($GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING']) && $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING']) {
+                @header($header, $replace);
+            } else {
+                header($header, $replace);
+            }
         }
-        $count = count($fields);
-        if ($count == 0) {
-            return "''";
+
+        /**
+         * Returns the ID of the current LocationProvider (see UserCountry plugin code) from
+         * the Tracker cache.
+         */
+        public static function getCurrentLocationProviderId()
+        {
+            $cache = Piwik_Tracker_Cache::getCacheGeneral();
+            return empty($cache['currentLocationProviderId'])
+                ? Piwik_UserCountry_LocationProvider_Default::ID
+                : $cache['currentLocationProviderId'];
+        }
+
+        /**
+         * Unprefix class name (if needed)
+         *
+         * @param string $class
+         * @return string
+         */
+        public static function unprefixClass($class)
+        {
+            $lenPrefix = strlen(\Piwik\Core\self::CLASSES_PREFIX);
+            if (!strncmp($class, \Piwik\Core\self::CLASSES_PREFIX, $lenPrefix)) {
+                return substr($class, $lenPrefix);
+            }
+            return $class;
         }
-        return '?' . str_repeat(',?', $count - 1);
     }
-
+}
+namespace {
     /**
-     * Sets outgoing header.
+     * Piwik - Open source web analytics
      *
-     * @param string $header The header.
-     * @param bool $replace Whether to replace existing or not.
+     * @link http://piwik.org
+     * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+     *
+     * @category Piwik
+     * @package Piwik
      */
-    public static function sendHeader($header, $replace = true)
-    {
-        if (isset($GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING']) && $GLOBALS['PIWIK_TRACKER_LOCAL_TRACKING']) {
-            @header($header, $replace);
-        } else {
-            header($header, $replace);
-        }
-    }
+    use Piwik\Core\Config;
 
-    /**
-     * Returns the ID of the current LocationProvider (see UserCountry plugin code) from
-     * the Tracker cache.
-     */
-    public static function getCurrentLocationProviderId()
-    {
-        $cache = Piwik_Tracker_Cache::getCacheGeneral();
-        return empty($cache['currentLocationProviderId'])
-            ? Piwik_UserCountry_LocationProvider_Default::ID
-            : $cache['currentLocationProviderId'];
-    }
 
     /**
-     * Unprefix class name (if needed)
+     * Mark orphaned object for garbage collection
      *
-     * @param string $class
-     * @return string
+     * For more information: @link http://dev.piwik.org/trac/ticket/374
+     * @param $var
      */
-    public static function unprefixClass($class)
+    function destroy(&$var)
     {
-        $lenPrefix = strlen(self::CLASSES_PREFIX);
-        if (!strncmp($class, self::CLASSES_PREFIX, $lenPrefix)) {
-            return substr($class, $lenPrefix);
+        if (is_object($var) && method_exists($var, '__destruct')) {
+            $var->__destruct();
         }
-        return $class;
+        unset($var);
+        $var = null;
     }
-}
-
-/**
- * Mark orphaned object for garbage collection
- *
- * For more information: @link http://dev.piwik.org/trac/ticket/374
- * @param $var
- */
-function destroy(&$var)
-{
-    if (is_object($var) && method_exists($var, '__destruct')) {
-        $var->__destruct();
-    }
-    unset($var);
-    $var = null;
-}
 
-if (!function_exists('printDebug')) {
-    function printDebug($info = '')
-    {
-        if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) {
-            if (is_array($info) || is_object($info)) {
-                print("<pre>");
-                print(htmlspecialchars(var_export($info, true), ENT_QUOTES));
-                print("</pre>");
-            } else {
-                print(htmlspecialchars($info, ENT_QUOTES) . "<br />\n");
+    if (!function_exists('printDebug')) {
+        function printDebug($info = '')
+        {
+            if (isset($GLOBALS['PIWIK_TRACKER_DEBUG']) && $GLOBALS['PIWIK_TRACKER_DEBUG']) {
+                if (is_array($info) || is_object($info)) {
+                    print("<pre>");
+                    print(htmlspecialchars(var_export($info, true), ENT_QUOTES));
+                    print("</pre>");
+                } else {
+                    print(htmlspecialchars($info, ENT_QUOTES) . "<br />\n");
+                }
             }
         }
     }
diff --git a/core/Controller.php b/core/Controller.php
index b2e4dfa29598f5588efe72969d212669acbc04ec..bfb37b59d87f3f4717064cff5afe712c234b34ac 100644
--- a/core/Controller.php
+++ b/core/Controller.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Parent class of all plugins Controllers (located in /plugins/PluginName/Controller.php
diff --git a/core/Cookie.php b/core/Cookie.php
index 69cd83c188e60eb4795d1d8ae87e023280f3f028..8165a6bc36a834e7522652ace9e4ffe390faf052 100644
--- a/core/Cookie.php
+++ b/core/Cookie.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Simple class to handle the cookies:
diff --git a/core/DataAccess/ArchiveSelector.php b/core/DataAccess/ArchiveSelector.php
index 299b292a49a857a7ff666ec74d83f1612cb2cea3..46b677d7e8f8c302b39b247474705decb174d4af 100644
--- a/core/DataAccess/ArchiveSelector.php
+++ b/core/DataAccess/ArchiveSelector.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Data Access object used to query archives
diff --git a/core/DataAccess/ArchiveTableCreator.php b/core/DataAccess/ArchiveTableCreator.php
index d7c344665478f53f888faa2b9dce8f3652c9feb2..e501a9b28a2820dd9c3aba984b06f9322d646d6f 100644
--- a/core/DataAccess/ArchiveTableCreator.php
+++ b/core/DataAccess/ArchiveTableCreator.php
@@ -1,5 +1,6 @@
 <?php
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/core/DataAccess/ArchiveWriter.php b/core/DataAccess/ArchiveWriter.php
index 167e3bcc9258de5f541328dc04927d07c039d07d..413f9d76eb7165d3d807d11bd03367f9ebf3369c 100644
--- a/core/DataAccess/ArchiveWriter.php
+++ b/core/DataAccess/ArchiveWriter.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * This class is used to create a new Archive.
diff --git a/core/DataAccess/LogAggregator.php b/core/DataAccess/LogAggregator.php
index bac194ea0bc3e78d666ecc6b6275b89d5e6fbed1..2992aa203c4d117ecbfec4a6be99330074893d55 100644
--- a/core/DataAccess/LogAggregator.php
+++ b/core/DataAccess/LogAggregator.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * This class queries the Visitor logs tables (visits, actions, conversions, ecommerce)
diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php
index ba8a2488492eed3f513956614e0d09eb88038731..555f35a71add83f79f3c59aab1e3fd1d0dd9bb8f 100644
--- a/core/DataTable/Renderer/Csv.php
+++ b/core/DataTable/Renderer/Csv.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * CSV export
diff --git a/core/DataTable/Renderer/Json.php b/core/DataTable/Renderer/Json.php
index bc973ea93a82526d3dca7380fabc093328e87f6a..6d815ea4bc7a421d6bf34db8c0699124f2f0dc03 100644
--- a/core/DataTable/Renderer/Json.php
+++ b/core/DataTable/Renderer/Json.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * JSON export.
diff --git a/core/DataTable/Renderer/Rss.php b/core/DataTable/Renderer/Rss.php
index a9e6376455e54de6a2e636d30852d60f12b421df..4ea2c0453c8a30a58be1a299b32be5502c8b6073 100644
--- a/core/DataTable/Renderer/Rss.php
+++ b/core/DataTable/Renderer/Rss.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * RSS Feed.
diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Myisam.php
index 248823e2d6be021b8c5eee78b62d65996ca43c38..c8d6d9a040d8720c0c7fdda4119fd8a76f927618 100644
--- a/core/Db/Schema/Myisam.php
+++ b/core/Db/Schema/Myisam.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * MySQL schema
diff --git a/core/FrontController.php b/core/FrontController.php
index fb0df9b92807bdd45c056888b127418e0d6bc3dc..c201546ed79e28a6ca3cb0fa8e2b1603ea81a871 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see core/PluginsManager.php
diff --git a/core/Http.php b/core/Http.php
index 00cc73618ad108ec6bfabb6598fe8e67b35d4717..60f8ea6e65eac8dcff2a306782fd153e9b681d70 100644
--- a/core/Http.php
+++ b/core/Http.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Server-side http client to retrieve content from remote servers, and optionally save to a local file.
diff --git a/core/IP.php b/core/IP.php
index 86f7555b802c9f492bde6cad42e23c90cd8c991e..3e528eb6289af3322e15c516e44f6ebb2304ea7a 100644
--- a/core/IP.php
+++ b/core/IP.php
@@ -10,6 +10,7 @@
  */
 
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 if (Piwik_Common::isWindows() || !function_exists('inet_ntop')) {
     function _inet_ntop($in_addr)
diff --git a/core/Log.php b/core/Log.php
index 40ec5e88cf971f31b0c6f0105cfd535bbf9ff162..2707b4a19c26a53a2263fa98fe4b55a8577ffb30 100644
--- a/core/Log.php
+++ b/core/Log.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
@@ -175,7 +176,7 @@ class Piwik_Log_Formatter_ScreenFormatter implements Zend_Log_Formatter_Interfac
     function formatEvent($event)
     {
         // no injection in error messages, backtrace when displayed on screen
-        return array_map(array('Piwik_Common', 'sanitizeInputValue'), $event);
+        return array_map(array('Piwik\Core\Piwik_Common', 'sanitizeInputValue'), $event);
     }
 
     function format($string)
diff --git a/core/Log/Exception.php b/core/Log/Exception.php
index b18233b3e2d41d1a989b04c68b252c6d864ac1b9..2865ad74a3551608612e8bf652b8e5b7aec81623 100644
--- a/core/Log/Exception.php
+++ b/core/Log/Exception.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Class used to log an exception event.
diff --git a/core/Log/Message.php b/core/Log/Message.php
index f8ca15ba4cc425f06d1e0cae6c0f1214e8241609..6852f572c05586f42e1adb965282320ea698d493 100644
--- a/core/Log/Message.php
+++ b/core/Log/Message.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Class used to log a standard message event.
diff --git a/core/Menu/Abstract.php b/core/Menu/Abstract.php
index 4388a70032c228fbd3862b6f1ad310c794eb9319..1547a27eae9222831ba16bb979b400df7f52088e 100644
--- a/core/Menu/Abstract.php
+++ b/core/Menu/Abstract.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik_Menu
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_Menu
diff --git a/core/Nonce.php b/core/Nonce.php
index f7763ee15b42f7c8156f135dd5e49ea7ae86140a..4cb6b440d6a000f2ccdf1650e67833dd8abc20f6 100644
--- a/core/Nonce.php
+++ b/core/Nonce.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Nonce class.
diff --git a/core/Option.php b/core/Option.php
index ab3a1c672f00f1c0f2fc44dedc437ce5c2903de0..179e25c23c82567a625e40b5cb20523784391887 100644
--- a/core/Option.php
+++ b/core/Option.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik_Option provides a very simple mechanism to save/retrieve key-values pair
diff --git a/core/Period/Range.php b/core/Period/Range.php
index 27ef4bd01520aa8365054e0022b286c5fa719108..e126ec835b38e7808458e0a1e973acff05072702 100644
--- a/core/Period/Range.php
+++ b/core/Period/Range.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * from a starting date to an ending date
diff --git a/core/Piwik.php b/core/Piwik.php
index d33725d09ff93fc8e4c0b4c7313677ef01060103..b377cd54a75db89a6ceb2059fe279292af5e2609 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -16,7 +16,7 @@ use Piwik\Core\Config;
 use Piwik_Access;
 use Piwik_Access_NoAccessException;
 use Piwik_AssetManager;
-use Piwik_Common;
+use Piwik\Core\Piwik_Common;
 use Piwik_Db_Adapter;
 use Piwik_Db_Schema;
 use Piwik_Log_APICall;
diff --git a/core/Plugin.php b/core/Plugin.php
index 2fbf45923ae975fbc63ec68709af40eccf589f28..582bb7ff51a1222865e01965e219124e704a8eab 100644
--- a/core/Plugin.php
+++ b/core/Plugin.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see core/Plugin/MetadataLoader.php
diff --git a/core/Plugin/MetadataLoader.php b/core/Plugin/MetadataLoader.php
index 1fe999edce5c570b355654836f62d3cb8650a03c..e96ce56ec4b847dc6dc132ac600ccfe099cda814 100644
--- a/core/Plugin/MetadataLoader.php
+++ b/core/Plugin/MetadataLoader.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see core/Version.php
diff --git a/core/PluginsArchiver.php b/core/PluginsArchiver.php
index 782e2536cba79c1d58a721e50deee0de23b2bebc..f568ac545967bf9cb4aeb77f0e6d9db2f1011d49 100644
--- a/core/PluginsArchiver.php
+++ b/core/PluginsArchiver.php
@@ -10,6 +10,7 @@
  * @package Piwik_PluginArchiver
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Plugins that archive metrics for websites can implement an Archiver that extends this class
diff --git a/core/PluginsManager.php b/core/PluginsManager.php
index b256d65c0baa045d5f3ba54de105844b961e5035..0d03e460780f6358b119854730f4d44cb51ea38f 100644
--- a/core/PluginsManager.php
+++ b/core/PluginsManager.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see core/Menu/Abstract.php
diff --git a/core/ProxyHeaders.php b/core/ProxyHeaders.php
index 5eb05b5076e1151803c2544562ff50d4235c9031..4cd540e4daca2672ec972196cb91b806cc9b68b3 100644
--- a/core/ProxyHeaders.php
+++ b/core/ProxyHeaders.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Proxy headers
diff --git a/core/ReportRenderer/Pdf.php b/core/ReportRenderer/Pdf.php
index a7e65d45c026eee1055602a108c2a44fadeb9239..85a3c9dbdaa72033512aa69fa0fd9fba1e04ddb9 100644
--- a/core/ReportRenderer/Pdf.php
+++ b/core/ReportRenderer/Pdf.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik_ReportRenderer
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see libs/tcpdf
diff --git a/core/Segment.php b/core/Segment.php
index dd3654b767ec87e113da732f2a9834727305dfdc..f4a2be255e20f88a34777d9318b7e1e690e527c4 100644
--- a/core/Segment.php
+++ b/core/Segment.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/core/Session.php b/core/Session.php
index f08df94c60967655f46190a0c954583252f63d57..7072c26c5392b2ec99fb7b2f87a8682fd59481ce 100644
--- a/core/Session.php
+++ b/core/Session.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Session initialization.
diff --git a/core/Session/Namespace.php b/core/Session/Namespace.php
index 3c18aa06db8753f797182f3e22fd81054d35deb5..0b65168ca44c80267dc15b884bd835e05155da3d 100644
--- a/core/Session/Namespace.php
+++ b/core/Session/Namespace.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Session namespace.
diff --git a/core/Tracker.php b/core/Tracker.php
index fd8bb92bf5ad84207bbf6acb9abf5aa94fac2233..f375ea35e401d2e777a18b3c728b296260aae1f7 100644
--- a/core/Tracker.php
+++ b/core/Tracker.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Class used by the logging script piwik.php called by the javascript tag.
diff --git a/core/Tracker/Action.php b/core/Tracker/Action.php
index 5da830968287aedfa72d065c1aa4553fd7ddbbd9..b98f284f78c96de56464e803ff5ccf418f8e0672 100644
--- a/core/Tracker/Action.php
+++ b/core/Tracker/Action.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Interface of the Action object.
diff --git a/core/Tracker/Db.php b/core/Tracker/Db.php
index acccd4e858778fe526e5b2dca95dbab3e89e9b6a..6ddb7b5183e8ae70ceaac9ea3c06f1a6723a0daf 100644
--- a/core/Tracker/Db.php
+++ b/core/Tracker/Db.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Simple database wrapper.
diff --git a/core/Tracker/GoalManager.php b/core/Tracker/GoalManager.php
index 4a33837ac403a06dca4f604dca62ac764aaa16b3..1f47cfcef598bafb9607e336754780b014c17b7b 100644
--- a/core/Tracker/GoalManager.php
+++ b/core/Tracker/GoalManager.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik
diff --git a/core/Tracker/Referer.php b/core/Tracker/Referer.php
index c941e0e480a52cbfd45cdfb4dd7f5215ae7240d9..85a456f95ce26d2c0693a1dc161dfea65b93a886 100644
--- a/core/Tracker/Referer.php
+++ b/core/Tracker/Referer.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik
diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php
index f1a6757806c65f0ac3687b81f0db74c9218e6656..243e6e44623dbd9f8e1a23193a1a4eaf59fdc34f 100644
--- a/core/Tracker/Request.php
+++ b/core/Tracker/Request.php
@@ -1,5 +1,6 @@
 <?php
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php
index 27457ad860c3d9674e3d8bbe68a50816d1fec7d5..7cdcff57bfa0ecf871a04a6688a54029263cc13b 100644
--- a/core/Tracker/Visit.php
+++ b/core/Tracker/Visit.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik
diff --git a/core/Tracker/VisitExcluded.php b/core/Tracker/VisitExcluded.php
index 64c9c8e8cc8397058f575c426a3ec8060f544e0c..062020dbe7689c1ea839bae849d66a457d1a305c 100644
--- a/core/Tracker/VisitExcluded.php
+++ b/core/Tracker/VisitExcluded.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * This class contains the logic to exclude some visitors from being tracked as per user settings
diff --git a/core/Translate.php b/core/Translate.php
index 95e6b9551f05f011ddc9be66cdde407f71c7197a..a1ac503edd5f3417c3049c58c672d3c1995d2031 100644
--- a/core/Translate.php
+++ b/core/Translate.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik
diff --git a/core/TranslationWriter.php b/core/TranslationWriter.php
index e47ae10f896709b1e3491c70b2ad12bfefb42bad..c7b073712d8fa4103e586e72345c08b76a1feafc 100644
--- a/core/TranslationWriter.php
+++ b/core/TranslationWriter.php
@@ -9,6 +9,7 @@
  * @package Piwik
  *
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Write translations to file
diff --git a/core/Twig.php b/core/Twig.php
index 023653959bd44d8a756ec8a8895d5d51acc77a84..6af9f80413a9bbf4db21d3bc370f8c3431cbc1d3 100644
--- a/core/Twig.php
+++ b/core/Twig.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 
 /**
diff --git a/core/UpdateCheck.php b/core/UpdateCheck.php
index 7e94922f32996fb087d2e7883d748d582566f37b..62fcc33415393e2475c426cc63bebefcbed79a92 100644
--- a/core/UpdateCheck.php
+++ b/core/UpdateCheck.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Class to check if a newer version of Piwik is available
diff --git a/core/Updater.php b/core/Updater.php
index 4b86b7d9ed26b228dc73013f37e743da6b5f69bf..9ec42e8b59a910fd6d478a4694631fd942299b1f 100644
--- a/core/Updater.php
+++ b/core/Updater.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see core/Option.php
diff --git a/core/Updates/0.2.10.php b/core/Updates/0.2.10.php
index 2f2f289c9a777bd9878c91ed92926f269a3f9f22..627c626af829b86963836aed84c14331beee26fb 100644
--- a/core/Updates/0.2.10.php
+++ b/core/Updates/0.2.10.php
@@ -9,6 +9,7 @@
  * @package Updates
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.2.12.php b/core/Updates/0.2.12.php
index f6ac41e839a212a29751324c45e5518feca98c63..72bde57ba1e6298709cc1736a4e417f3fa21c1f1 100644
--- a/core/Updates/0.2.12.php
+++ b/core/Updates/0.2.12.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.2.13.php b/core/Updates/0.2.13.php
index 1572cd73bd230312bb7424f3f5c5e972a0837f43..a70d1d68b805d06f016c938b08dc59bab5a00a80 100644
--- a/core/Updates/0.2.13.php
+++ b/core/Updates/0.2.13.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.2.24.php b/core/Updates/0.2.24.php
index 594a461805fed5efacc951de5dd2c2a995b7102c..e71b829bcd4236e380865ce3a8f6ea252fcdb537 100644
--- a/core/Updates/0.2.24.php
+++ b/core/Updates/0.2.24.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.2.27.php b/core/Updates/0.2.27.php
index 8aac68fe3a6cc6929d660100e17ad184de19b48a..dd43c0eb10488e6ff48abc71a79b0f8ecdcf3afb 100644
--- a/core/Updates/0.2.27.php
+++ b/core/Updates/0.2.27.php
@@ -9,6 +9,7 @@
  * @package Updates
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.2.32.php b/core/Updates/0.2.32.php
index 7a3bbfac42e5d625692b2e70f47e87d84dc0f431..921a48ed79c458a79fc2e4f95752555c494537df 100644
--- a/core/Updates/0.2.32.php
+++ b/core/Updates/0.2.32.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.2.33.php b/core/Updates/0.2.33.php
index cdf755109254a89e0563ce760acf60b3cb8973bc..ac82c5d5ac4713b62bb447a89736ae5e08401d3f 100644
--- a/core/Updates/0.2.33.php
+++ b/core/Updates/0.2.33.php
@@ -9,6 +9,7 @@
  * @package Updates
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.2.35.php b/core/Updates/0.2.35.php
index 9f0f80abe7781ffa0d74b52c3ce92075802af1b9..70e4c17fddc1efc1703783966396b5c647254d71 100644
--- a/core/Updates/0.2.35.php
+++ b/core/Updates/0.2.35.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.2.37.php b/core/Updates/0.2.37.php
index ca859c5f946db935c7497a95cdba8276dd39708e..adb9096327e491ac63c0df2409d08d6c7b02604f 100644
--- a/core/Updates/0.2.37.php
+++ b/core/Updates/0.2.37.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.4.1.php b/core/Updates/0.4.1.php
index 60223f845e145e93a2e8679655e34fa139134459..bae1d4c7932234bf493c237c6374cd0f8e0c5089 100644
--- a/core/Updates/0.4.1.php
+++ b/core/Updates/0.4.1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.4.2.php b/core/Updates/0.4.2.php
index e21135068ba371eccb5a3074afc4f6bb22107045..7b629c97ca2e193a1f116c166cc9b835979e6366 100644
--- a/core/Updates/0.4.2.php
+++ b/core/Updates/0.4.2.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.4.php b/core/Updates/0.4.php
index dcbfffd5781c1cb86b26e4aa5c688e1c38cf1244..5b578e780062679d6a2166bc9e0f1837377da7ba 100644
--- a/core/Updates/0.4.php
+++ b/core/Updates/0.4.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.5.4.php b/core/Updates/0.5.4.php
index 45e69d1c1803fa856b44972ed86a03c1e1b63dcd..bde45af8713997087021831025c37bd8a2cf7cb7 100644
--- a/core/Updates/0.5.4.php
+++ b/core/Updates/0.5.4.php
@@ -9,6 +9,7 @@
  * @package Updates
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.5.5.php b/core/Updates/0.5.5.php
index 923f14cd2f86469ae03334f188b0fecf86807f2a..e781f02db27698d78cbc763c4837039cb081bf94 100644
--- a/core/Updates/0.5.5.php
+++ b/core/Updates/0.5.5.php
@@ -9,6 +9,7 @@
  * @package Updates
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.5.php b/core/Updates/0.5.php
index 7877fba142f36d4be686d679f11b71bcd1e4e941..1a01bcf5f1ebaf69fbabd9b4da781ee021a273ec 100644
--- a/core/Updates/0.5.php
+++ b/core/Updates/0.5.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.6-rc1.php b/core/Updates/0.6-rc1.php
index e4dc34d522bc36e196e187a9c47e2dfc93f76275..b1e83f3d3b5e9b6efa3b6c45a1928d769b327ed0 100644
--- a/core/Updates/0.6-rc1.php
+++ b/core/Updates/0.6-rc1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.6.3.php b/core/Updates/0.6.3.php
index 0cb43f125f159ee0c21f6dc5177dab53abe8302b..82041c3620e557c36c7d3a1d51db52e200a674a9 100644
--- a/core/Updates/0.6.3.php
+++ b/core/Updates/0.6.3.php
@@ -9,6 +9,7 @@
  * @package Updates
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.7.php b/core/Updates/0.7.php
index 685fe7c9624260b912bc0f9230538d7c08d5aadd..fa153883a938d0e158bd123590bfc6d16beb8d1e 100644
--- a/core/Updates/0.7.php
+++ b/core/Updates/0.7.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/0.9.1.php b/core/Updates/0.9.1.php
index 04658a23c56a8bdef8c61066fc714bbf15548480..31998ad17d48f0146078e8cc7769aed085857c7d 100644
--- a/core/Updates/0.9.1.php
+++ b/core/Updates/0.9.1.php
@@ -9,6 +9,7 @@
  * @package Updates
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.10.2-b1.php b/core/Updates/1.10.2-b1.php
index 17968632978483706ca184fc5ee291e00e02a5e8..10a28c6143bcbcf14ec4ff86fc756b9634cb1868 100755
--- a/core/Updates/1.10.2-b1.php
+++ b/core/Updates/1.10.2-b1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.10.2-b2.php b/core/Updates/1.10.2-b2.php
index 26cfd3e0047229dcd2481ed25e29b1d060947150..7c05ea806c1765a510280c9d979778775a42aadb 100644
--- a/core/Updates/1.10.2-b2.php
+++ b/core/Updates/1.10.2-b2.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.12-b1.php b/core/Updates/1.12-b1.php
index 6fb3551d4f91b3fac5a58884ce54e043237320c4..c91dbb1df013740cf326ecd85d7b86c67c245922 100644
--- a/core/Updates/1.12-b1.php
+++ b/core/Updates/1.12-b1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.12-b16.php b/core/Updates/1.12-b16.php
index 8ac3df70da8760b36913113799134de3158b5d9f..fb5ba2a9a6222137e275049bcee473dd4a0fddac 100644
--- a/core/Updates/1.12-b16.php
+++ b/core/Updates/1.12-b16.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.2-rc1.php b/core/Updates/1.2-rc1.php
index ac6bbcb0e378cab9fee89ff404b0ef892cdbf34c..7f36539f7b3a10ec981ae4a3b885d85236a0c065 100644
--- a/core/Updates/1.2-rc1.php
+++ b/core/Updates/1.2-rc1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.2.3.php b/core/Updates/1.2.3.php
index 177b85a092bde4d01ad6ac64e698b1ff95695490..066cea1a827739710b0b94590766a63e07ab3ba2 100644
--- a/core/Updates/1.2.3.php
+++ b/core/Updates/1.2.3.php
@@ -9,6 +9,7 @@
  * @package Updates
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.2.5-rc1.php b/core/Updates/1.2.5-rc1.php
index 90b0399589111ba2e5a7a3bb11175ad207065d96..d17bfd38254ab1c86395a469bc83719b4ac0eb46 100644
--- a/core/Updates/1.2.5-rc1.php
+++ b/core/Updates/1.2.5-rc1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.2.5-rc7.php b/core/Updates/1.2.5-rc7.php
index aafc70c7a978f3cb95aa13ca9795df3a522c86a3..b1da1cd65a100ea66d26528ff1b0c3a5bf221101 100644
--- a/core/Updates/1.2.5-rc7.php
+++ b/core/Updates/1.2.5-rc7.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.4-rc1.php b/core/Updates/1.4-rc1.php
index ce99c40497cbcd44f64c265031c2c8539147230c..52e55899598d6a9242bce33ab381d4622f710be5 100644
--- a/core/Updates/1.4-rc1.php
+++ b/core/Updates/1.4-rc1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.4-rc2.php b/core/Updates/1.4-rc2.php
index b5273b05057e51d2959b1f65a4661d0cbe6a289c..f38e8208a00cbd0bfcdce5b957a270fbe33f0829 100644
--- a/core/Updates/1.4-rc2.php
+++ b/core/Updates/1.4-rc2.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.5-b1.php b/core/Updates/1.5-b1.php
index 7156719e3dd0976394412c6bac4597fd6b579ba4..ba72c69a3fdb9f21f0e2e0bdb0980a66923c2eb8 100644
--- a/core/Updates/1.5-b1.php
+++ b/core/Updates/1.5-b1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.5-b2.php b/core/Updates/1.5-b2.php
index fee8f86e9a60e71a33b42b52ad220af14e53c399..4711c7a97f5bf1b5cf0bb72b9d7019545f87ad4e 100644
--- a/core/Updates/1.5-b2.php
+++ b/core/Updates/1.5-b2.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.5-b3.php b/core/Updates/1.5-b3.php
index e7d76bd2e565f093eab4bb2ac1e179bd5fa60393..2beb4ad58361c0d1a3cb088f423fefb584024525 100644
--- a/core/Updates/1.5-b3.php
+++ b/core/Updates/1.5-b3.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.5-b4.php b/core/Updates/1.5-b4.php
index 15479fb029745a65d015a38571152691c876d451..dcf67cf04d2b737d93ffe11111c7b13fd8b13218 100644
--- a/core/Updates/1.5-b4.php
+++ b/core/Updates/1.5-b4.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.5-b5.php b/core/Updates/1.5-b5.php
index c00eac3dced3c571ba2c12d23e977e37e1d0a3f1..87913e6153dd14d8ba51e5e3540f424da8234ee1 100644
--- a/core/Updates/1.5-b5.php
+++ b/core/Updates/1.5-b5.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.6-b1.php b/core/Updates/1.6-b1.php
index 57e1deb8895071c875879295868bc120380636a8..f8d87d99457f9c447733eef7b6d17acb57e5834e 100644
--- a/core/Updates/1.6-b1.php
+++ b/core/Updates/1.6-b1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.7-b1.php b/core/Updates/1.7-b1.php
index f5f084f892e498590315e97398ee48a199953b8a..62632a518362b48e8e473b6c28a4a599df62e72c 100644
--- a/core/Updates/1.7-b1.php
+++ b/core/Updates/1.7-b1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.7.2-rc5.php b/core/Updates/1.7.2-rc5.php
index 6d9e88a8b2be1228d718a41aec5d3741e716735b..d526d5f708cb77aac106cec43daeb965ae19bdb2 100644
--- a/core/Updates/1.7.2-rc5.php
+++ b/core/Updates/1.7.2-rc5.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.7.2-rc7.php b/core/Updates/1.7.2-rc7.php
index c901f37a7d821a1be10e081dcd3d9a164019449c..b6a25fae9604308bd049f30dbfaeb39f9ebbb1ed 100755
--- a/core/Updates/1.7.2-rc7.php
+++ b/core/Updates/1.7.2-rc7.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.8.3-b1.php b/core/Updates/1.8.3-b1.php
index 2dfe336559c281fbb2f9af22cca6b2d11aa96871..9605f15702a8f3748dae679bbcde8343306fdfab 100644
--- a/core/Updates/1.8.3-b1.php
+++ b/core/Updates/1.8.3-b1.php
@@ -8,6 +8,7 @@
  * @category Piwik‚
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.8.4-b1.php b/core/Updates/1.8.4-b1.php
index 2c0b5138c73cbb15c035183b556e972ab50b8837..58b813964744c78c798ca122fafdd19b78932eda 100644
--- a/core/Updates/1.8.4-b1.php
+++ b/core/Updates/1.8.4-b1.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.9-b16.php b/core/Updates/1.9-b16.php
index b4ec3648019efa243a572af65df1d0afd7177ca7..dade3e37b3d6c6b2d8875f547b96a06db9cddce1 100755
--- a/core/Updates/1.9-b16.php
+++ b/core/Updates/1.9-b16.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.9-b19.php b/core/Updates/1.9-b19.php
index e5fc17f1ba51c15faf332c8b7c817e641100ea99..9dc79c3d4a3816bdc8f6aa18ac00513d4da20570 100755
--- a/core/Updates/1.9-b19.php
+++ b/core/Updates/1.9-b19.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.9-b9.php b/core/Updates/1.9-b9.php
index f986381d97c5ab3f60b0718fda4784d9b8c26bc3..c70169d3ef3bf4721f46300fb184c6fd0e7ab935 100755
--- a/core/Updates/1.9-b9.php
+++ b/core/Updates/1.9-b9.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.9.1-b2.php b/core/Updates/1.9.1-b2.php
index af9954be9a46b0d0bc25734e6cd9c541f535ee25..bf478a6fc8e7cb22e22279e41040568d106af7bb 100644
--- a/core/Updates/1.9.1-b2.php
+++ b/core/Updates/1.9.1-b2.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Updates/1.9.3-b8.php b/core/Updates/1.9.3-b8.php
index e0d29e0acdf67b34726feaa27f9111476f4fb5d7..67e296ea8172223f86ae0081b45963bc00539d77 100755
--- a/core/Updates/1.9.3-b8.php
+++ b/core/Updates/1.9.3-b8.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Updates
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Updates
diff --git a/core/Url.php b/core/Url.php
index b4eacdff83d776f6f32b55cf5ca60b5d85bf9fd4..b31d8549357e117ebed62beb61099dea8e717d82 100644
--- a/core/Url.php
+++ b/core/Url.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Class to retrieve absolute URL or URI components of the current URL,
diff --git a/core/View.php b/core/View.php
index ea4a43b8b3ea5af39fa031680a5e6a3c155ed137..8047dc6230461d84d227735494bd4769ac13cf5f 100644
--- a/core/View.php
+++ b/core/View.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Transition for pre-Piwik 0.4.4
diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php
index 46eabeecc745484937c44ec8eda4c998dfb01a2d..91da163f478e7344c6692375f63efcf4445c8f9c 100644
--- a/core/ViewDataTable.php
+++ b/core/ViewDataTable.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * This class is used to load (from the API) and customize the output of a given DataTable.
diff --git a/core/ViewDataTable/GenerateGraphData.php b/core/ViewDataTable/GenerateGraphData.php
index eab6293b638994462f9444240d99758ccbcbcd61..865809310223f39169a328ad2ad8481b18f37ece 100644
--- a/core/ViewDataTable/GenerateGraphData.php
+++ b/core/ViewDataTable/GenerateGraphData.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Reads data from the API and prepares data to give to the renderer Piwik_Visualization_Chart.
diff --git a/core/ViewDataTable/GenerateGraphData/ChartEvolution.php b/core/ViewDataTable/GenerateGraphData/ChartEvolution.php
index 9237a5e42706d6cf47736e67aa2946da7f0ed96e..d0cbb29f3e5f4087bee97b96b1b05d265351b645 100644
--- a/core/ViewDataTable/GenerateGraphData/ChartEvolution.php
+++ b/core/ViewDataTable/GenerateGraphData/ChartEvolution.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik_ViewDataTable_GenerateGraphData for the Evolution graph (eg. Last 30 days visits) using Piwik_Visualization_Chart_Evolution
diff --git a/core/ViewDataTable/GenerateGraphHTML.php b/core/ViewDataTable/GenerateGraphHTML.php
index f7b580eb3daecf5ebb9591c74cacc1c8edebffb2..f34390404d2da41c1c47ec771016db6061348786 100644
--- a/core/ViewDataTable/GenerateGraphHTML.php
+++ b/core/ViewDataTable/GenerateGraphHTML.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * This class generates the HTML code to embed graphs in the page.
diff --git a/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php b/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php
index 73d0f3a1670d835f5298979bcad567c14b2f0e74..aec31a7a3a6563472a2e8d062e37d2ab1a1df298 100644
--- a/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php
+++ b/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Generates HTML embed for the Evolution graph
diff --git a/core/ViewDataTable/HtmlTable.php b/core/ViewDataTable/HtmlTable.php
index 08df07ffabd0cfe9e8f1d99a90cb54247140e406..6267a2aca23b5e22812b88d80fdd99f66b62ba5a 100644
--- a/core/ViewDataTable/HtmlTable.php
+++ b/core/ViewDataTable/HtmlTable.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Outputs an AJAX Table for a given DataTable.
diff --git a/core/ViewDataTable/HtmlTable/Goals.php b/core/ViewDataTable/HtmlTable/Goals.php
index 21740d0905dab19f74fc7d05adb3ef46718767b7..325253872fcfd7b103e49f16638e38c1a0a5a4ce 100644
--- a/core/ViewDataTable/HtmlTable/Goals.php
+++ b/core/ViewDataTable/HtmlTable/Goals.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik
diff --git a/core/ViewDataTable/Sparkline.php b/core/ViewDataTable/Sparkline.php
index 062a9267b2dda7815182a812591cb80974ad381b..09a4d7373af65542f1ebba6acd31714ed7e2bd08 100644
--- a/core/ViewDataTable/Sparkline.php
+++ b/core/ViewDataTable/Sparkline.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Reads the requested DataTable from the API and prepare data for the Sparkline view.
diff --git a/core/Visualization/Chart.php b/core/Visualization/Chart.php
index 4cf3de47dbec9da648f3bf6a98981c58880bb218..9c8f53700d12b6b444f794ecd9ac301404b8e9ac 100644
--- a/core/Visualization/Chart.php
+++ b/core/Visualization/Chart.php
@@ -9,6 +9,7 @@
  * @package Piwik
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Generates the data in the Open Flash Chart format, from the given data.
diff --git a/core/Visualization/Cloud.php b/core/Visualization/Cloud.php
index c00c088e3951411f1ba699ab5a8f43e40f8234e8..3458c70605a09502ae097b6bcd337c4c14dea6cc 100644
--- a/core/Visualization/Cloud.php
+++ b/core/Visualization/Cloud.php
@@ -8,6 +8,7 @@
  * @category Piwik
  * @package Piwik
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Generates a tag cloud from a given data array.
diff --git a/libs/upgradephp/upgrade.php b/libs/upgradephp/upgrade.php
index c0d187aaca1eb12d90bf8c416e9d59275abb03ea..e553110d36942a92feabcb861ff4f7a26a7ecfb5 100644
--- a/libs/upgradephp/upgrade.php
+++ b/libs/upgradephp/upgrade.php
@@ -35,6 +35,7 @@
  * Any contribution is appreciated. <milky*users#sf#net>
  *
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @since PHP 5
diff --git a/misc/cron/archive.php b/misc/cron/archive.php
index 2fbf894783401d4902796d4c484df4438e2f068a..89850874911210337aef98e35ef2aaff64d10ead 100644
--- a/misc/cron/archive.php
+++ b/misc/cron/archive.php
@@ -1,6 +1,7 @@
 <?php
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 $USAGE = "
 Usage: 
diff --git a/misc/others/geoipUpdateRows.php b/misc/others/geoipUpdateRows.php
index 747cf4d62e97353bbea0d143d615387925091bf8..137b2bd1d0420d5d15657df76ebe7ed0fb517f86 100755
--- a/misc/others/geoipUpdateRows.php
+++ b/misc/others/geoipUpdateRows.php
@@ -1,6 +1,7 @@
 <?php
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 ini_set("memory_limit", "512M");
 error_reporting(E_ALL | E_NOTICE);
diff --git a/misc/others/iframeWidget_localhost.php b/misc/others/iframeWidget_localhost.php
index d01ba892278742eccae2ffbc877289ae77b87963..7b4d87db9d850f61f6a63449f80cdffa7ac45319 100644
--- a/misc/others/iframeWidget_localhost.php
+++ b/misc/others/iframeWidget_localhost.php
@@ -1,4 +1,6 @@
 <?php
+use Piwik\Core\Piwik_Common;
+
 exit;
 $date = date('Y-m-d');
 $period = 'month';
diff --git a/misc/others/test_cookies_GenerateHundredsWebsitesAndVisits.php b/misc/others/test_cookies_GenerateHundredsWebsitesAndVisits.php
index ac2539eca7358cdeac237e77450b194c67bbac31..1b6ecf53614659416f69e9e45142885883eaf556 100644
--- a/misc/others/test_cookies_GenerateHundredsWebsitesAndVisits.php
+++ b/misc/others/test_cookies_GenerateHundredsWebsitesAndVisits.php
@@ -2,6 +2,7 @@
 // Script that creates 100 websites, then outputs a IMG that records a pageview in each website
 // Used initially to test how to handle cookies for this use case (see http://dev.piwik.org/trac/ticket/409)
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 exit;
 
diff --git a/misc/others/test_generateLotsVisitsWebsites.php b/misc/others/test_generateLotsVisitsWebsites.php
index 9a077683881b375ba510b7f762e8f70f3a06b7af..44d5bc031a850ab0dc11c6d3d2a20aa1d14b3b4b 100644
--- a/misc/others/test_generateLotsVisitsWebsites.php
+++ b/misc/others/test_generateLotsVisitsWebsites.php
@@ -1,6 +1,7 @@
 <?php
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__) . "/../.."));
 define('PIWIK_ENABLE_DISPATCH', false);
diff --git a/plugins/API/API.php b/plugins/API/API.php
index 203d8295ff4fcf8cc83138358c1a12af738a89fb..a08e046c4be55ee6f95bbda23a027656c1ffb4ec 100644
--- a/plugins/API/API.php
+++ b/plugins/API/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_API
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_API
@@ -552,7 +553,7 @@ class Piwik_API_API
         }
 
         $urls = array_map('urldecode', $urls);
-        $urls = array_map(array('Piwik_Common', 'unsanitizeInputValue'), $urls);
+        $urls = array_map(array('Piwik\Core\Piwik_Common', 'unsanitizeInputValue'), $urls);
 
         $result = array();
         foreach ($urls as $url) {
@@ -628,7 +629,7 @@ class Piwik_API_API
         arsort($values);
         $values = array_keys($values);
 
-        $values = array_map(array('Piwik_Common', 'unsanitizeInputValue'), $values);
+        $values = array_map(array('Piwik\Core\Piwik_Common', 'unsanitizeInputValue'), $values);
 
         $values = array_slice($values, 0, $maxSuggestionsToReturn);
         return $values;
diff --git a/plugins/API/Controller.php b/plugins/API/Controller.php
index a586b43b1a7c28899af237313cc720f1af984bd5..8d70af3650178e9d55e2cd72e059c0739aaf3dde 100644
--- a/plugins/API/Controller.php
+++ b/plugins/API/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_API
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/API/ProcessedReport.php b/plugins/API/ProcessedReport.php
index 3657ffab25185db3ae83df661dfd4420bf4eb3a2..318929f1ce3d794367fc84174fc13f41bd1b84cf 100644
--- a/plugins/API/ProcessedReport.php
+++ b/plugins/API/ProcessedReport.php
@@ -1,5 +1,6 @@
 <?php
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/plugins/API/RowEvolution.php b/plugins/API/RowEvolution.php
index cc762d11dec6b3fb81efb28785938e6fffeb6930..dfc24d6a6ac02310ebbee3af787ce0dbcda1bb4f 100644
--- a/plugins/API/RowEvolution.php
+++ b/plugins/API/RowEvolution.php
@@ -9,6 +9,7 @@
  * @package Piwik_API
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * This class generates a Row evolution dataset, from input request
diff --git a/plugins/Actions/API.php b/plugins/Actions/API.php
index 5a4ad1e181b75d081d89fda3aa6c58ee62ceee3b..25a21a2d8da9ee6f0976018791792a6c652e12d2 100644
--- a/plugins/Actions/API.php
+++ b/plugins/Actions/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_Actions
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The Actions API lets you request reports for all your Visitor Actions: Page URLs, Page titles (Piwik Events),
diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php
index 0ad2593184639bc7332fad9af7adb30f91e3139d..eb2171397a144edc48d6f87a485f52659105bace 100644
--- a/plugins/Actions/Actions.php
+++ b/plugins/Actions/Actions.php
@@ -9,6 +9,7 @@
  * @package Piwik_Actions
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Actions plugin
diff --git a/plugins/Annotations/Controller.php b/plugins/Annotations/Controller.php
index 3b88fadb9d88c489acf745e86d1a7f0601a71009..32ad2b49318308a34b68c10796449e82b29a8e41 100755
--- a/plugins/Annotations/Controller.php
+++ b/plugins/Annotations/Controller.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_Annotations
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Controller for the Annotations plugin.
diff --git a/plugins/AnonymizeIP/AnonymizeIP.php b/plugins/AnonymizeIP/AnonymizeIP.php
index 4e14459fd7bbeab93856154b986284720e162cad..e50c7386a1a66ac4fd844d1af7d6a139a4c2733b 100644
--- a/plugins/AnonymizeIP/AnonymizeIP.php
+++ b/plugins/AnonymizeIP/AnonymizeIP.php
@@ -9,6 +9,7 @@
  * @package Piwik_AnonymizeIP
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Anonymize visitor IP addresses to comply with the privacy laws/guidelines in countries, such as Germany.
diff --git a/plugins/CoreAdminHome/API.php b/plugins/CoreAdminHome/API.php
index 08108363e4ba70fcbdbf8afa66013bc3dee848e1..07cb1218e8f19131a0deb3b8dbc093d9973c549c 100644
--- a/plugins/CoreAdminHome/API.php
+++ b/plugins/CoreAdminHome/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_CoreAdminHome
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_CoreAdminHome
diff --git a/plugins/CoreAdminHome/Controller.php b/plugins/CoreAdminHome/Controller.php
index af0ef50a86c37e4aafe8fc6f9c8a07ff9e799e02..69344d2771abdc4a63cdfe5c398c375ad2a7848f 100644
--- a/plugins/CoreAdminHome/Controller.php
+++ b/plugins/CoreAdminHome/Controller.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/CoreHome/Controller.php b/plugins/CoreHome/Controller.php
index ee30059e4517924b2eadaefb59f46b6bb0879937..c7758373d47a2b84c33aa630410fe5639fcfe672 100644
--- a/plugins/CoreHome/Controller.php
+++ b/plugins/CoreHome/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_CoreHome
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php b/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php
index 1e761a0aae0d4504e1cefc0a7ccc4e07e6344d44..cb4c49ab8a23b7e8acee1d39604cef087cc20da5 100644
--- a/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php
+++ b/plugins/CoreHome/DataTableRowAction/MultiRowEvolution.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_CoreHome
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * MULTI ROW EVOLUTION
diff --git a/plugins/CoreHome/DataTableRowAction/RowEvolution.php b/plugins/CoreHome/DataTableRowAction/RowEvolution.php
index 9b8d958c880ef257f030703f9d7fffbb9632d4e7..22da9411f79b12d51308b64c86d25337766455a2 100644
--- a/plugins/CoreHome/DataTableRowAction/RowEvolution.php
+++ b/plugins/CoreHome/DataTableRowAction/RowEvolution.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_CoreHome
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * ROW EVOLUTION
diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php
index 0bfb838a875fef89265a48426bd67bf50c707d10..692ee1abd14577498ee0826bdae493957022b7ee 100644
--- a/plugins/CorePluginsAdmin/Controller.php
+++ b/plugins/CorePluginsAdmin/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_CorePluginsAdmin
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/CoreUpdater/Controller.php b/plugins/CoreUpdater/Controller.php
index dcf109113d4ad1b0a5b6a5e7a46d7e1320cfb486..3d4040a6a5b7dfd88569ccf89494ef87671996d9 100644
--- a/plugins/CoreUpdater/Controller.php
+++ b/plugins/CoreUpdater/Controller.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/CoreUpdater/CoreUpdater.php b/plugins/CoreUpdater/CoreUpdater.php
index e3aab1affb63a6f0018984674f00d4daa7decb12..72d5269000d315e40729ac30033f643be003a2c7 100644
--- a/plugins/CoreUpdater/CoreUpdater.php
+++ b/plugins/CoreUpdater/CoreUpdater.php
@@ -9,6 +9,7 @@
  * @package Piwik_CoreUpdater
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/CustomVariables/Archiver.php b/plugins/CustomVariables/Archiver.php
index 8d8d018d6788fcc085a0a16320b8067e82a4fa6b..bae7cb7066cc496e26ae2e1de19746ac30f9702b 100644
--- a/plugins/CustomVariables/Archiver.php
+++ b/plugins/CustomVariables/Archiver.php
@@ -1,5 +1,5 @@
 <?php
-use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/plugins/DBStats/API.php b/plugins/DBStats/API.php
index 81f036874960c88a3b2b8914989ad9e1bf80bb6f..8e99fc8fec4ca14fbc3940ea3979b3666f1dd979 100644
--- a/plugins/DBStats/API.php
+++ b/plugins/DBStats/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_DBStats
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see plugins/DBStats/MySQLMetadataProvider.php
diff --git a/plugins/DBStats/MySQLMetadataProvider.php b/plugins/DBStats/MySQLMetadataProvider.php
index 80bc9be7c495c4a7702032f55a52f92ecd7399b0..90185312cbaab55c8fa9908baa0fe23f65a8ed4f 100755
--- a/plugins/DBStats/MySQLMetadataProvider.php
+++ b/plugins/DBStats/MySQLMetadataProvider.php
@@ -9,6 +9,7 @@
  * @package Piwik_DBStats
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Utility class that provides general information about databases, including the size of
diff --git a/plugins/Dashboard/Controller.php b/plugins/Dashboard/Controller.php
index 10b64bc1643639487a44b46552771c5bdfa4b8cc..589eb29e73b30ad364809d2e4c34cef681cce4b8 100644
--- a/plugins/Dashboard/Controller.php
+++ b/plugins/Dashboard/Controller.php
@@ -8,6 +8,7 @@
  * @package  Piwik_Dashboard
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Dashboard Controller
diff --git a/plugins/Dashboard/Dashboard.php b/plugins/Dashboard/Dashboard.php
index 25d33fd5f6470662e97584a795db6b48dca1f7e4..f6a0274dfee875dff16e1e87603c6d3704516254 100644
--- a/plugins/Dashboard/Dashboard.php
+++ b/plugins/Dashboard/Dashboard.php
@@ -9,6 +9,7 @@
  * @package Piwik_Dashboard
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_Dashboard
diff --git a/plugins/DevicesDetection/Controller.php b/plugins/DevicesDetection/Controller.php
index a76ede7038a40405426ad59be0e0e1b1ed1de29a..9d09a35abee3b769ab99a7f354c95bc77226c97b 100644
--- a/plugins/DevicesDetection/Controller.php
+++ b/plugins/DevicesDetection/Controller.php
@@ -1,5 +1,6 @@
 <?php
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/plugins/DevicesDetection/DevicesDetection.php b/plugins/DevicesDetection/DevicesDetection.php
index 85324d7cbdd0fc7add20972871449c2217638543..31c12d6b07a1b4c6f4f95d26a4c5f58d5f16bec2 100644
--- a/plugins/DevicesDetection/DevicesDetection.php
+++ b/plugins/DevicesDetection/DevicesDetection.php
@@ -10,6 +10,7 @@
  * @package Piwik_DevicesDetection
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 require_once PIWIK_INCLUDE_PATH . "/plugins/DevicesDetection/UserAgentParserEnhanced/UserAgentParserEnhanced.php";
 require_once PIWIK_INCLUDE_PATH . '/plugins/DevicesDetection/functions.php';
diff --git a/plugins/ExamplePlugin/Controller.php b/plugins/ExamplePlugin/Controller.php
index c44edb73bfaf4f5f929fd8c3c84ac602c3b445ff..73329f92701141ee95bd953efef2947bfa569ef9 100644
--- a/plugins/ExamplePlugin/Controller.php
+++ b/plugins/ExamplePlugin/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_ExamplePlugin
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/ExampleUI/Controller.php b/plugins/ExampleUI/Controller.php
index 1535c07220cffc052fb3c23989b4e5baaa9d7aad..1cb48ecb5e6c417cbf61124b67b35f81b1826c20 100644
--- a/plugins/ExampleUI/Controller.php
+++ b/plugins/ExampleUI/Controller.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_ExampleUI
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_ExampleUI
diff --git a/plugins/Feedback/Controller.php b/plugins/Feedback/Controller.php
index 6d28c054f9a683864219647e3fe80025d6dba8dc..783a64dbb5c125c033748034dab5574aef887913 100644
--- a/plugins/Feedback/Controller.php
+++ b/plugins/Feedback/Controller.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Goals/API.php b/plugins/Goals/API.php
index 308d6dc9e89016285d9493db5c8329cd22619dcd..f6fd240773f3041a04e3b502a6b16a2a2b616b17 100644
--- a/plugins/Goals/API.php
+++ b/plugins/Goals/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_Goals
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Goals API lets you Manage existing goals, via "updateGoal" and "deleteGoal", create new Goals via "addGoal",
diff --git a/plugins/Goals/Controller.php b/plugins/Goals/Controller.php
index 8e89a78cd1bf2dab6f7de7f2fedafc7819c28a06..d96730e3b554a561eb47b871dcfe998b696ed562 100644
--- a/plugins/Goals/Controller.php
+++ b/plugins/Goals/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_Goals
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Goals/Goals.php b/plugins/Goals/Goals.php
index c491dabe2211c6e7ebc6f0152c8df00ed3ce9ed0..80a6cfc8e947ca62ba4787c9c3ebef5eaa20b729 100644
--- a/plugins/Goals/Goals.php
+++ b/plugins/Goals/Goals.php
@@ -9,6 +9,7 @@
  * @package Piwik_Goals
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/ImageGraph/API.php b/plugins/ImageGraph/API.php
index 92cc1767f5b8e74a371848608cc091e69e8d1cae..d6d7feaa42c4eeefade5601c2b8fc4d95248b796 100644
--- a/plugins/ImageGraph/API.php
+++ b/plugins/ImageGraph/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_ImageGraph
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The ImageGraph.get API call lets you generate beautiful static PNG Graphs for any existing Piwik report.
diff --git a/plugins/ImageGraph/Controller.php b/plugins/ImageGraph/Controller.php
index 0e7839f1275b73b58e490958ec660d86523657bb..56157a4f2a4039195f9cd8c09a2c8f75804c6b8b 100644
--- a/plugins/ImageGraph/Controller.php
+++ b/plugins/ImageGraph/Controller.php
@@ -1,5 +1,6 @@
 <?php
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/plugins/ImageGraph/ImageGraph.php b/plugins/ImageGraph/ImageGraph.php
index 0604942cdee3187921f207d57f24126afebc8c21..8cf15cd7ffad98a5bc119926d457ebb7fde4e14d 100644
--- a/plugins/ImageGraph/ImageGraph.php
+++ b/plugins/ImageGraph/ImageGraph.php
@@ -1,5 +1,5 @@
 <?php
-use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php
index 65d4c0c52fd970a937c8b9a598faabca242678e1..26e5f23b72e2b42919aaafbbd686deeaf04eddde 100644
--- a/plugins/Installation/Controller.php
+++ b/plugins/Installation/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_Installation
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Installation controller
diff --git a/plugins/Installation/FormDatabaseSetup.php b/plugins/Installation/FormDatabaseSetup.php
index 642753f760342608e17c360c6af2d5f153514e59..bae926f4ed420d081ef2345e41b9d88e17b49d0b 100644
--- a/plugins/Installation/FormDatabaseSetup.php
+++ b/plugins/Installation/FormDatabaseSetup.php
@@ -9,6 +9,7 @@
  * @package Piwik_Installation
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Installation/Installation.php b/plugins/Installation/Installation.php
index 8e3c63fc08e63787421046b828fed954c3852ef7..36326a93adf2fe4fccd1311fb3792f970e08279f 100644
--- a/plugins/Installation/Installation.php
+++ b/plugins/Installation/Installation.php
@@ -9,6 +9,7 @@
  * @package Piwik_Installation
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/LanguagesManager/API.php b/plugins/LanguagesManager/API.php
index 3f481e95f3b743dc021830b73cfc7cb53184f64e..a4048e99b583790a80f0e17db445547136d43044 100644
--- a/plugins/LanguagesManager/API.php
+++ b/plugins/LanguagesManager/API.php
@@ -10,6 +10,7 @@
  *
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The LanguagesManager API lets you access existing Piwik translations, and change Users languages preferences.
diff --git a/plugins/LanguagesManager/Controller.php b/plugins/LanguagesManager/Controller.php
index 0538f4d54068a5ce14b338507d9988141df8e065..2fbc094382a91eb9f1f3bc5eae773507db84c870 100644
--- a/plugins/LanguagesManager/Controller.php
+++ b/plugins/LanguagesManager/Controller.php
@@ -10,6 +10,7 @@
  *
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_LanguagesManager
diff --git a/plugins/LanguagesManager/LanguagesManager.php b/plugins/LanguagesManager/LanguagesManager.php
index 0100a78965f1c8e1ba4bca6d0176bd8751d681b4..5d8f6a3a72f4b8626372614cd47a983ad06cd93d 100644
--- a/plugins/LanguagesManager/LanguagesManager.php
+++ b/plugins/LanguagesManager/LanguagesManager.php
@@ -11,6 +11,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Live/API.php b/plugins/Live/API.php
index 78034dd50abdd9145f6574c4c7950f4020497d47..4928570526761cde53d7d84a6c6e4c22376c892c 100644
--- a/plugins/Live/API.php
+++ b/plugins/Live/API.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see plugins/Referers/functions.php
diff --git a/plugins/Live/Controller.php b/plugins/Live/Controller.php
index bd42e046ee8dfb12e92d86d33eaaaeaa357add7a..40058843c4df5850b13b8367085fcebfde3da095 100644
--- a/plugins/Live/Controller.php
+++ b/plugins/Live/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_Live
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_Live
diff --git a/plugins/Live/Visitor.php b/plugins/Live/Visitor.php
index 786d6491ab9f440e3a68f18a03aade1ad29313fe..0efd06ba63f330420a6ffd0fd75d8546d9cfac00 100644
--- a/plugins/Live/Visitor.php
+++ b/plugins/Live/Visitor.php
@@ -9,6 +9,7 @@
  * @package Piwik_Live
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see plugins/Referers/functions.php
diff --git a/plugins/Login/Auth.php b/plugins/Login/Auth.php
index 4bcfe24d068a8b9496bea604e74f029dc7de709d..a9027cd864295c049a97f32246df9982116f393f 100644
--- a/plugins/Login/Auth.php
+++ b/plugins/Login/Auth.php
@@ -9,6 +9,7 @@
  * @package Piwik_Login
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php
index e255aba40bb22b657b7a578ad5f8b5f231c39c1b..135f6f3af60691a38edbe303f72e939edb0aad67 100644
--- a/plugins/Login/Controller.php
+++ b/plugins/Login/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_Login
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Login controller
diff --git a/plugins/MobileMessaging/API.php b/plugins/MobileMessaging/API.php
index ce4adeef49d33a24920733f041090699af4d7711..d8b88da705ad3bd9c9cbc6eb26b030841d13fb34 100644
--- a/plugins/MobileMessaging/API.php
+++ b/plugins/MobileMessaging/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_MobileMessaging
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The MobileMessaging API lets you manage and access all the MobileMessaging plugin features including :
diff --git a/plugins/MobileMessaging/Controller.php b/plugins/MobileMessaging/Controller.php
index 0796892c6143750ec6b49c69d8ed2ae5a586072c..d720b62236586f41d204de566f047af022ccb22c 100644
--- a/plugins/MobileMessaging/Controller.php
+++ b/plugins/MobileMessaging/Controller.php
@@ -10,6 +10,7 @@
  */
 
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 require_once PIWIK_INCLUDE_PATH . '/plugins/UserCountry/functions.php';
 
diff --git a/plugins/MobileMessaging/ReportRenderer/Sms.php b/plugins/MobileMessaging/ReportRenderer/Sms.php
index 2fe2a3d1119145c938e2e514799b9632ccc53382..39d10cad2f13d16a8038fb1c54c06bb132843d77 100644
--- a/plugins/MobileMessaging/ReportRenderer/Sms.php
+++ b/plugins/MobileMessaging/ReportRenderer/Sms.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_MobileMessaging_ReportRenderer
  */
+use Piwik\Core\Piwik_Common;
 
 
 /**
diff --git a/plugins/MultiSites/API.php b/plugins/MultiSites/API.php
index 8ed333e3f5a8aca5e23121d1b969fd7cd4aab883..1060129b8a87faedc82e0360e0396a86fae420b5 100755
--- a/plugins/MultiSites/API.php
+++ b/plugins/MultiSites/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_MultiSites
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The MultiSites API lets you request the key metrics (visits, page views, revenue) for all Websites in Piwik.
diff --git a/plugins/MultiSites/Controller.php b/plugins/MultiSites/Controller.php
index 0a86c09ed7e638125e825052f66ff38526f22edd..c63820a6a73602e133ef6d868ba85e0a3c529dfc 100644
--- a/plugins/MultiSites/Controller.php
+++ b/plugins/MultiSites/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_MultiSites
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Overlay/Controller.php b/plugins/Overlay/Controller.php
index 8fccad0a3a8049e2dcb00f1c077b1027ef37edd3..0754731d4987e0064b142a223b11b5483cf1402f 100644
--- a/plugins/Overlay/Controller.php
+++ b/plugins/Overlay/Controller.php
@@ -1,5 +1,6 @@
 <?php
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/plugins/PDFReports/API.php b/plugins/PDFReports/API.php
index 5c33b44e6dcd9aba70020039cdee8e251be9f0ce..5a048ed1dce03f2015018db140b731bfd52e24db 100644
--- a/plugins/PDFReports/API.php
+++ b/plugins/PDFReports/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_PDFReports
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The PDFReports API lets you manage Scheduled Email reports, as well as generate, download or email any existing report.
diff --git a/plugins/PDFReports/Controller.php b/plugins/PDFReports/Controller.php
index 9ec3dc91f53e378fa6ad3e92ee1ebc17cff5f0eb..1203246a1e6ca568de2f216e4aa120c607c92d4f 100644
--- a/plugins/PDFReports/Controller.php
+++ b/plugins/PDFReports/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_PDFReports
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/PDFReports/PDFReports.php b/plugins/PDFReports/PDFReports.php
index ca977f73a72a5bdfc1a1873fea3cd57e16f7f667..a7bc831e8007733b19a0eafa554204025d97a7ad 100644
--- a/plugins/PDFReports/PDFReports.php
+++ b/plugins/PDFReports/PDFReports.php
@@ -9,6 +9,7 @@
  * @package Piwik_PDFReports
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/PrivacyManager/Controller.php b/plugins/PrivacyManager/Controller.php
index 15508cb5db131057f5c2775cf61c35e6b208758a..3791d830c711e4003be23041afe66aad638ced32 100644
--- a/plugins/PrivacyManager/Controller.php
+++ b/plugins/PrivacyManager/Controller.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/PrivacyManager/LogDataPurger.php b/plugins/PrivacyManager/LogDataPurger.php
index 7a4f846a69366fc12fc00af1de4f388db9f34ee7..6b9fc829ef0130053be4feb8a7c59171ce150342 100755
--- a/plugins/PrivacyManager/LogDataPurger.php
+++ b/plugins/PrivacyManager/LogDataPurger.php
@@ -9,6 +9,7 @@
  * @package Piwik_PrivacyManager
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Purges the log_visit, log_conversion and related tables of old visit data.
diff --git a/plugins/PrivacyManager/PrivacyManager.php b/plugins/PrivacyManager/PrivacyManager.php
index 1c9cab13b07d9c54b4448b6276953438ebd694c5..39381d8cd25d9b42219ac21d3ff920fc832d13ce 100644
--- a/plugins/PrivacyManager/PrivacyManager.php
+++ b/plugins/PrivacyManager/PrivacyManager.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see plugins/PrivacyManager/LogDataPurger.php
diff --git a/plugins/Provider/Provider.php b/plugins/Provider/Provider.php
index 6a22f1ba4f35213cbe282e3b70dc772657d22b38..ab06434fe461b80537526b9909facd446e40c8ed 100644
--- a/plugins/Provider/Provider.php
+++ b/plugins/Provider/Provider.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_Provider
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Provider/functions.php b/plugins/Provider/functions.php
index 62f16590cd9881f2662c0da91a62ed85c8f534f1..1c36f8a9291266081a67d7a7ff284d61049aa4c4 100644
--- a/plugins/Provider/functions.php
+++ b/plugins/Provider/functions.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_Provider
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Return hostname portion of a domain name
diff --git a/plugins/Proxy/Controller.php b/plugins/Proxy/Controller.php
index 4a5ddc14dc676d725c00216d3a28d74beaeb51af..cac2e2505e76b6f42e266c41cbcffaf4c03c96f5 100644
--- a/plugins/Proxy/Controller.php
+++ b/plugins/Proxy/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_Proxy
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Controller for proxy services
diff --git a/plugins/Referers/API.php b/plugins/Referers/API.php
index e4cf16596b60b5058b9cd0a4e400370238b662b4..f71d3c2a45cdc4a256b2cc5e52e5257f7e36af5b 100644
--- a/plugins/Referers/API.php
+++ b/plugins/Referers/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_Referers
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The Referrers API lets you access reports about Websites, Search engines, Keywords, Campaigns used to access your website.
diff --git a/plugins/Referers/Archiver.php b/plugins/Referers/Archiver.php
index 6c37226e26debe007578b9a20e532f04f0e2d1d8..1ebab392d63cc63edfe2a4c739c0a36148a54ef8 100644
--- a/plugins/Referers/Archiver.php
+++ b/plugins/Referers/Archiver.php
@@ -1,5 +1,5 @@
 <?php
-use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/plugins/Referers/Controller.php b/plugins/Referers/Controller.php
index 267718a5fe1d6f709b8245c7228f01f446a576a7..cc3d253f2934cfaa3237f9c12095bd7cc63ebb00 100644
--- a/plugins/Referers/Controller.php
+++ b/plugins/Referers/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_Referers
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Referers/functions.php b/plugins/Referers/functions.php
index 572eaa64d7ed573d2b930f9da8ad10af6e0b3904..e22f28cd1ad2e7e952f57fb37cc4da8854c488cf 100644
--- a/plugins/Referers/functions.php
+++ b/plugins/Referers/functions.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_Referers
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Returns path component from a URL
diff --git a/plugins/SEO/Controller.php b/plugins/SEO/Controller.php
index 68ae5caa128699d46b33bb3909d0c1f95c2ca508..00abd8337e5dff61103d25fb801fd1ea7591b282 100644
--- a/plugins/SEO/Controller.php
+++ b/plugins/SEO/Controller.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_SEO
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_SEO
diff --git a/plugins/SEO/MajesticClient.php b/plugins/SEO/MajesticClient.php
index f6678be192dc357462ae4f9dae52590c9bbfa23f..4834a66e8c15ec263d6337c7ef73f31e254634de 100644
--- a/plugins/SEO/MajesticClient.php
+++ b/plugins/SEO/MajesticClient.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_SEO
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Client for Majestic SEO's HTTP API.
diff --git a/plugins/SegmentEditor/API.php b/plugins/SegmentEditor/API.php
index 6b75833668c92f738a1ceee935caa756d111021e..2d5aa2b71489691804e7caab6913884b5e868fe3 100644
--- a/plugins/SegmentEditor/API.php
+++ b/plugins/SegmentEditor/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_SegmentEditor
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The SegmentEditor API lets you add, update, delete custom Segments, and list saved segments.a
diff --git a/plugins/SegmentEditor/Controller.php b/plugins/SegmentEditor/Controller.php
index f21c95bfffad3d59b9658c1347101fb92a2182e1..8fc5b6871a56a5eed2fcaeaadc4125cc40a6c5a3 100644
--- a/plugins/SegmentEditor/Controller.php
+++ b/plugins/SegmentEditor/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_SegmentEditor
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_SegmentEditor
diff --git a/plugins/SegmentEditor/SegmentEditor.php b/plugins/SegmentEditor/SegmentEditor.php
index 194f0b21682917b5c58a75bf92f890d60cdad2a5..4dd4f163acdc24ba8eecf5576d857f757d7bb910 100644
--- a/plugins/SegmentEditor/SegmentEditor.php
+++ b/plugins/SegmentEditor/SegmentEditor.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_SegmentEditor
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_SegmentEditor
diff --git a/plugins/SitesManager/API.php b/plugins/SitesManager/API.php
index cc537a43db8651a7ed4cd399b9ee335beb52c883..69a72e92cda56fcfa72ca2afa617986f3ebf0134 100644
--- a/plugins/SitesManager/API.php
+++ b/plugins/SitesManager/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_SitesManager
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The SitesManager API gives you full control on Websites in Piwik (create, update and delete), and many methods to retrieve websites based on various attributes.
diff --git a/plugins/SitesManager/Controller.php b/plugins/SitesManager/Controller.php
index adf875266fb716b97f6179043beb3f9c020f147b..3a73b32d60d33fa0e9a22fa879c2f10d61f7a895 100644
--- a/plugins/SitesManager/Controller.php
+++ b/plugins/SitesManager/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_SitesManager
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php
index 912d54e525c00f6f61ed25762339ed5b3bd80c93..4e4d0ab038543ff601343c6a0037ba356ea25e49 100644
--- a/plugins/Transitions/API.php
+++ b/plugins/Transitions/API.php
@@ -9,6 +9,7 @@
  * @package Piwik_Transitions
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @package Piwik_Transitions
diff --git a/plugins/UserCountry/Controller.php b/plugins/UserCountry/Controller.php
index ccab166581f17a4acd87defe9f017910297775ce..b6ffad1963e5eaa0a913a69d33ff1194f5b82384 100644
--- a/plugins/UserCountry/Controller.php
+++ b/plugins/UserCountry/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_UserCountry
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/UserCountry/GeoIPAutoUpdater.php b/plugins/UserCountry/GeoIPAutoUpdater.php
index d64b95c4f1ab6bc1795c3ff23c26059147f599cd..15e207edeb2324e7869c416180e439ffa6d07de6 100755
--- a/plugins/UserCountry/GeoIPAutoUpdater.php
+++ b/plugins/UserCountry/GeoIPAutoUpdater.php
@@ -9,6 +9,7 @@
  * @package Piwik_UserCountry
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Used to automatically update installed GeoIP databases, and manages the updater's
diff --git a/plugins/UserCountry/LocationProvider.php b/plugins/UserCountry/LocationProvider.php
index 0274f2b7fce976f27aaa2f002525c76ab81fa9c2..983d0f6839022929938229fc240b44938a5779dd 100755
--- a/plugins/UserCountry/LocationProvider.php
+++ b/plugins/UserCountry/LocationProvider.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_UserCountry
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see plugins/UserCountry/LocationProvider/Default.php
diff --git a/plugins/UserCountry/LocationProvider/Default.php b/plugins/UserCountry/LocationProvider/Default.php
index b7467e71d35639e18404406113429a2770d335b9..703c1441ec9eb9fe6f783c24e23725474d4da6aa 100755
--- a/plugins/UserCountry/LocationProvider/Default.php
+++ b/plugins/UserCountry/LocationProvider/Default.php
@@ -9,6 +9,7 @@
  * @package Piwik_UserCountry
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The default LocationProvider, this LocationProvider guesses a visitor's country
diff --git a/plugins/UserCountry/UserCountry.php b/plugins/UserCountry/UserCountry.php
index 5e57e053de99ad1317249991a72b568f846c39c8..c7d559b289a4f13394638571face22b8b32dc3e0 100644
--- a/plugins/UserCountry/UserCountry.php
+++ b/plugins/UserCountry/UserCountry.php
@@ -9,6 +9,7 @@
  * @package Piwik_UserCountry
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * @see plugins/UserCountry/GeoIPAutoUpdater.php
diff --git a/plugins/UserCountryMap/Controller.php b/plugins/UserCountryMap/Controller.php
index 9345f37d731cc64b23774c6be0c3d2455a90f912..8e732b399c2987090fe08a801f72b9c8e5b2e21f 100644
--- a/plugins/UserCountryMap/Controller.php
+++ b/plugins/UserCountryMap/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_UserCountryMap
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/UserSettings/Archiver.php b/plugins/UserSettings/Archiver.php
index d6ba9e32b21a9b426d387a74349c99d84dae3a63..817b8b9a5e4454308dec4f764ac1cbb2090ba945 100644
--- a/plugins/UserSettings/Archiver.php
+++ b/plugins/UserSettings/Archiver.php
@@ -9,6 +9,8 @@
  * @package Piwik_UserSettings
  */
 
+use Piwik\Core\Piwik_Common;
+
 require_once PIWIK_INCLUDE_PATH . '/plugins/UserSettings/functions.php';
 
 class Piwik_UserSettings_Archiver extends Piwik_PluginsArchiver
diff --git a/plugins/UsersManager/API.php b/plugins/UsersManager/API.php
index 1670b367df690c643a7e86dfc3475133dda18ea4..411cd735a2865432f9cab2b4bed6bca18fb17a4a 100644
--- a/plugins/UsersManager/API.php
+++ b/plugins/UsersManager/API.php
@@ -10,6 +10,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * The UsersManager API lets you Manage Users and their permissions to access specific websites.
diff --git a/plugins/UsersManager/Controller.php b/plugins/UsersManager/Controller.php
index 5ee315d2f2727235bd3fe35c71099bfb4db93270..322a4ebff0c6a335a81c5a4bd230e90b11ea442d 100644
--- a/plugins/UsersManager/Controller.php
+++ b/plugins/UsersManager/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_UsersManager
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/VisitFrequency/Controller.php b/plugins/VisitFrequency/Controller.php
index 527b8c0ac886984548d83ffbc63bc2d85f1f3963..0c32d3dcf6fcbee76add8d199bd9020e27657331 100644
--- a/plugins/VisitFrequency/Controller.php
+++ b/plugins/VisitFrequency/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_VisitFrequency
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/VisitTime/VisitTime.php b/plugins/VisitTime/VisitTime.php
index 18e6fde02fdfe4e023482083055c236764df299c..dee8d07368e07369b1e271be36fa84ecd05248d3 100644
--- a/plugins/VisitTime/VisitTime.php
+++ b/plugins/VisitTime/VisitTime.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_VisitTime
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/VisitorGenerator/Controller.php b/plugins/VisitorGenerator/Controller.php
index 43f4669ea092bec08dd786a22f655115a63f7069..cb9a567b523ab9416162f482e0a1285951aea93d 100644
--- a/plugins/VisitorGenerator/Controller.php
+++ b/plugins/VisitorGenerator/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_VisitorGenerator
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/VisitsSummary/Controller.php b/plugins/VisitsSummary/Controller.php
index ec058e6aabcf1b18a9bfd324f12d6cc9e8028cb6..3dc80647a4c08d0470ecdd172f5a06953116c5d7 100644
--- a/plugins/VisitsSummary/Controller.php
+++ b/plugins/VisitsSummary/Controller.php
@@ -9,6 +9,7 @@
  * @package Piwik_VisitsSummary
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/plugins/Widgetize/Controller.php b/plugins/Widgetize/Controller.php
index 1f326563b813bbf4ec29ffc3cd73cc356021bee7..c8751b6b7bb4e6f26e8f7f1be90565649a750ea2 100644
--- a/plugins/Widgetize/Controller.php
+++ b/plugins/Widgetize/Controller.php
@@ -8,6 +8,7 @@
  * @category Piwik_Plugins
  * @package Piwik_Widgetize
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  *
diff --git a/tests/PHPUnit/BaseFixture.php b/tests/PHPUnit/BaseFixture.php
index fae7717825022e9edc4e7d25358604e3776aa690..812fdc2960d1e294760c7b5e1510d752846ab81b 100644
--- a/tests/PHPUnit/BaseFixture.php
+++ b/tests/PHPUnit/BaseFixture.php
@@ -6,6 +6,7 @@
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Base type for all integration test fixtures. Integration test fixtures
diff --git a/tests/PHPUnit/BenchmarkTestCase.php b/tests/PHPUnit/BenchmarkTestCase.php
index 46f2400d75c83333dd257f4b4149064a830b1b0d..72df0a58dcd2a6b61dc9608f4b98e09167e6fa74 100755
--- a/tests/PHPUnit/BenchmarkTestCase.php
+++ b/tests/PHPUnit/BenchmarkTestCase.php
@@ -6,6 +6,7 @@
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  */
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/IntegrationTestCase.php';
 require_once PIWIK_INCLUDE_PATH . '/tests/LocalTracker.php';
diff --git a/tests/PHPUnit/Benchmarks/Fixtures/SqlDump.php b/tests/PHPUnit/Benchmarks/Fixtures/SqlDump.php
index fb73285612e35b5e579020baca4c394029df0dda..ee8a4f8b4946500cc87a0ce51b954d4dd3858b10 100755
--- a/tests/PHPUnit/Benchmarks/Fixtures/SqlDump.php
+++ b/tests/PHPUnit/Benchmarks/Fixtures/SqlDump.php
@@ -7,6 +7,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Reusable fixture. Loads a ~1GB SQL dump into the DB.
diff --git a/tests/PHPUnit/Core/ArchiveProcessingTest.php b/tests/PHPUnit/Core/ArchiveProcessingTest.php
index 596c7973c4d20abcca7dd38960f1a4010e9cde2a..dd1e9a8186d8363c7c3afc1389678dd9b9a1f7df 100644
--- a/tests/PHPUnit/Core/ArchiveProcessingTest.php
+++ b/tests/PHPUnit/Core/ArchiveProcessingTest.php
@@ -1,6 +1,7 @@
 <?php
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/tests/PHPUnit/Core/CommonTest.php b/tests/PHPUnit/Core/CommonTest.php
index 4f882e09336e5a048b989e75cd576fecd27de680..f8d7b431b7c0b9e7dc93902185da84889dfd8f1a 100644
--- a/tests/PHPUnit/Core/CommonTest.php
+++ b/tests/PHPUnit/Core/CommonTest.php
@@ -1,4 +1,6 @@
 <?php
+use Piwik\Core\Piwik_Common;
+
 /**
  * Piwik - Open source web analytics
  *
diff --git a/tests/PHPUnit/Core/IPTest.php b/tests/PHPUnit/Core/IPTest.php
index f9ae6bc3d37a9f8f8dc68ec46e248f770b41fae7..3ca6be38dc492a0773f77692fcb16c605d4598cd 100644
--- a/tests/PHPUnit/Core/IPTest.php
+++ b/tests/PHPUnit/Core/IPTest.php
@@ -1,5 +1,6 @@
 <?php
 use Piwik\Core\Config;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/tests/PHPUnit/Core/OptionTest.php b/tests/PHPUnit/Core/OptionTest.php
index 63c59036367d1401fee15e0c484d9b4b83006238..eafb246501f15cdbf71b15a5f07ad0a1e597f940 100644
--- a/tests/PHPUnit/Core/OptionTest.php
+++ b/tests/PHPUnit/Core/OptionTest.php
@@ -5,6 +5,8 @@
  * @link http://piwik.org
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  */
+use Piwik\Core\Piwik_Common;
+
 require_once "Option.php";
 
 class OptionTest extends DatabaseTestCase
diff --git a/tests/PHPUnit/Core/ReleaseCheckListTest.php b/tests/PHPUnit/Core/ReleaseCheckListTest.php
index 04cb72a5a358b1a6a471d0b8b2cf82bc871899a9..e24f9cf144bc3d19e21a7b2c319f3029a987a473 100644
--- a/tests/PHPUnit/Core/ReleaseCheckListTest.php
+++ b/tests/PHPUnit/Core/ReleaseCheckListTest.php
@@ -1,5 +1,6 @@
 <?php
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Piwik - Open source web analytics
diff --git a/tests/PHPUnit/Core/SegmentTest.php b/tests/PHPUnit/Core/SegmentTest.php
index 3f881e9eb3e4e4e3a81c17a98708a2c9b9b66181..bbc8f4d70e58bc311180c3fdf441485ef06b980d 100644
--- a/tests/PHPUnit/Core/SegmentTest.php
+++ b/tests/PHPUnit/Core/SegmentTest.php
@@ -1,4 +1,6 @@
 <?php
+use Piwik\Core\Piwik_Common;
+
 /**
  * Piwik - Open source web analytics
  *
diff --git a/tests/PHPUnit/Core/ServeStaticFileTest.php b/tests/PHPUnit/Core/ServeStaticFileTest.php
index 764fd85e176a3913a9ee761c5289c3ede31acf63..034a64a4ba5f97dd981f9a9a30978bac290f4e66 100644
--- a/tests/PHPUnit/Core/ServeStaticFileTest.php
+++ b/tests/PHPUnit/Core/ServeStaticFileTest.php
@@ -13,6 +13,7 @@
 
 // This is Piwik logo, the static file used in this test suit
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 define("TEST_FILE_LOCATION", realpath(dirname(__FILE__) . "/../../resources/lipsum.txt"));
 define("TEST_FILE_CONTENT_TYPE", "text/plain");
diff --git a/tests/PHPUnit/Core/TranslationWriterTest.php b/tests/PHPUnit/Core/TranslationWriterTest.php
index 27a4fa597a2a2522a2d4752de5cf2bd6f29913c9..187996ed0b22333190b319601a8228bd93d0e0e2 100644
--- a/tests/PHPUnit/Core/TranslationWriterTest.php
+++ b/tests/PHPUnit/Core/TranslationWriterTest.php
@@ -1,4 +1,6 @@
 <?php
+use Piwik\Core\Piwik_Common;
+
 /**
  * Piwik - Open source web analytics
  *
diff --git a/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php b/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php
index 80f36f55445353c6832af491352a88a7df59c2dc..df3fd04f16a2fbc0c85a1384dc749ab564ca74ed 100644
--- a/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php
+++ b/tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php
@@ -5,6 +5,8 @@
  * @link    http://piwik.org
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  */
+use Piwik\Core\Piwik_Common;
+
 require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Fixtures/ManySitesImportedLogs.php';
 
 /**
diff --git a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php
index e416615da9def6ae2fced82c7c6e2bc1b4931b84..92f495fac102c6a055b743bbd1ec0f660aa7946a 100755
--- a/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php
+++ b/tests/PHPUnit/Integration/OneVisitorOneWebsite_SeveralDaysDateRange_ArchivingTestsTest.php
@@ -6,6 +6,7 @@
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 /**
  * Tests some API using range periods & makes sure the correct amount of blob/numeric
diff --git a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php
index fd08f464cd357c796d6d9e459cc79d528f1740e0..3fd750022b7e1c6897b5a9cef4b10507e1102aee 100755
--- a/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php
+++ b/tests/PHPUnit/Integration/TwoVisitsWithCustomVariables_SegmentMatchVisitorTypeTest.php
@@ -5,6 +5,7 @@
  * @link    http://piwik.org
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  */
+use Piwik\Core\Piwik_Common;
 
 /**
  * Tests use of custom variable segments.
diff --git a/tests/PHPUnit/Integration/UrlNormalizationTest.php b/tests/PHPUnit/Integration/UrlNormalizationTest.php
index 690a2a57ba37dd5ee7549915edf15d2e751dfba5..a2b0e6c7027e60e42f9eb5f64a12b05565f004c8 100644
--- a/tests/PHPUnit/Integration/UrlNormalizationTest.php
+++ b/tests/PHPUnit/Integration/UrlNormalizationTest.php
@@ -1,4 +1,6 @@
 <?php
+use Piwik\Core\Piwik_Common;
+
 /**
  * Tests the URL normalization.
  */
diff --git a/tests/PHPUnit/IntegrationTestCase.php b/tests/PHPUnit/IntegrationTestCase.php
index 2c662f39f5dc6109d09c850bbd0b772d5eecd02d..86460d46d51de8647232c0ff3e233e7c829dee89 100755
--- a/tests/PHPUnit/IntegrationTestCase.php
+++ b/tests/PHPUnit/IntegrationTestCase.php
@@ -7,6 +7,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 require_once PIWIK_INCLUDE_PATH . '/libs/PiwikTracker/PiwikTracker.php';
 
diff --git a/tests/PHPUnit/Plugins/LanguagesManagerTest.php b/tests/PHPUnit/Plugins/LanguagesManagerTest.php
index 9acc5f3a9efd39715c55149e70224f68a366a51c..2b47a4bb805f144adc6e8afe7feb94ad649878d1 100755
--- a/tests/PHPUnit/Plugins/LanguagesManagerTest.php
+++ b/tests/PHPUnit/Plugins/LanguagesManagerTest.php
@@ -5,6 +5,8 @@
  * @link    http://piwik.org
  * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
  */
+use Piwik\Core\Piwik_Common;
+
 require_once 'LanguagesManager/API.php';
 
 class Test_LanguagesManager extends PHPUnit_Framework_TestCase
diff --git a/tests/PHPUnit/Plugins/PrivacyManagerTest.php b/tests/PHPUnit/Plugins/PrivacyManagerTest.php
index ffcfe6a38f3ef6500a01de5db08cde9c090da399..2b81e55dadcfb912aa47a42aa800dbd7aac102b5 100755
--- a/tests/PHPUnit/Plugins/PrivacyManagerTest.php
+++ b/tests/PHPUnit/Plugins/PrivacyManagerTest.php
@@ -7,6 +7,7 @@
  */
 use Piwik\Core\Config;
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 require_once 'PrivacyManager/PrivacyManager.php';
 
diff --git a/tests/resources/staticFileServer.php b/tests/resources/staticFileServer.php
index da49ceb7adf413b8e8b509646b3c11a11948cf0b..e0e2a00dc1384f946e61fb1a539f8605e0342a59 100644
--- a/tests/resources/staticFileServer.php
+++ b/tests/resources/staticFileServer.php
@@ -10,6 +10,7 @@
  * serveStaticFile.test.php has been created to avoid making too many modifications to /tests/core/Piwik.test.php
  */
 use Piwik\Core\Piwik;
+use Piwik\Core\Piwik_Common;
 
 define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__).'/../../');
 if(file_exists(PIWIK_DOCUMENT_ROOT . '/bootstrap.php'))