X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FfetchText.php;h=8d04adc6688c245fc840e397a6a12dda34f04e9f;hb=62991fcb7a5027b1eceb5656829c1c65bf9f98cb;hp=bc4fa31f10a23af8b91821e13c46b947fcfedb67;hpb=6f7e982df6479e27c3b17f2deda8404ef55f50e6;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/fetchText.php b/maintenance/fetchText.php index bc4fa31f10..8d04adc668 100644 --- a/maintenance/fetchText.php +++ b/maintenance/fetchText.php @@ -24,7 +24,9 @@ require_once __DIR__ . '/Maintenance.php'; -use Wikimedia\Rdbms\IDatabase; +use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\BlobAccessException; +use MediaWiki\Storage\SqlBlobStore; /** * Maintenance script used to fetch page text in a subprocess. @@ -32,14 +34,24 @@ use Wikimedia\Rdbms\IDatabase; * @ingroup Maintenance */ class FetchText extends Maintenance { + public function __construct() { parent::__construct(); - $this->addDescription( "Fetch the raw revision blob from an old_id.\n" . + + $this->addDescription( "Fetch the raw revision blob from a blob address.\n" . + "Integer IDs are interpreted as referring to text.old_id for backwards compatibility.\n" . "NOTE: Export transformations are NOT applied. " . - "This is left to backupTextPass.php" + "This is left to dumpTextPass.php" ); } + /** + * @return SqlBlobStore + */ + private function getBlobStore() { + return MediaWikiServices::getInstance()->getBlobStore(); + } + /** * returns a string containing the following in order: * textid @@ -51,7 +63,6 @@ class FetchText extends Maintenance { * note that the text string itself is *not* followed by newline */ public function execute() { - $db = $this->getDB( DB_REPLICA ); $stdin = $this->getStdin(); while ( !feof( $stdin ) ) { $line = fgets( $stdin ); @@ -59,37 +70,30 @@ class FetchText extends Maintenance { // We appear to have lost contact... break; } - $textId = intval( $line ); - $text = $this->doGetText( $db, $textId ); - if ( $text === false ) { - # actual error, not zero-length text - $textLen = "-1"; - } else { + $blobAddress = trim( $line ); + + // Plain integers are supported for backwards compatibility with pre-MCR dumps. + if ( strpos( $blobAddress, ':' ) === false && is_numeric( $blobAddress ) ) { + $blobAddress = SqlBlobStore::makeAddressFromTextId( intval( $blobAddress ) ); + } + + try { + $text = $this->getBlobStore()->getBlob( $blobAddress ); $textLen = strlen( $text ); + } catch ( BlobAccessException $ex ) { + // XXX: log $ex to stderr? + $textLen = '-1'; + $text = ''; + } catch ( InvalidArgumentException $ex ) { + // XXX: log $ex to stderr? + $textLen = '-1'; + $text = ''; } - $this->output( $textId . "\n" . $textLen . "\n" . $text ); - } - } - /** - * May throw a database error if, say, the server dies during query. - * @param IDatabase $db - * @param int $id The old_id - * @return string - */ - private function doGetText( $db, $id ) { - $id = intval( $id ); - $row = $db->selectRow( 'text', - [ 'old_text', 'old_flags' ], - [ 'old_id' => $id ], - __METHOD__ ); - $text = Revision::getRevisionText( $row ); - if ( $text === false ) { - return false; + $this->output( $blobAddress . "\n" . $textLen . "\n" . $text ); } - - return $text; } + } $maintClass = FetchText::class;