Fix NS_PROJECT_TALK (bug #7792)
[lhc/web/wiklou.git] / maintenance / importImages.php
index 925c64b..abf0ec0 100644 (file)
@@ -26,13 +26,27 @@ if( count( $args ) > 1 ) {
        $files = findFiles( $dir, $exts );
 
        # Set up a fake user for this operation
-       $wgUser = User::newFromName( 'Image import script' );
-       $wgUser->setLoaded( true );
+       if( isset( $options['user'] ) ) {
+               $wgUser = User::newFromName( $options['user'] );
+       } else {
+               $wgUser = User::newFromName( 'Image import script' );
+       }
+       if ( $wgUser->isAnon() ) {
+               $wgUser->addToDatabase();
+       }
+       
+       # Get the upload comment
+       $comment = isset( $options['comment'] )
+               ? $options['comment']
+               : 'Importing image file';
+       
+       # Get the license specifier
+       $license = isset( $options['license'] ) ? $options['license'] : '';
        
        # Batch "upload" operation
        foreach( $files as $file ) {
        
-               $base = basename( $file );
+               $base = wfBaseName( $file );
                
                # Validate a title
                $title = Title::makeTitleSafe( NS_IMAGE, $base );
@@ -59,7 +73,7 @@ if( count( $args ) > 1 ) {
                                        $image->loadFromFile();
                                        
                                        # Record the upload
-                                       if( $image->recordUpload( '', 'Importing image file' ) ) {
+                                       if( $image->recordUpload( '', $comment, $license ) ) {
                                        
                                                # We're done!
                                                echo( "done.\n" );
@@ -92,10 +106,19 @@ exit();
 function showUsage( $reason = false ) {
        if( $reason )
                echo( $reason . "\n" );
-       echo( "USAGE: php importImages.php <dir> <ext1> <ext2>\n\n" );
-       echo( "<dir> : Path to the directory containing images to be imported\n" );
-       echo( "<ext1+> File extensions to import\n\n" );                
+       echo <<<END
+USAGE: php importImages.php [options] <dir> <ext1> ...
+
+<dir> : Path to the directory containing images to be imported
+<ext1+> File extensions to import
+
+Options:
+--user=<username> Set username of uploader, default 'Image import script'
+--comment=<text>  Set upload summary comment, default 'Importing image file'
+--license=<code>  Use an optional license template
+
+END;
        exit();
 }
 
-?>
\ No newline at end of file
+?>