The war on redundant ampersand usage!
[lhc/web/wiklou.git] / maintenance / dumpHTML.inc
index 86f675c..ca2a7df 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 /**
- * @package MediaWiki
- * @subpackage Maintenance
+ * @addtogroup Maintenance
  */
 
 define( 'REPORTING_INTERVAL', 10 );
@@ -70,6 +69,9 @@ class DumpHTML {
        # Max page ID, lazy initialised
        var $maxPageID = false;
 
+       # UDP profiling
+       var $udpProfile, $udpProfileCounter = 0, $udpProfileInit = false;
+
        function DumpHTML( $settings = array() ) {
                foreach ( $settings as $var => $value ) {
                        $this->$var = $value;
@@ -241,10 +243,9 @@ class DumpHTML {
         * have a local image
         */
        function doLocalImageDescriptions() {
-               global $wgSharedUploadDirectory;
                $chunkSize = 1000;
 
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                
                $cp = $this->getCheckpoint( 'local image' );
                if ( $cp == 'done' ) {
@@ -344,7 +345,7 @@ class DumpHTML {
                $chunkSize = 1000;
                
                $this->setupGlobals();
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                
                $cp = $this->getCheckpoint( 'category' );
                if ( $cp == 'done' ) {
@@ -407,7 +408,7 @@ class DumpHTML {
                }
 
                $this->setupGlobals();
-               $dbr =& wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_SLAVE );
                $i = 0;
 
                for ( $chunkStart = $start; $chunkStart <= $end; $chunkStart += $chunkSize ) {
@@ -440,9 +441,6 @@ class DumpHTML {
 
        /** Write an article specified by title */
        function doArticle( $title ) {
-               global $wgTitle, $wgSharedUploadPath, $wgSharedUploadDirectory;
-               global $wgUploadDirectory;
-
                if ( $this->noOverwrite ) {
                        $fileName = $this->dest.'/'.$this->getHashedFilename( $title );
                        if ( file_exists( $fileName ) ) {
@@ -450,6 +448,8 @@ class DumpHTML {
                        }
                }
 
+               $this->profile();
+
                $this->rawPages = array();
                $text = $this->getArticleHTML( $title );
 
@@ -479,7 +479,7 @@ class DumpHTML {
                                print "Writing $file\n";
                                $file = fopen( $path, 'w' );
                                if ( !$file ) {
-                                       print("Can't open file $fullName for writing\n");
+                                       print("Can't open file $path for writing\n");
                                        continue;
                                }
                                fwrite( $file, $text );
@@ -491,7 +491,7 @@ class DumpHTML {
        }
 
        /** Write the given text to the file identified by the given title object */
-       function writeArticle( &$title, $text ) {
+       function writeArticle( $title, $text ) {
                $filename = $this->getHashedFilename( $title );
 
                # Temporary hack for current dump, this should be moved to 
@@ -531,7 +531,7 @@ class DumpHTML {
 
        /** Set up globals required for parsing */
        function setupGlobals( $currentDepth = NULL ) {
-               global $wgUser, $wgTitle, $wgStylePath, $wgArticlePath, $wgMathPath;
+               global $wgUser, $wgStylePath, $wgArticlePath, $wgMathPath;
                global $wgUploadPath, $wgLogo, $wgMaxCredits, $wgSharedUploadPath;
                global $wgHideInterlanguageLinks, $wgUploadDirectory, $wgThumbnailScriptPath;
                global $wgSharedThumbnailScriptPath, $wgEnableParserCache, $wgHooks, $wgServer;
@@ -618,7 +618,7 @@ class DumpHTML {
        }
 
        /** Reads the content of a title object, executes the skin and captures the result */
-       function getArticleHTML( &$title ) {
+       function getArticleHTML( $title ) {
                global $wgOut, $wgTitle, $wgArticle, $wgUser;
 
                $linkCache =& LinkCache::singleton();
@@ -795,6 +795,7 @@ ENDTEXT;
 
                $url = false;
                if ( $query != '' ) {
+                       $params = array();
                        parse_str( $query, $params );
                        if ( isset($params['action']) && $params['action'] == 'raw' ) {
                                if ( $params['gen'] == 'css' || $params['gen'] == 'js' ) {
@@ -802,6 +803,7 @@ ENDTEXT;
                                } else {
                                        $file = $this->getFriendlyName( $title->getPrefixedDBkey() );
                                        // Clean up Monobook.css etc.
+                                       $matches = array();
                                        if ( preg_match( '/^(.*)\.(css|js)_[0-9a-f]{4}$/', $file, $matches ) ) {
                                                $file = $matches[1] . '.' . $matches[2];
                                        }
@@ -877,6 +879,7 @@ ENDTEXT;
                }
 
                # Split into characters
+               $m = array();
                preg_match_all( '/./us', $dbk, $m );
 
                $chars = $m[0];
@@ -953,12 +956,38 @@ ENDTEXT;
 
        function getMaxPageID() {
                if ( $this->maxPageID === false ) {
-                       $dbr =& wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_SLAVE );
                        $this->maxPageID = $dbr->selectField( 'page', 'max(page_id)', false, __METHOD__ );
                }
                return $this->maxPageID;
        }
-                       
+
+       function profile() {
+               global $wgProfiler;
+
+               if ( !$this->udpProfile ) {
+                       return;
+               }
+               if ( !$this->udpProfileInit ) {
+                       $this->udpProfileInit = true;
+               } elseif ( $this->udpProfileCounter == 1 % $this->udpProfile ) {
+                       $wgProfiler->getFunctionReport();
+                       $wgProfiler = new DumpHTML_ProfilerStub;
+               }
+               if ( $this->udpProfileCounter == 0 ) {
+                       $wgProfiler = new ProfilerSimpleUDP;
+                       $wgProfiler->setProfileID( 'dumpHTML' );
+               }
+               $this->udpProfileCounter = ( $this->udpProfileCounter + 1 ) % $this->udpProfile;
+       }
+}
+
+class DumpHTML_ProfilerStub {
+       function profileIn() {}
+       function profileOut() {}
+       function getOutput() {}
+       function close() {}
+       function getFunctionReport() {}
 }
 
 /** XML parser callback */