- $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();
- }
+ $this->addDirectoryContent( $d );
+ }
+
+ // Manually add two user-editable files that are usually sources of problems
+ if ( file_exists( "$IP/LocalSettings.php" ) ) {
+ $this->mFiles[] = "$IP/LocalSettings.php";
+ }
+ if ( file_exists( "$IP/AdminSettings.php" ) ) {
+ $this->mFiles[] = "$IP/AdminSettings.php";
+ }
+
+ $this->output( 'done.', 'listfiles' );
+ }
+
+ /**
+ * Returns true if $file is of a type we can check
+ */
+ private function isSuitableFile( $file ) {
+ $ext = pathinfo( $file, PATHINFO_EXTENSION );
+ if ( $ext != 'php' && $ext != 'inc' && $ext != 'php5' )
+ return false;
+ foreach( $this->mIgnorePaths as $regex ) {
+ $m = array();
+ if ( preg_match( "~{$regex}~", $file, $m ) )
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Add given path to file list, searching it in include path if needed
+ */
+ private function addPath( $path ) {
+ global $IP;
+ return $this->addFileOrDir( $path ) || $this->addFileOrDir( "$IP/$path" );
+ }
+
+ /**
+ * Add given file to file list, or, if it's a directory, add its content
+ */
+ private function addFileOrDir( $path ) {
+ if ( is_dir( $path ) ) {
+ $this->addDirectoryContent( $path );
+ } elseif ( file_exists( $path ) ) {
+ $this->mFiles[] = $path;
+ } else {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Add all suitable files in given directory or its subdirectories to the file list
+ *
+ * @param $dir String: directory to process
+ */
+ private function addDirectoryContent( $dir ) {
+ $iterator = new RecursiveIteratorIterator(
+ new RecursiveDirectoryIterator( $dir ),
+ RecursiveIteratorIterator::SELF_FIRST
+ );
+ foreach ( $iterator as $file ) {
+ if ( $this->isSuitableFile( $file->getRealPath() ) ) {
+ $this->mFiles[] = $file->getRealPath();