Merge "Don't ask users to mark own page creations as patrolled"
[lhc/web/wiklou.git] / includes / libs / CSSJanus.php
index ac33448..128d9b9 100644 (file)
@@ -76,6 +76,7 @@ class CSSJanus {
                'cursor_west' => null,
                'four_notation_quantity' => null,
                'four_notation_color' => null,
+               'border_radius' => null,
                'bg_horizontal_percentage' => null,
                'bg_horizontal_percentage_x' => null,
        );
@@ -96,9 +97,9 @@ class CSSJanus {
                $patterns['ident'] = "-?{$patterns['nmstart']}{$patterns['nmchar']}*";
                $patterns['quantity'] = "{$patterns['num']}(?:\s*{$patterns['unit']}|{$patterns['ident']})?";
                $patterns['possibly_negative_quantity'] = "((?:-?{$patterns['quantity']})|(?:inherit|auto))";
-               $patterns['color'] = "(#?{$patterns['nmchar']}+)";
+               $patterns['color'] = "(#?{$patterns['nmchar']}+|(?:rgba?|hsla?)\([ \d.,%-]+\))";
                $patterns['url_chars'] = "(?:{$patterns['url_special_chars']}|{$patterns['nonAscii']}|{$patterns['escape']})*";
-               $patterns['lookahead_not_open_brace'] = "(?!({$patterns['nmchar']}|\r?\n|\s|#|\:|\.|\,|\+|>)*?{)";
+               $patterns['lookahead_not_open_brace'] = "(?!({$patterns['nmchar']}|\r?\n|\s|#|\:|\.|\,|\+|>|\(|\))*?{)";
                $patterns['lookahead_not_closing_paren'] = "(?!{$patterns['url_chars']}?{$patterns['valid_after_uri_chars']}\))";
                $patterns['lookahead_for_closing_paren'] = "(?={$patterns['url_chars']}?{$patterns['valid_after_uri_chars']}\))";
                $patterns['noflip_single'] = "/({$patterns['noflip_annotation']}{$patterns['lookahead_not_open_brace']}[^;}]+;?)/i";
@@ -115,6 +116,7 @@ class CSSJanus {
                $patterns['cursor_west'] = "/{$patterns['lookbehind_not_letter']}([ns]?)w-resize/";
                $patterns['four_notation_quantity'] = "/(:\s*){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s*[;}])/i";
                $patterns['four_notation_color'] = "/(-color\s*:\s*){$patterns['color']}(\s+){$patterns['color']}(\s+){$patterns['color']}(\s+){$patterns['color']}(\s*[;}])/i";
+               $patterns['border_radius'] = "/(border-radius\s*:\s*){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s*[;}])/i";
                // The two regexes below are parenthesized differently then in the original implementation to make the
                // callback's job more straightforward
                $patterns['bg_horizontal_percentage'] = "/(background(?:-position)?\s*:\s*[^%]*?)(-?{$patterns['num']})(%\s*(?:{$patterns['quantity']}|{$patterns['ident']}))/";
@@ -160,6 +162,7 @@ class CSSJanus {
                $css = self::fixLeftAndRight( $css );
                $css = self::fixCursorProperties( $css );
                $css = self::fixFourPartNotation( $css );
+               $css = self::fixBorderRadius( $css );
                $css = self::fixBackgroundPosition( $css );
 
                // Detokenize stuff we tokenized before
@@ -263,6 +266,22 @@ class CSSJanus {
                return $css;
        }
 
+       /**
+        * Swaps appropriate corners in four-part border-radius rules.
+        * Needs to undo the effect of fixFourPartNotation() on those rules, too.
+        *
+        * @param $css string
+        * @return string
+        */
+       private static function fixBorderRadius( $css ) {
+               // Undo four_notation_quantity
+               $css = preg_replace( self::$patterns['border_radius'], '$1$2$3$8$5$6$7$4$9', $css );
+               // Do the real thing
+               $css = preg_replace( self::$patterns['border_radius'], '$1$4$3$2$5$8$7$6$9', $css );
+
+               return $css;
+       }
+
        /**
         * Flip horizontal background percentages.
         * @param $css string