Merge "mw.language.convertPlural: Check if matching form exists"
[lhc/web/wiklou.git] / maintenance / backupTextPass.inc
index 547abab..f16772c 100644 (file)
@@ -24,7 +24,7 @@
  * @ingroup Maintenance
  */
 
-require_once( __DIR__ . '/backup.inc' );
+require_once __DIR__ . '/backup.inc';
 
 /**
  * @ingroup Maintenance
@@ -82,7 +82,6 @@ class TextPassDumper extends BackupDumper {
         */
        protected $db;
 
-
        /**
         * Drop the database connection $this->db and try to get a new one.
         *
@@ -123,16 +122,14 @@ class TextPassDumper extends BackupDumper {
                        throw new MWException( __METHOD__ . " rotating DB failed to obtain new load balancer (" . $e->getMessage() . ")" );
                }
 
-
                // 2. The Connection, through the load balancer.
                try {
-                       $this->db = $this->lb->getConnection( DB_SLAVE, 'backup' );
+                       $this->db = $this->lb->getConnection( DB_SLAVE, 'dump' );
                } catch ( Exception $e ) {
                        throw new MWException( __METHOD__ . " rotating DB failed to obtain new database (" . $e->getMessage() . ")" );
                }
        }
 
-
        function initProgress( $history = WikiExporter::FULL ) {
                parent::initProgress();
                $this->timeOfCheckpoint = $this->startTime;
@@ -414,12 +411,14 @@ class TextPassDumper extends BackupDumper {
         * @throws MWException
         */
        function getText( $id ) {
+               global $wgContentHandlerUseDB;
+
                $prefetchNotTried = true; // Whether or not we already tried to get the text via prefetch.
                $text = false; // The candidate for a good text. false if no proper value.
                $failures = 0; // The number of times, this invocation of getText already failed.
 
-               static $consecutiveFailedTextRetrievals = 0; // The number of times getText failed without
-                                                            // yielding a good text in between.
+               // The number of times getText failed without yielding a good text in between.
+               static $consecutiveFailedTextRetrievals = 0;
 
                $this->fetchCount++;
 
@@ -479,7 +478,28 @@ class TextPassDumper extends BackupDumper {
                                if ( ! isset( $this->db ) ) {
                                        throw new MWException( "No database available" );
                                }
-                               $revLength = $this->db->selectField( 'revision', 'rev_len', array( 'rev_id' => $revID ) );
+
+                               $revLength = strlen( $text );
+                               if ( $wgContentHandlerUseDB ) {
+                                       $row = $this->db->selectRow(
+                                               'revision',
+                                               array( 'rev_len', 'rev_content_model' ),
+                                               array( 'rev_id' => $revID ),
+                                               __METHOD__
+                                       );
+                                       if ( $row ) {
+                                               // only check the length for the wikitext content handler,
+                                               // it's a wasted (and failed) check otherwise
+                                               if ( $row->rev_content_model == CONTENT_MODEL_WIKITEXT ) {
+                                                       $revLength = $row->rev_len;
+                                               }
+                                       }
+
+                               }
+                               else {
+                                       $revLength = $this->db->selectField( 'revision', 'rev_len', array( 'rev_id' => $revID ) );
+                               }
+
                                if ( strlen( $text ) == $revLength ) {
                                        if ( $tryIsPrefetch ) {
                                                $this->prefetchCount++;
@@ -533,7 +553,6 @@ class TextPassDumper extends BackupDumper {
                return "";
        }
 
-
        /**
         * May throw a database error if, say, the server dies during query.
         * @param $id