Fix syntax error from r55287
[lhc/web/wiklou.git] / maintenance / FiveUpgrade.inc
index 8b7e613..be0112e 100644 (file)
@@ -1,4 +1,8 @@
 <?php
+/**
+ * @file
+ * @ingroup Maintenance
+ */
 
 require_once( 'cleanupDupes.inc' );
 require_once( 'userDupes.inc' );
@@ -9,12 +13,16 @@ define( 'MW_UPGRADE_ENCODE',   true  );
 define( 'MW_UPGRADE_NULL',     null  );
 define( 'MW_UPGRADE_CALLBACK', null  ); // for self-documentation only
 
+/**
+ * @ingroup Maintenance
+ */
 class FiveUpgrade {
        function FiveUpgrade() {
                $this->conversionTables = $this->prepareWindows1252();
 
-               $this->dbw =& $this->newConnection();
-               $this->dbr =& $this->streamConnection();
+               $this->loadBalancers = array();
+               $this->dbw = wfGetDB( DB_MASTER );
+               $this->dbr = $this->streamConnection();
 
                $this->cleanupSwaps = array();
                $this->emailAuth = false; # don't preauthenticate emails
@@ -60,12 +68,23 @@ class FiveUpgrade {
         * @return Database
         * @access private
         */
-       function &newConnection() {
-               global $wgDBadminuser, $wgDBadminpassword;
-               global $wgDBserver, $wgDBname;
-               $db = new Database( $wgDBserver, $wgDBadminuser, $wgDBadminpassword, $wgDBname );
+       function newConnection() {
+               $lb = wfGetLBFactory()->newMainLB();
+               $db = $lb->getConnection( DB_MASTER );
+               
+               $this->loadBalancers[] = $lb;
                return $db;
        }
+       
+       /**
+        * Commit transactions and close the connections when we're done...
+        */
+       function close() {
+               foreach( $this->loadBalancers as $lb ) {
+                       $lb->commitMasterChanges();
+                       $lb->closeAll();
+               }
+       }
 
        /**
         * Open a second connection to the master server, with buffering off.
@@ -74,12 +93,16 @@ class FiveUpgrade {
         * @return Database
         * @access private
         */
-       function &streamConnection() {
+       function streamConnection() {
+               global $wgDBtype;
+
                $timeout = 3600 * 24;
-               $db =& $this->newConnection();
+               $db = $this->newConnection();
                $db->bufferResults( false );
-               $db->query( "SET net_read_timeout=$timeout" );
-               $db->query( "SET net_write_timeout=$timeout" );
+               if ($wgDBtype == 'mysql') {
+                       $db->query( "SET net_read_timeout=$timeout" );
+                       $db->query( "SET net_write_timeout=$timeout" );
+               }
                return $db;
        }
 
@@ -501,8 +524,9 @@ class FiveUpgrade {
                if( $this->dbw->fieldExists( 'interwiki', 'iw_trans' ) ) {
                        $this->log( 'interwiki has iw_trans.' );
                } else {
+                       global $IP;
                        $this->log( 'adding iw_trans...' );
-                       dbsource( 'maintenance/archives/patch-interwiki-trans.sql', $this->dbw );
+                       $this->dbw->sourceFile( $IP . '/maintenance/archives/patch-interwiki-trans.sql' );
                        $this->log( 'added iw_trans.' );
                }
 
@@ -692,10 +716,7 @@ END;
                return $copy;
        }
 
-       function imageInfo( $name, $subdirCallback='wfImageDir', $basename = null ) {
-               if( is_null( $basename ) ) $basename = $name;
-               $dir = call_user_func( $subdirCallback, $basename );
-               $filename = $dir . '/' . $name;
+       function imageInfo( $filename ) {
                $info = array(
                        'width'  => 0,
                        'height' => 0,
@@ -704,26 +725,19 @@ END;
                        'major'  => '',
                        'minor'  => '' );
 
-               $magic =& wfGetMimeMagic();
+               $magic = MimeMagic::singleton();
                $mime = $magic->guessMimeType( $filename, true );
                list( $info['major'], $info['minor'] ) = explode( '/', $mime );
 
                $info['media'] = $magic->getMediaType( $filename, $mime );
 
-               # Height and width
-               $gis = false;
-               if( $mime == 'image/svg' ) {
-                       $gis = wfGetSVGsize( $filename );
-               } elseif( $magic->isPHPImageType( $mime ) ) {
-                       $gis = getimagesize( $filename );
-               } else {
-                       $this->log( "Surprising mime type: $mime" );
-               }
-               if( $gis ) {
-                       $info['width' ] = $gis[0];
-                       $info['height'] = $gis[1];
-               }
-               if( isset( $gis['bits'] ) ) {
+               $image = UnregisteredLocalFile::newFromPath( $filename, $mime );
+
+               $info['width'] = $image->getWidth();
+               $info['height'] = $image->getHeight();
+
+               $gis = $image->getImageSize();
+               if ( isset( $gis['bits'] ) ) {
                        $info['bits'] = $gis['bits'];
                }
 
@@ -738,7 +752,7 @@ END;
        function clearTable( $table ) {
                print "Clearing $table...\n";
                $tableName = $this->db->tableName( $table );
-               $this->db->query( 'TRUNCATE $tableName' );
+               $this->db->query( "TRUNCATE $tableName" );
        }
 
        /**
@@ -874,17 +888,17 @@ END;
                $add = array();
                while( $row = $this->dbr->fetchObject( $result ) ) {
                        $add[] = array(
-                               'wl_user'      =>                        $row->wl_user,
-                               'wl_namespace' => Namespace::getSubject( $row->wl_namespace ),
-                               'wl_title'     =>           $this->conv( $row->wl_title ),
-                               'wl_notificationtimestamp' =>            '0' );
+                               'wl_user'      =>                          $row->wl_user,
+                               'wl_namespace' => MWNamespace::getSubject( $row->wl_namespace ),
+                               'wl_title'     =>             $this->conv( $row->wl_title ),
+                               'wl_notificationtimestamp' =>              '0' );
                        $this->addChunk( $add );
 
                        $add[] = array(
-                               'wl_user'      =>                        $row->wl_user,
-                               'wl_namespace' =>    Namespace::getTalk( $row->wl_namespace ),
-                               'wl_title'     =>           $this->conv( $row->wl_title ),
-                               'wl_notificationtimestamp' =>            '0' );
+                               'wl_user'      =>                          $row->wl_user,
+                               'wl_namespace' =>    MWNamespace::getTalk( $row->wl_namespace ),
+                               'wl_title'     =>             $this->conv( $row->wl_title ),
+                               'wl_notificationtimestamp' =>              '0' );
                        $this->addChunk( $add );
                }
                $this->lastChunk( $add );
@@ -895,7 +909,7 @@ END;
        }
 
        function upgradeLogging() {
-               $tabledef = <<<END
+               $tabledef = <<<ENDS
 CREATE TABLE $1 (
   -- Symbolic keys for the general log type and the action type
   -- within the log. The output format will be controlled by the
@@ -925,7 +939,7 @@ CREATE TABLE $1 (
   KEY page_time (log_namespace, log_title, log_timestamp)
 
 ) TYPE=InnoDB
-END;
+ENDS;
                $fields = array(
                        'log_type'      => MW_UPGRADE_COPY,
                        'log_action'    => MW_UPGRADE_COPY,
@@ -939,7 +953,7 @@ END;
        }
 
        function upgradeArchive() {
-               $tabledef = <<<END
+               $tabledef = <<<ENDS
 CREATE TABLE $1 (
   ar_namespace int NOT NULL default '0',
   ar_title varchar(255) binary NOT NULL default '',
@@ -959,7 +973,7 @@ CREATE TABLE $1 (
   KEY name_title_timestamp (ar_namespace,ar_title,ar_timestamp)
 
 ) TYPE=InnoDB
-END;
+ENDS;
                $fields = array(
                        'ar_namespace'  => MW_UPGRADE_COPY,
                        'ar_title'      => MW_UPGRADE_ENCODE,
@@ -978,21 +992,21 @@ END;
        function upgradeImagelinks() {
                global $wgUseLatin1;
                if( $wgUseLatin1 ) {
-                       $tabledef = <<<END
+                       $tabledef = <<<ENDS
 CREATE TABLE $1 (
   -- Key to page_id of the page containing the image / media link.
   il_from int(8) unsigned NOT NULL default '0',
 
   -- Filename of target image.
   -- This is also the page_title of the file's description page;
-  -- all such pages are in namespace 6 (NS_IMAGE).
+  -- all such pages are in namespace 6 (NS_FILE).
   il_to varchar(255) binary NOT NULL default '',
 
   UNIQUE KEY il_from(il_from,il_to),
   KEY (il_to)
 
 ) TYPE=InnoDB
-END;
+ENDS;
                        $fields = array(
                                'il_from' => MW_UPGRADE_COPY,
                                'il_to'   => MW_UPGRADE_ENCODE );
@@ -1003,7 +1017,7 @@ END;
        function upgradeCategorylinks() {
                global $wgUseLatin1;
                if( $wgUseLatin1 ) {
-                       $tabledef = <<<END
+                       $tabledef = <<<ENDS
 CREATE TABLE $1 (
   cl_from int(8) unsigned NOT NULL default '0',
   cl_to varchar(255) binary NOT NULL default '',
@@ -1014,7 +1028,7 @@ CREATE TABLE $1 (
   KEY cl_sortkey(cl_to,cl_sortkey),
   KEY cl_timestamp(cl_to,cl_timestamp)
 ) TYPE=InnoDB
-END;
+ENDS;
                        $fields = array(
                                'cl_from'      => MW_UPGRADE_COPY,
                                'cl_to'        => MW_UPGRADE_ENCODE,
@@ -1027,7 +1041,7 @@ END;
        function upgradeIpblocks() {
                global $wgUseLatin1;
                if( $wgUseLatin1 ) {
-                       $tabledef = <<<END
+                       $tabledef = <<<ENDS
 CREATE TABLE $1 (
   ipb_id int(8) NOT NULL auto_increment,
   ipb_address varchar(40) binary NOT NULL default '',
@@ -1043,7 +1057,7 @@ CREATE TABLE $1 (
   INDEX ipb_user (ipb_user)
 
 ) TYPE=InnoDB
-END;
+ENDS;
                        $fields = array(
                                'ipb_id'        => MW_UPGRADE_COPY,
                                'ipb_address'   => MW_UPGRADE_COPY,
@@ -1059,7 +1073,7 @@ END;
 
        function upgradeRecentchanges() {
                // There's a format change in the namespace field
-               $tabledef = <<<END
+               $tabledef = <<<ENDS
 CREATE TABLE $1 (
   rc_id int(8) NOT NULL auto_increment,
   rc_timestamp varchar(14) binary NOT NULL default '',
@@ -1097,7 +1111,7 @@ CREATE TABLE $1 (
   INDEX rc_ip (rc_ip)
 
 ) TYPE=InnoDB
-END;
+ENDS;
                $fields = array(
                        'rc_id'             => MW_UPGRADE_COPY,
                        'rc_timestamp'      => MW_UPGRADE_COPY,
@@ -1123,7 +1137,7 @@ END;
 
        function upgradeQuerycache() {
                // There's a format change in the namespace field
-               $tabledef = <<<END
+               $tabledef = <<<ENDS
 CREATE TABLE $1 (
   -- A key name, generally the base name of of the special page.
   qc_type char(32) NOT NULL,
@@ -1138,7 +1152,7 @@ CREATE TABLE $1 (
   KEY (qc_type,qc_value)
 
 ) TYPE=InnoDB
-END;
+ENDS;
                $fields = array(
                        'qc_type'      => MW_UPGRADE_COPY,
                        'qc_value'     => MW_UPGRADE_COPY,
@@ -1174,5 +1188,3 @@ END;
        }
 
 }
-
-?>