Documentation
[lhc/web/wiklou.git] / maintenance / importDump.php
index 2390ba5..2ad0872 100644 (file)
@@ -57,7 +57,7 @@ TEXT;
                $this->stderr = fopen( "php://stderr", "wt" );
                $this->addOption( 'report',
                        'Report position and speed after every n pages processed', false, true );
-               $this->addOption( 'namespaces', 
+               $this->addOption( 'namespaces',
                        'Import only the pages from namespaces belonging to the list of ' .
                        'pipe-separated namespace names or namespace indexes', false, true );
                $this->addOption( 'dry-run', 'Parse dump without actually importing pages' );
@@ -74,6 +74,10 @@ TEXT;
                }
 
                $this->reportingInterval = intval( $this->getOption( 'report', 100 ) );
+               if ( !$this->reportingInterval ) {
+                       $this->reportingInterval = 100; // avoid division by zero
+               }
+
                $this->dryRun = $this->hasOption( 'dry-run' );
                $this->uploads = $this->hasOption( 'uploads' ); // experimental!
                if ( $this->hasOption( 'image-base-path' ) ) {
@@ -113,6 +117,10 @@ TEXT;
                $this->error( "Unknown namespace text / index specified: $namespace", true );
        }
 
+       /**
+        * @param $obj Title|Revision
+        * @return bool
+        */
        private function skippedNamespace( $obj ) {
                if ( $obj instanceof Title ) {
                        $ns = $obj->getNamespace();
@@ -131,6 +139,10 @@ TEXT;
                $this->pageCount++;
        }
 
+       /**
+        * @param $rev Revision
+        * @return mixed
+        */
        function handleRevision( $rev ) {
                $title = $rev->getTitle();
                if ( !$title ) {
@@ -150,6 +162,10 @@ TEXT;
                }
        }
 
+       /**
+        * @param $revision Revision
+        * @return bool
+        */
        function handleUpload( $revision ) {
                if ( $this->uploads ) {
                        if ( $this->skippedNamespace( $revision ) ) {
@@ -187,7 +203,7 @@ TEXT;
        }
 
        function showReport() {
-               if ( $this->mQuiet ) {
+               if ( !$this->mQuiet ) {
                        $delta = wfTime() - $this->startTime;
                        if ( $delta ) {
                                $rate = sprintf( "%.2f", $this->pageCount / $delta );
@@ -205,7 +221,7 @@ TEXT;
                }
                wfWaitForSlaves();
                // XXX: Don't let deferred jobs array get absurdly large (bug 24375)
-               wfDoUpdates( 'commit' );
+               DeferredUpdates::doUpdates( 'commit' );
        }
 
        function progress( $string ) {
@@ -215,11 +231,9 @@ TEXT;
        function importFromFile( $filename ) {
                if ( preg_match( '/\.gz$/', $filename ) ) {
                        $filename = 'compress.zlib://' . $filename;
-               }
-               elseif ( preg_match( '/\.bz2$/', $filename ) ) {
+               } elseif ( preg_match( '/\.bz2$/', $filename ) ) {
                        $filename = 'compress.bzip2://' . $filename;
-               }
-               elseif ( preg_match( '/\.7z$/', $filename ) ) {
+               } elseif ( preg_match( '/\.7z$/', $filename ) ) {
                        $filename = 'mediawiki.compress.7z://' . $filename;
                }
 
@@ -229,7 +243,7 @@ TEXT;
 
        function importFromStdin() {
                $file = fopen( 'php://stdin', 'rt' );
-               if( posix_isatty( $file ) ) {
+               if( self::posix_isatty( $file ) ) {
                        $this->maybeHelp( true );
                }
                return $this->importFromHandle( $file );