r72922 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72921‎ | r72922 | r72923 >
Date:19:07, 13 September 2010
Author:daniel
Status:deferred
Tags:
Comment:
recursive directory scan
Modified paths:
  • /trunk/extensions/DataTransclusion/ImportMAB2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DataTransclusion/ImportMAB2.php
@@ -25,6 +25,7 @@
2626 $this->addOption( "create", "create database tables if they do not exist", false, false );
2727 $this->addOption( "truncate", "truncate (empty) database tables", false, false );
2828 $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 );
 29+ $this->addOption( "recursive", "recurse into subdirectories while importing MAB files", false, false );
2930 $this->addOption( "noblob", "don't write blob data, import index fields only", false, false );
3031 $this->addOption( "limit", "max number of files to process", false, true );
3132 $this->addOption( "debug", "don't write to the database, dump to console instead", false, false );
@@ -68,6 +69,7 @@
6970
7071 $this->debug = $this->hasOption( 'debug' );
7172 $this->noblob = $this->hasOption( 'noblob' );
 73+ $recursive = $this->hasOption( 'recursive' );
7274 $limit = (int)$this->getOption( 'limit' );
7375
7476 $src = $this->mArgs[0];
@@ -109,9 +111,14 @@
110112 }
111113 }
112114
 115+ $this->importDir( $dir, $recursive, $limit );
 116+ }
 117+
 118+ public function importDir( $dir, $recursive = false, $limit = 0 ) {
113119 $dir = "$dir/";
114120
115121 $this->output( "scanning directory $dir\n" );
 122+
116123 $d = opendir( $dir );
117124 if ( !$d ) {
118125 $this->error( "unable to open directory $dir!\n" );
@@ -123,6 +130,14 @@
124131 continue;
125132 }
126133
 134+ if ( is_dir( $dir . $file ) && $recursive ) {
 135+ $this->importDir( $dir . $file );
 136+ continue;
 137+ } else if ( !is_file( $dir . $file ) ) {
 138+ $this->output( "not a file: $dir/$file\n" );
 139+ continue;
 140+ }
 141+
127142 $rec = $this->readMabFile( $dir . $file );
128143
129144 if ( !$rec ) {

Status & tagging log