Merge "Enforce no-session constraint in opensearch_desc.php and profileinfo.php"
[lhc/web/wiklou.git] / includes / parser / Sanitizer.php
index 71b71e0..85c71ee 100644 (file)
@@ -24,6 +24,8 @@
  * @ingroup Parser
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * HTML sanitizer for MediaWiki
  * @ingroup Parser
@@ -1155,9 +1157,10 @@ class Sanitizer {
                $fixtags = [
                        # French spaces, last one Guillemet-left
                        # only if there is something before the space
-                       '/(.) (?=[?:;!%»])/u' => "\\1$space",
+                       # and a non-word character after the punctuation.
+                       '/(\S) (?=[?:;!%»›](?!\w))/u' => "\\1$space",
                        # French spaces, Guillemet-right
-                       '/(«) /u' => "\\1$space",
+                       '/([«‹]) /u' => "\\1$space",
                ];
                return preg_replace( array_keys( $fixtags ), array_values( $fixtags ), $text );
        }
@@ -1505,10 +1508,10 @@ class Sanitizer {
         * @return string
         */
        private static function normalizeWhitespace( $text ) {
-               return preg_replace(
-                       '/\r\n|[\x20\x0d\x0a\x09]/',
+               return trim( preg_replace(
+                       '/(?:\r\n|[\x20\x0d\x0a\x09])+/',
                        ' ',
-                       $text );
+                       $text ) );
        }
 
        /**
@@ -1656,7 +1659,6 @@ class Sanitizer {
         * @return string Still normalized, without entities
         */
        public static function decodeCharReferencesAndNormalize( $text ) {
-               global $wgContLang;
                $text = preg_replace_callback(
                        self::CHAR_REFS_REGEX,
                        [ self::class, 'decodeCharReferencesCallback' ],
@@ -1666,7 +1668,7 @@ class Sanitizer {
                );
 
                if ( $count ) {
-                       return $wgContLang->normalize( $text );
+                       return MediaWikiServices::getInstance()->getContentLanguage()->normalize( $text );
                } else {
                        return $text;
                }