mDescription = "Check syntax for all PHP files in MediaWiki"; $this->addOption( 'with-extensions', 'Also recurse the extensions folder' ); } protected function getDbType() { return Maintenance::DB_NONE; } public function execute() { $this->output( "Building file list..." ); $this->buildFileList(); $this->output( "done.\n" ); $this->output( "Checking syntax (this can take a really long time)...\n\n" ); $res = $this->checkSyntax(); } /** * Build the list of files we'll check for syntax errors */ private function buildFileList() { global $IP; // Only check files in these directories. // Don't just put $IP, because the recursive dir thingie goes into all subdirs $dirs = array( $IP . '/includes', $IP . '/config', $IP . '/languages', $IP . '/maintenance', $IP . '/skins', ); if( $this->hasOption( 'with-extensions' ) ) { $dirs[] = $IP . '/extensions'; } foreach( $dirs as $d ) { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator( $d ), RecursiveIteratorIterator::SELF_FIRST ); foreach ( $iterator as $file ) { $ext = pathinfo( $file->getFilename(), PATHINFO_EXTENSION ); if ( $ext == 'php' || $ext == 'inc' || $ext == 'php5' ) { $this->mFiles[] = $file->getRealPath(); } } } } /** * Check the files for syntax errors * @return boolean */ private function checkSyntax() { foreach( $this->mFiles as $f ) { $res = exec( 'php -l ' . $f ); if( strpos( $res, 'No syntax errors detected' ) === false ) { $this->mFailures[] = $f; $this->error( $res . "\n" ); } } $this->output( count($this->mFiles) . " files checked, " . count($this->mFailures) . " failures\n" ); } } $maintClass = "SyntaxChecker"; require_once( DO_MAINTENANCE );