$this->mDescription = "Check syntax for all PHP files in MediaWiki";
$this->addOption( 'with-extensions', 'Also recurse the extensions folder' );
$this->addOption( 'path', 'Specific path (file or directory) to check, either with absolute path or relative to the root of this MediaWiki installation',
- false, true);
- $this->addOption( 'list-file', 'Text file containing list of files or directories to check', false, true);
+ false, true );
+ $this->addOption( 'list-file', 'Text file containing list of files or directories to check', false, true );
$this->addOption( 'modified', 'Check only files that were modified (requires SVN command-line client)' );
$this->addOption( 'syntax-only', 'Check for syntax validity only, skip code style warnings' );
}
- protected function getDbType() {
+ public function getDbType() {
return Maintenance::DB_NONE;
}
// ParseKit is broken on PHP 5.3+, disabled until this is fixed
$useParseKit = function_exists( 'parsekit_compile_file' ) && version_compare( PHP_VERSION, '5.3', '<' );
- $str = 'Checking syntax (using ' . ( $useParseKit ?
- 'parsekit)' : ' php -l, this can take a long time)' );
+ $str = 'Checking syntax (using ' . ( $useParseKit ?
+ 'parsekit' : ' php -l, this can take a long time' ) . ")\n";
$this->output( $str );
- foreach( $this->mFiles as $f ) {
- if( $useParseKit ) {
+ foreach ( $this->mFiles as $f ) {
+ if ( $useParseKit ) {
$this->checkFileWithParsekit( $f );
} else {
$this->checkFileWithCli( $f );
}
- if( !$this->hasOption( 'syntax-only' ) ) {
+ if ( !$this->hasOption( 'syntax-only' ) ) {
$this->checkForMistakes( $f );
}
}
'\bphplot-',
"/svggraph/",
"\bjsmin.php$",
- "OggHandler/PEAR/",
+ "PEAR/File_Ogg/",
"QPoll/Excel/",
"/geshi/",
"/smarty/",
if ( !$f ) {
$this->error( "Can't open file $file\n", true );
}
- while( $path = trim( fgets( $f ) ) ) {
+ while ( $path = trim( fgets( $f ) ) ) {
$this->addPath( $path );
}
fclose( $f );
preg_match_all( '/^\s*[AM].{7}(.*?)\r?$/m', $output, $matches );
foreach ( $matches[1] as $file ) {
- if ( self::isSuitableFile( $file ) && !is_dir( $file ) ) {
+ if ( $this->isSuitableFile( $file ) && !is_dir( $file ) ) {
$this->mFiles[] = $file;
}
}
// Only check files in these directories.
// Don't just put $IP, because the recursive dir thingie goes into all subdirs
- $dirs = array(
+ $dirs = array(
$IP . '/includes',
$IP . '/config',
$IP . '/languages',
$IP . '/maintenance',
$IP . '/skins',
);
- if( $this->hasOption( 'with-extensions' ) ) {
+ if ( $this->hasOption( 'with-extensions' ) ) {
$dirs[] = $IP . '/extensions';
}
- foreach( $dirs as $d ) {
+ foreach ( $dirs as $d ) {
$this->addDirectoryContent( $d );
}
* Returns true if $file is of a type we can check
*/
private function isSuitableFile( $file ) {
+ $file = str_replace( '\\', '/', $file );
$ext = pathinfo( $file, PATHINFO_EXTENSION );
if ( $ext != 'php' && $ext != 'inc' && $ext != 'php5' )
return false;
- foreach( $this->mIgnorePaths as $regex ) {
+ foreach ( $this->mIgnorePaths as $regex ) {
$m = array();
if ( preg_match( "~{$regex}~", $file, $m ) )
return false;
*/
private function addDirectoryContent( $dir ) {
$iterator = new RecursiveIteratorIterator(
- new RecursiveDirectoryIterator( $dir ),
+ new RecursiveDirectoryIterator( $dir ),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ( $iterator as $file ) {
* @return boolean
*/
private function checkFileWithCli( $file ) {
- $res = exec( 'php -l ' . wfEscapeShellArg( $file ) );
- if( strpos( $res, 'No syntax errors detected' ) === false ) {
+ $res = exec( 'php -l ' . wfEscapeShellArg( $file ) );
+ if ( strpos( $res, 'No syntax errors detected' ) === false ) {
$this->mFailures[$file] = $res;
$this->output( $res . "\n" );
return false;
* @return boolean
*/
private function checkForMistakes( $file ) {
- foreach( $this->mNoStyleCheckPaths as $regex ) {
+ foreach ( $this->mNoStyleCheckPaths as $regex ) {
$m = array();
if ( preg_match( "~{$regex}~", $file, $m ) )
return;