Index: trunk/phase3/maintenance/syntaxChecker.php |
— | — | @@ -0,0 +1,96 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Check syntax of all PHP files in MediaWiki |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along |
| 17 | + * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 19 | + * http://www.gnu.org/copyleft/gpl.html |
| 20 | + * |
| 21 | + * @ingroup Maintenance |
| 22 | + */ |
| 23 | + |
| 24 | +require_once( dirname( __FILE__ ) . '/Maintenance.php' ); |
| 25 | + |
| 26 | +class SyntaxChecker extends Maintenance { |
| 27 | + |
| 28 | + // List of files we're going to check |
| 29 | + private $mFiles = array(); |
| 30 | + |
| 31 | + public function __construct() { |
| 32 | + parent::__construct(); |
| 33 | + $this->mDescription = "Check syntax for all PHP files in MediaWiki"; |
| 34 | + $this->addOption( 'with-extensions', 'Also recurse the extensions folder' ); |
| 35 | + } |
| 36 | + |
| 37 | + public function execute() { |
| 38 | + $this->output( "Building file list..." ); |
| 39 | + $this->buildFileList(); |
| 40 | + $this->output( "done.\n" ); |
| 41 | + |
| 42 | + $this->output( "Checking syntax (this can take a really long time)...\n\n" ); |
| 43 | + $res = $this->checkSyntax(); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Build the list of files we'll check for syntax errors |
| 48 | + */ |
| 49 | + private function buildFileList() { |
| 50 | + global $IP; |
| 51 | + |
| 52 | + // Only check files in these directories. |
| 53 | + // Don't just put $IP, because the recursive dir thingie goes into all subdirs |
| 54 | + $dirs = array( |
| 55 | + $IP . '/includes', |
| 56 | + $IP . '/config', |
| 57 | + $IP . '/languages', |
| 58 | + $IP . '/maintenance', |
| 59 | + $IP . '/skins', |
| 60 | + ); |
| 61 | + if( $this->hasOption( 'with-extensions' ) ) { |
| 62 | + $dirs[] = $IP . '/extensions'; |
| 63 | + } |
| 64 | + |
| 65 | + foreach( $dirs as $d ) { |
| 66 | + $iterator = new RecursiveIteratorIterator( |
| 67 | + new RecursiveDirectoryIterator( $d ), |
| 68 | + RecursiveIteratorIterator::SELF_FIRST |
| 69 | + ); |
| 70 | + foreach ( $iterator as $file ) { |
| 71 | + $ext = pathinfo( $file->getFilename(), PATHINFO_EXTENSION ); |
| 72 | + if ( $ext == 'php' || $ext == 'inc' || $ext == 'php5' ) { |
| 73 | + $this->mFiles[] = $file->getRealPath(); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + /** |
| 80 | + * Check the files for syntax errors |
| 81 | + */ |
| 82 | + private function checkSyntax() { |
| 83 | + $count = $bad = 0; |
| 84 | + foreach( $this->mFiles as $f ) { |
| 85 | + $count++; |
| 86 | + $res = exec( 'php -l ' . $f ); |
| 87 | + if( strpos( $res, 'No syntax errors detected' ) === false ) { |
| 88 | + $bad++; |
| 89 | + $this->error( $res . "\n" ); |
| 90 | + } |
| 91 | + } |
| 92 | + $this->output( "$count files checked, $bad failures\n" ); |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +$maintClass = "SyntaxChecker"; |
| 97 | +require_once( DO_MAINTENANCE ); |
Property changes on: trunk/phase3/maintenance/syntaxChecker.php |
___________________________________________________________________ |
Name: svn:eol-style |
1 | 98 | + native |