r89329 followup: roa-rup -> rup in addwiki.php's initial main page text.
[lhc/web/wiklou.git] / maintenance / checkSyntax.php
index 02b5a69..ad52a18 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
+ * @file
  * @ingroup Maintenance
  */
+
 require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
 class CheckSyntax extends Maintenance {
@@ -77,11 +78,11 @@ class CheckSyntax extends Maintenance {
                        // Compat stuff, explodes on PHP 5.3
                        "includes/NamespaceCompat.php$",
                        );
-       
+
                $this->mNoStyleCheckPaths = array(
                        // Third-party code we don't care about
                        "/activemq_stomp/",
-                       "EmailPage/phpMailer",
+                       "EmailPage/PHPMailer",
                        "FCKeditor/fckeditor/",
                        '\bphplot-',
                        "/svggraph/",
@@ -104,7 +105,8 @@ class CheckSyntax extends Maintenance {
                        if ( !$f ) {
                                $this->error( "Can't open file $file\n", true );
                        }
-                       while ( $path = trim( fgets( $f ) ) ) {
+                       $path = trim( fgets( $f ) );
+                       while ( $path ) {
                                $this->addPath( $path );
                        }
                        fclose( $f );
@@ -112,6 +114,7 @@ class CheckSyntax extends Maintenance {
                } elseif ( $this->hasOption( 'modified' ) ) {
                        $this->output( "Retrieving list from Subversion... " );
                        $parentDir = wfEscapeShellArg( dirname( __FILE__ ) . '/..' );
+                       $retval = null;
                        $output = wfShellExec( "svn status --ignore-externals $parentDir", $retval );
                        if ( $retval ) {
                                $this->error( "Error retrieving list from Subversion!\n", true );
@@ -130,11 +133,11 @@ class CheckSyntax extends Maintenance {
 
                $this->output( 'Building file list...', 'listfiles' );
 
-               // Only check files in these directories. 
+               // 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 . '/mw-config',
                        $IP . '/languages',
                        $IP . '/maintenance',
                        $IP . '/skins',
@@ -157,7 +160,7 @@ class CheckSyntax extends Maintenance {
 
                $this->output( 'done.', 'listfiles' );
        }
-       
+
        /**
         * Returns true if $file is of a type we can check
         */
@@ -272,7 +275,9 @@ class CheckSyntax extends Maintenance {
                }
 
                $text = file_get_contents( $file );
+               $tokens = token_get_all( $text );
 
+               $this->checkEvilToken( $file, $tokens, '@', 'Error supression operator (@)');
                $this->checkRegex( $file, $text, '/^[\s\r\n]+<\?/', 'leading whitespace' );
                $this->checkRegex( $file, $text, '/\?>[\s\r\n]*$/', 'trailing ?>' );
                $this->checkRegex( $file, $text, '/^[\xFF\xFE\xEF]/', 'byte-order mark' );
@@ -289,8 +294,20 @@ class CheckSyntax extends Maintenance {
                $this->mWarnings[$file][] = $desc;
                $this->output( "Warning in file $file: $desc found.\n" );
        }
+
+       private function checkEvilToken( $file, $tokens, $evilToken, $desc ) {
+               if ( !in_array( $evilToken, $tokens ) ) {
+                       return;
+               }
+
+               if ( !isset( $this->mWarnings[$file] ) ) {
+                       $this->mWarnings[$file] = array();
+               }
+               $this->mWarnings[$file][] = $desc;
+               $this->output( "Warning in file $file: $desc found.\n" );
+       }
 }
 
 $maintClass = "CheckSyntax";
-require_once( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );