Merge "Add findVariantLink to StubUserLang"
[lhc/web/wiklou.git] / includes / debug / MWDebug.php
index fb11f36..c4c6cf3 100644 (file)
@@ -26,8 +26,6 @@
  * By default, most methods do nothing ( self::$enabled = false ). You have
  * to explicitly call MWDebug::init() to enabled them.
  *
- * @todo Profiler support
- *
  * @since 1.19
  */
 class MWDebug {
@@ -46,7 +44,7 @@ class MWDebug {
        protected static $debug = array();
 
        /**
-        * SQL statements of the databses queries.
+        * SQL statements of the database queries.
         *
         * @var array $query
         */
@@ -335,6 +333,28 @@ class MWDebug {
                        return -1;
                }
 
+               // Replace invalid UTF-8 chars with a square UTF-8 character
+               // This prevents json_encode from erroring out due to binary SQL data
+               $sql = preg_replace(
+                       '/(
+                               [\xC0-\xC1] # Invalid UTF-8 Bytes
+                               | [\xF5-\xFF] # Invalid UTF-8 Bytes
+                               | \xE0[\x80-\x9F] # Overlong encoding of prior code point
+                               | \xF0[\x80-\x8F] # Overlong encoding of prior code point
+                               | [\xC2-\xDF](?![\x80-\xBF]) # Invalid UTF-8 Sequence Start
+                               | [\xE0-\xEF](?![\x80-\xBF]{2}) # Invalid UTF-8 Sequence Start
+                               | [\xF0-\xF4](?![\x80-\xBF]{3}) # Invalid UTF-8 Sequence Start
+                               | (?<=[\x0-\x7F\xF5-\xFF])[\x80-\xBF] # Invalid UTF-8 Sequence Middle
+                               | (?<![\xC2-\xDF]|[\xE0-\xEF]|[\xE0-\xEF][\x80-\xBF]|[\xF0-\xF4]
+                                  |[\xF0-\xF4][\x80-\xBF]|[\xF0-\xF4][\x80-\xBF]{2})[\x80-\xBF] # Overlong Sequence
+                               | (?<=[\xE0-\xEF])[\x80-\xBF](?![\x80-\xBF]) # Short 3 byte sequence
+                               | (?<=[\xF0-\xF4])[\x80-\xBF](?![\x80-\xBF]{2}) # Short 4 byte sequence
+                               | (?<=[\xF0-\xF4][\x80-\xBF])[\x80-\xBF](?![\x80-\xBF]) # Short 4 byte sequence (2)
+                       )/x',
+                       '■',
+                       $sql
+               );
+
                self::$query[] = array(
                        'sql' => $sql,
                        'function' => $function,
@@ -512,7 +532,6 @@ class MWDebug {
                $result->setIndexedTagName( $debugInfo['debugLog'], 'msg' );
                $result->setIndexedTagName( $debugInfo['queries'], 'query' );
                $result->setIndexedTagName( $debugInfo['includes'], 'queries' );
-               $result->setIndexedTagName( $debugInfo['profile'], 'function' );
                $result->addValue( null, 'debuginfo', $debugInfo );
        }
 
@@ -556,7 +575,6 @@ class MWDebug {
                        'memory' => $context->getLanguage()->formatSize( memory_get_usage( $realMemoryUsage ) ),
                        'memoryPeak' => $context->getLanguage()->formatSize( memory_get_peak_usage( $realMemoryUsage ) ),
                        'includes' => self::getFilesIncluded( $context ),
-                       'profile' => Profiler::instance()->getRawData(),
                );
        }
 }