From f7c1ecc5ee270b2a97dcf61cc37d5652a8ead1a3 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Tue, 19 Apr 2011 10:13:25 +0000 Subject: [PATCH] Removed JavaScriptDistiller: unused --- includes/AutoLoader.php | 1 - includes/libs/JavaScriptDistiller.php | 337 ------------------ .../includes/libs/JavaScriptDistillerTest.php | 18 - tests/phpunit/includes/libs/distiller-in.js | 15 - .../includes/libs/distiller-out-full.js | 7 - tests/phpunit/includes/libs/distiller-out.js | 11 - 6 files changed, 389 deletions(-) delete mode 100644 includes/libs/JavaScriptDistiller.php delete mode 100644 tests/phpunit/includes/libs/JavaScriptDistillerTest.php delete mode 100644 tests/phpunit/includes/libs/distiller-in.js delete mode 100644 tests/phpunit/includes/libs/distiller-out-full.js delete mode 100644 tests/phpunit/includes/libs/distiller-out.js diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index 2a92f8c1e1..ebecd779e4 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -494,7 +494,6 @@ $wgAutoloadLocalClasses = array( 'CSSJanus' => 'includes/libs/CSSJanus.php', 'CSSMin' => 'includes/libs/CSSMin.php', 'IEContentAnalyzer' => 'includes/libs/IEContentAnalyzer.php', - 'JavaScriptDistiller' => 'includes/libs/JavaScriptDistiller.php', 'JavaScriptMinifier' => 'includes/libs/JavaScriptMinifier.php', 'Spyc' => 'includes/libs/spyc.php', diff --git a/includes/libs/JavaScriptDistiller.php b/includes/libs/JavaScriptDistiller.php deleted file mode 100644 index 0ceeb64e0a..0000000000 --- a/includes/libs/JavaScriptDistiller.php +++ /dev/null @@ -1,337 +0,0 @@ - 1000 ) { - ini_set( 'pcre.recursion_limit', '1000' ); - } - - $script = self::stripHorizontalSpace( $script ); - // If requested, make some vertical whitespace collapsing as well - if ( $stripVerticalSpace ) { - $script = self::stripVerticalSpace( $script ); - } - // Done - ini_set( 'pcre.recursion_limit', $oldLimit ); - return $script; - } - - public static function stripHorizontalSpace( $script ) { - $parser = self::createParser(); - // Collapse horizontal whitespaces between variable names into a single space - $parser->add( '(\b|\$) [ \t]+ (\b|\$)', '$2 $3' ); - // Collapse horizontal whitespaces between unary operators into a single space - $parser->add( '([+\-]) [ \t]+ ([+\-])', '$2 $3' ); - // Remove all remaining un-protected horizontal whitespace - $parser->add( '[ \t]+'); - // Collapse multiple vertical whitespaces with some horizontal spaces between them - $parser->add( '[\r\n]+ [ \t]* [\r\n]+', "\n" ); - // Execute and return - return $parser->exec($script); - } - - public static function stripVerticalSpace( $script ) { - $parser = self::createParser(); - // Collapse whitespaces between and after a ){ pair (function definitions) - $parser->add( '\) \s+ \{ \s+', '){' ); - // Collapse whitespaces between and after a ({ pair (JSON argument) - $parser->add( '\( \s+ \{ \s+', '({' ); - // Collapse whitespaces between a parenthesis and a period (call chaining) - $parser->add( '\) \s+ \.', ').'); - // Collapse vertical whitespaces which come directly after a semicolon or a comma - $parser->add( '( [;,] ) \s+', '$2' ); - // Collapse whitespaces between multiple parenthesis/brackets of similar direction - $parser->add( '( [\)\}] ) \s+ ( [\)\}] )', '$2$3' ); - $parser->add( '( [\(\{] ) \s+ ( [\(\{] )', '$2$3' ); - return $parser->exec( $script ); - } - - /* - * Creates an instance of ParseMaster and protects sensitive JavaScript regions. - * - * This parser is based on regular expressions, which all get or'd together, so rules take - * precedence in the order they are added. We can use it to minify by armoring certain regions - * by matching them and replacing them with the full match, leaving the remaining regions around - * for further matching and replacing. When creating rules please note that because ParseMaster - * "or"s all of the rules together in a single pattern, encapsulating them in parenthesis, $1 - * represents the whole match for a given rule, and $2 is the first submatch. - */ - private static function createParser() { - $parser = new ParseMaster(); - // There is a bug in ParseMaster that causes a backslash at the end of a line to be changed - // to \s if we use a backslash as the escape character. We work around this by using an - // obscure escape character that we hope will never appear at the end of a line. - $parser->escapeChar = chr( 1 ); - - // C-style comment: use non-greedy repetition to find the end - $parser->add( '\/ \* .*? \* \/' ); - - // Preserve the newline after a C++-style comment -- bug 27046 - $parser->add( '\/ \/ [^\r\n]* ( [\r\n] )', '$2' ); - - // Protect strings. The original code had [^\'\\v] here, but that didn't armor multiline - // strings correctly. This also armors multiline strings that don't have backslashes at the - // end of the line (these are invalid), but that's fine because we're just armoring here. - - // Single quotes - $parser->add( - '\'' . // start quote - '[^\'\\\\]*' . // a run of non-special characters - '(?:' . - '\\\\ .' . // a backslash followed by any character - '[^\'\\\\]*' . // a run of non-special characters - ')*' . // any number of the above - '\'', // end quote - '$1' ); - - // Double quotes: same as above - $parser->add( '" [^"\\\\]* (?: \\\\ . [^"\\\\]* )* "', '$1' ); - - // Protect regular expressions - $parser->add( - '(?<= [ \t] | [^\w\$\/\'"*)\?:] )' . // assert that whitespace or punctuation precedes - '\/' . // start slash - '[^\r\n\*]' . // not a comment-start or line ending - '[^\/\r\n\\\\]*' . // a sequence of non-special characters - '(?:' . - '\\\\ .' . // a backslash followed by any character - '[^\/\r\n\\\\]*' . // a sequence of non-special characters - ')*' . // any number of the above - '\/[ig]*' , // pattern end, optional modifier - '$1' ); - return $parser; - } -} - -/** - * ParseMaster, version 1.0.2 (2005-08-19) Copyright 2005, Dean Edwards - * A multi-pattern parser. - * License: http://creativecommons.org/licenses/LGPL/2.1/ - * - * This is the PHP version of the ParseMaster component of Dean Edwards' (http://dean.edwards.name/) - * Packer, which was originally written in JavaScript. It was ported to PHP by Nicolas Martin. - * - * Original Source: http://joliclic.free.fr/php/javascript-packer/en/ - * - * Changes should be pushed back upstream. - */ -class ParseMaster { - public $ignoreCase = false; - public $escapeChar = ''; - - // constants - const EXPRESSION = 0; - const REPLACEMENT = 1; - const LENGTH = 2; - - // used to determine nesting levels - private $GROUPS = '/\( (?! \? ) /x';//g - private $SUB_REPLACE = '/\$\d/'; - private $INDEXED = '/^\$\d+$/'; - private $ESCAPE = '/\\\./';//g - private $QUOTE = '/\'/'; - private $DELETED = '/\x01[^\x01]*\x01/';//g - - public function add($expression, $replacement = '') { - // count the number of sub-expressions - // - add one because each pattern is itself a sub-expression - $length = 1 + preg_match_all($this->GROUPS, $this->_internalEscape((string)$expression), $out); - - // treat only strings $replacement - if (is_string($replacement)) { - // does the pattern deal with sub-expressions? - if (preg_match($this->SUB_REPLACE, $replacement)) { - // a simple lookup? (e.g. "$2") - if (preg_match($this->INDEXED, $replacement)) { - // store the index (used for fast retrieval of matched strings) - $replacement = (int)(substr($replacement, 1)) - 1; - } else { // a complicated lookup (e.g. "Hello $2 $1") - // build a function to do the lookup - $quote = preg_match($this->QUOTE, $this->_internalEscape($replacement)) - ? '"' : "'"; - $replacement = array( - 'fn' => '_backReferences', - 'data' => array( - 'replacement' => $replacement, - 'length' => $length, - 'quote' => $quote - ) - ); - } - } - } - // pass the modified arguments - if (!empty($expression)) $this->_add($expression, $replacement, $length); - else $this->_add('/^$/', $replacement, $length); - } - - public function exec($string) { - // execute the global replacement - $this->_escaped = array(); - - // simulate the _patterns.toSTring of Dean - $regexp = '/'; - foreach ($this->_patterns as $reg) { - $regexp .= '(' . $reg[self::EXPRESSION] . ")|\n"; - } - $regexp = substr($regexp, 0, -2) . '/Sxs'; - $regexp .= ($this->ignoreCase) ? 'i' : ''; - - $string = $this->_escape($string, $this->escapeChar); - $string = preg_replace_callback( - $regexp, - array( - &$this, - '_replacement' - ), - $string - ); - $string = $this->_unescape($string, $this->escapeChar); - - return preg_replace($this->DELETED, '', $string); - } - - public function reset() { - // clear the patterns collection so that this object may be re-used - $this->_patterns = array(); - } - - // private - private $_escaped = array(); // escaped characters - private $_patterns = array(); // patterns stored by index - - // create and add a new pattern to the patterns collection - private function _add() { - $arguments = func_get_args(); - $this->_patterns[] = $arguments; - } - - // this is the global replace function (it's quite complicated) - private function _replacement($arguments) { - if (empty($arguments)) return ''; - - $i = 1; $j = 0; - // loop through the patterns - while (isset($this->_patterns[$j])) { - $pattern = $this->_patterns[$j++]; - // do we have a result? - if (isset($arguments[$i]) && ($arguments[$i] != '')) { - $replacement = $pattern[self::REPLACEMENT]; - - if (is_array($replacement) && isset($replacement['fn'])) { - - if (isset($replacement['data'])) $this->buffer = $replacement['data']; - return call_user_func(array(&$this, $replacement['fn']), $arguments, $i); - - } elseif (is_int($replacement)) { - return $arguments[$replacement + $i]; - - } - $delete = ($this->escapeChar == '' || - strpos($arguments[$i], $this->escapeChar) === false) - ? '' : "\x01" . $arguments[$i] . "\x01"; - return $delete . $replacement; - - // skip over references to sub-expressions - } else { - $i += $pattern[self::LENGTH]; - } - } - } - - private function _backReferences($match, $offset) { - $replacement = $this->buffer['replacement']; - //$quote = $this->buffer['quote']; - $i = $this->buffer['length']; - while ($i) { - $replacement = str_replace('$'.$i--, $match[$offset + $i], $replacement); - } - return $replacement; - } - - private function _replace_name($match, $offset){ - $length = strlen($match[$offset + 2]); - $start = $length - max($length - strlen($match[$offset + 3]), 0); - return substr($match[$offset + 1], $start, $length) . $match[$offset + 4]; - } - - private function _replace_encoded($match, $offset) { - return $this->buffer[$match[$offset]]; - } - - - // php : we cannot pass additional data to preg_replace_callback, - // and we cannot use &$this in create_function, so let's go to lower level - private $buffer; - - // encode escaped characters - private function _escape($string, $escapeChar) { - if ($escapeChar) { - $this->buffer = $escapeChar; - return preg_replace_callback( - '/\\' . $escapeChar . '(.)' .'/', - array(&$this, '_escapeBis'), - $string - ); - - } else { - return $string; - } - } - private function _escapeBis($match) { - $this->_escaped[] = $match[1]; - return $this->buffer; - } - - // decode escaped characters - private function _unescape($string, $escapeChar) { - if ($escapeChar) { - $regexp = '/'.'\\'.$escapeChar.'/'; - $this->buffer = array('escapeChar'=> $escapeChar, 'i' => 0); - return preg_replace_callback - ( - $regexp, - array(&$this, '_unescapeBis'), - $string - ); - - } else { - return $string; - } - } - private function _unescapeBis() { - if (isset($this->_escaped[$this->buffer['i']]) - && $this->_escaped[$this->buffer['i']] != '') - { - $temp = $this->_escaped[$this->buffer['i']]; - } else { - $temp = ''; - } - $this->buffer['i']++; - return $this->buffer['escapeChar'] . $temp; - } - - private function _internalEscape($string) { - return preg_replace($this->ESCAPE, '', $string); - } -} diff --git a/tests/phpunit/includes/libs/JavaScriptDistillerTest.php b/tests/phpunit/includes/libs/JavaScriptDistillerTest.php deleted file mode 100644 index ddacd1e4df..0000000000 --- a/tests/phpunit/includes/libs/JavaScriptDistillerTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertEquals( $out, JavaScriptDistiller::stripWhiteSpace( $in ) ); - $this->assertEquals( $outFull, JavaScriptDistiller::stripWhiteSpace( $in, true ) ); - } - - private static function read( $file ) { - $text = file_get_contents( dirname( __FILE__ ) . "/$file" ); - return str_replace( "\r\n", "\n", $text ); - } -} \ No newline at end of file diff --git a/tests/phpunit/includes/libs/distiller-in.js b/tests/phpunit/includes/libs/distiller-in.js deleted file mode 100644 index 66116957e7..0000000000 --- a/tests/phpunit/includes/libs/distiller-in.js +++ /dev/null @@ -1,15 +0,0 @@ -/* this is a comment */ -/* a multi- - line comment */ -/* a /* weird comment */ -// one-line comment -var string = /* comment */'/* comment in string */'; - -move_to_the_same_line() - - dont_move(); - -if ( / a + bfoo.* /i.test( bar ) && ( a / b ) * c + d - e) { /* blah */ - statement(); - statement() -} \ No newline at end of file diff --git a/tests/phpunit/includes/libs/distiller-out-full.js b/tests/phpunit/includes/libs/distiller-out-full.js deleted file mode 100644 index ae0b35671d..0000000000 --- a/tests/phpunit/includes/libs/distiller-out-full.js +++ /dev/null @@ -1,7 +0,0 @@ - - - - -var string='/* comment in string */';move_to_the_same_line() -dont_move();if(/ a + bfoo.* /i.test(bar)&&(a/ b ) * c + d - e){ -statement();statement()} \ No newline at end of file diff --git a/tests/phpunit/includes/libs/distiller-out.js b/tests/phpunit/includes/libs/distiller-out.js deleted file mode 100644 index 1886143428..0000000000 --- a/tests/phpunit/includes/libs/distiller-out.js +++ /dev/null @@ -1,11 +0,0 @@ - - - - -var string='/* comment in string */'; -move_to_the_same_line() -dont_move(); -if(/ a + bfoo.* /i.test(bar)&&(a/ b ) * c + d - e) { /*blah*/ -statement(); -statement() -} \ No newline at end of file -- 2.20.1