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