MediaWiki
REL1_19
|
00001 <?php 00023 require_once( dirname( __FILE__ ) . '/Maintenance.php' ); 00024 00025 class JSParseHelper extends Maintenance { 00026 var $errs = 0; 00027 00028 public function __construct() { 00029 parent::__construct(); 00030 $this->mDescription = "Runs parsing/syntax checks on JavaScript files"; 00031 $this->addArg( 'file(s)', 'JavaScript file to test', false ); 00032 } 00033 00034 public function execute() { 00035 if ( $this->hasArg() ) { 00036 $files = $this->mArgs; 00037 } else { 00038 $this->maybeHelp( true ); // @fixme this is a lame API :) 00039 exit( 1 ); // it should exit from the above first... 00040 } 00041 00042 $parser = new JSParser(); 00043 foreach ( $files as $filename ) { 00044 wfSuppressWarnings(); 00045 $js = file_get_contents( $filename ); 00046 wfRestoreWarnings(); 00047 if ($js === false) { 00048 $this->output( "$filename ERROR: could not read file\n" ); 00049 $this->errs++; 00050 continue; 00051 } 00052 00053 try { 00054 $parser->parse( $js, $filename, 1 ); 00055 } catch (Exception $e) { 00056 $this->errs++; 00057 $this->output( "$filename ERROR: " . $e->getMessage() . "\n" ); 00058 continue; 00059 } 00060 00061 $this->output( "$filename OK\n" ); 00062 } 00063 00064 if ($this->errs > 0) { 00065 exit(1); 00066 } 00067 } 00068 } 00069 00070 $maintClass = "JSParseHelper"; 00071 require_once( RUN_MAINTENANCE_IF_MAIN );