http://www.mediawiki.org/wiki/Special:Code/MediaWiki/72922

Revision: 72922
Author:   daniel
Date:     2010-09-13 19:07:32 +0000 (Mon, 13 Sep 2010)

Log Message:
-----------
recursive directory scan

Modified Paths:
--------------
    trunk/extensions/DataTransclusion/ImportMAB2.php

Modified: trunk/extensions/DataTransclusion/ImportMAB2.php
===================================================================
--- trunk/extensions/DataTransclusion/ImportMAB2.php    2010-09-13 18:45:43 UTC 
(rev 72921)
+++ trunk/extensions/DataTransclusion/ImportMAB2.php    2010-09-13 19:07:32 UTC 
(rev 72922)
@@ -25,6 +25,7 @@
                $this->addOption( "create", "create database tables if they do 
not exist", false, false );
                $this->addOption( "truncate", "truncate (empty) database 
tables", false, false );
                $this->addOption( "prefix", "database table prefix. May contain 
a period (\".\") to reference tables in another database. If not given, the 
wiki's table prefix will be used", false, true );
+               $this->addOption( "recursive", "recurse into subdirectories 
while importing MAB files", false, false );
                $this->addOption( "noblob", "don't write blob data, import 
index fields only", false, false );
                $this->addOption( "limit", "max number of files to process", 
false, true );
                $this->addOption( "debug", "don't write to the database, dump 
to console instead", false, false );
@@ -68,6 +69,7 @@
 
                $this->debug = $this->hasOption( 'debug' );
                $this->noblob = $this->hasOption( 'noblob' );
+               $recursive = $this->hasOption( 'recursive' );
                $limit = (int)$this->getOption( 'limit' );
 
                $src = $this->mArgs[0];
@@ -109,9 +111,14 @@
                        }
                }
 
+               $this->importDir( $dir, $recursive, $limit );
+       }
+
+       public function importDir( $dir, $recursive = false, $limit = 0 ) {
                $dir = "$dir/";
 
                $this->output( "scanning directory $dir\n" );
+
                $d = opendir( $dir );
                if ( !$d ) {
                        $this->error( "unable to open directory $dir!\n" );
@@ -123,6 +130,14 @@
                                continue;
                        }
 
+                       if ( is_dir( $dir . $file ) && $recursive ) {
+                               $this->importDir( $dir . $file );
+                               continue;
+                       } else if ( !is_file( $dir . $file ) ) {
+                               $this->output( "not a file: $dir/$file\n" );
+                               continue;
+                       }
+
                        $rec = $this->readMabFile( $dir . $file );
 
                        if ( !$rec ) {



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to