diff options
Diffstat (limited to 'maintenance/backupTextPass.inc')
-rw-r--r-- | maintenance/backupTextPass.inc | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/maintenance/backupTextPass.inc b/maintenance/backupTextPass.inc index f1f09546..c515c6fe 100644 --- a/maintenance/backupTextPass.inc +++ b/maintenance/backupTextPass.inc @@ -24,7 +24,7 @@ * @ingroup Maintenance */ -require_once( __DIR__ . '/backup.inc' ); +require_once __DIR__ . '/backup.inc'; /** * @ingroup Maintenance @@ -141,8 +141,9 @@ class TextPassDumper extends BackupDumper { function dump( $history, $text = WikiExporter::TEXT ) { // Notice messages will foul up your XML output even if they're // relatively harmless. - if ( ini_get( 'display_errors' ) ) + if ( ini_get( 'display_errors' ) ) { ini_set( 'display_errors', 'stderr' ); + } $this->initProgress( $this->history ); @@ -169,7 +170,7 @@ class TextPassDumper extends BackupDumper { $this->xmlwriterobj = new XmlDumpWriter(); $input = fopen( $this->input, "rt" ); - $result = $this->readDump( $input ); + $this->readDump( $input ); if ( $this->spawnProc ) { $this->closeSpawn(); @@ -182,7 +183,7 @@ class TextPassDumper extends BackupDumper { global $IP; $url = $this->processFileOpt( $val, $param ); - switch( $opt ) { + switch ( $opt ) { case 'prefetch': require_once "$IP/maintenance/backupPrefetch.inc"; $this->prefetch = new BaseDump( $url ); @@ -214,7 +215,7 @@ class TextPassDumper extends BackupDumper { function processFileOpt( $val, $param ) { $fileURIs = explode( ';', $param ); foreach ( $fileURIs as $URI ) { - switch( $val ) { + switch ( $val ) { case "file": $newURI = $URI; break; @@ -294,11 +295,11 @@ class TextPassDumper extends BackupDumper { } function setTimeExceeded() { - $this->timeExceeded = True; + $this->timeExceeded = true; } function checkIfTimeExceeded() { - if ( $this->maxTimeAllowed && ( $this->lastTime - $this->timeOfCheckpoint > $this->maxTimeAllowed ) ) { + if ( $this->maxTimeAllowed && ( $this->lastTime - $this->timeOfCheckpoint > $this->maxTimeAllowed ) ) { return true; } return false; @@ -413,6 +414,8 @@ 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. @@ -478,7 +481,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++; @@ -611,17 +635,21 @@ class TextPassDumper extends BackupDumper { private function closeSpawn() { wfSuppressWarnings(); - if ( $this->spawnRead ) + if ( $this->spawnRead ) { fclose( $this->spawnRead ); + } $this->spawnRead = false; - if ( $this->spawnWrite ) + if ( $this->spawnWrite ) { fclose( $this->spawnWrite ); + } $this->spawnWrite = false; - if ( $this->spawnErr ) + if ( $this->spawnErr ) { fclose( $this->spawnErr ); + } $this->spawnErr = false; - if ( $this->spawnProc ) + if ( $this->spawnProc ) { pclose( $this->spawnProc ); + } $this->spawnProc = false; wfRestoreWarnings(); } @@ -631,11 +659,15 @@ class TextPassDumper extends BackupDumper { $ok = fwrite( $this->spawnWrite, "$id\n" ); // $this->progress( ">> $id" ); - if ( !$ok ) return false; + if ( !$ok ) { + return false; + } $ok = fflush( $this->spawnWrite ); // $this->progress( ">> [flush]" ); - if ( !$ok ) return false; + if ( !$ok ) { + return false; + } // check that the text id they are sending is the one we asked for // this avoids out of sync revision text errors we have encountered in the past @@ -649,18 +681,24 @@ class TextPassDumper extends BackupDumper { $len = fgets( $this->spawnRead ); // $this->progress( "<< " . trim( $len ) ); - if ( $len === false ) return false; + if ( $len === false ) { + return false; + } $nbytes = intval( $len ); // actual error, not zero-length text - if ( $nbytes < 0 ) return false; + if ( $nbytes < 0 ) { + return false; + } $text = ""; // Subprocess may not send everything at once, we have to loop. while ( $nbytes > strlen( $text ) ) { $buffer = fread( $this->spawnRead, $nbytes - strlen( $text ) ); - if ( $buffer === false ) break; + if ( $buffer === false ) { + break; + } $text .= $buffer; } |