Merge "Revert "Revert "jQuery 1.8"""
[lhc/web/wiklou.git] / maintenance / minify.php
index de9c53a..9f5a909 100644 (file)
  * @ingroup Maintenance
  */
 
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once( __DIR__ . '/Maintenance.php' );
 
+/**
+ * Maintenance script that minifies a file or set of files.
+ *
+ * @ingroup Maintenance
+ */
 class MinifyScript extends Maintenance {
        var $outDir;
 
@@ -35,8 +40,11 @@ class MinifyScript extends Maintenance {
                        "Directory for output. If this is not specified, and neither is --outfile, then the\n" .
                        "output files will be sent to the same directories as the input files.",
                        false, true );
-               $this->addOption( 'minify-vertical-space',
-                       "Boolean value for minifying the vertical space for javascript.",
+               $this->addOption( 'js-statements-on-own-line',
+                       "Boolean value for putting statements on their own line when minifying JavaScript.",
+                       false, true );
+               $this->addOption( 'js-max-line-length',
+                       "Maximum line length for JavaScript minification.",
                        false, true );
                $this->mDescription = "Minify a file or set of files.\n\n" .
                        "If --outfile is not specified, then the output file names will have a .min extension\n" .
@@ -92,14 +100,14 @@ class MinifyScript extends Maintenance {
        public function getExtension( $fileName ) {
                $dotPos = strrpos( $fileName, '.' );
                if ( $dotPos === false ) {
-                       $this->error( "No file extension, cannot determine type: $arg" );
+                       $this->error( "No file extension, cannot determine type: $fileName" );
                        exit( 1 );
                }
                return substr( $fileName, $dotPos + 1 );
        }
 
        public function minify( $inPath, $outPath ) {
-               global $wgResourceLoaderMinifyJSVerticalSpace;
+               global $wgResourceLoaderMinifierStatementsOnOwnLine, $wgResourceLoaderMinifierMaxLineLength;
 
                $extension = $this->getExtension( $inPath );
                $this->output( basename( $inPath ) . ' -> ' . basename( $outPath ) . '...' );
@@ -117,7 +125,10 @@ class MinifyScript extends Maintenance {
 
                switch ( $extension ) {
                        case 'js':
-                               $outText = JavaScriptDistiller::stripWhiteSpace( $inText, $this->getOption( 'minify-vertical-space', $wgResourceLoaderMinifyJSVerticalSpace ) );
+                               $outText = JavaScriptMinifier::minify( $inText,
+                                       $this->getOption( 'js-statements-on-own-line', $wgResourceLoaderMinifierStatementsOnOwnLine ),
+                                       $this->getOption( 'js-max-line-length', $wgResourceLoaderMinifierMaxLineLength )
+                               );
                                break;
                        case 'css':
                                $outText = CSSMin::minify( $inText );