X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FfetchText.php;h=8d04adc6688c245fc840e397a6a12dda34f04e9f;hb=aac6b26c0bafc81287bb042304f1d346da94dc89;hp=9dee6e530dbf69d5d104e4ddd39062141337fe4d;hpb=e968a1f431ad058dcb14adb2757bde5664b99a79;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/fetchText.php b/maintenance/fetchText.php index 9dee6e530d..8d04adc668 100644 --- a/maintenance/fetchText.php +++ b/maintenance/fetchText.php @@ -24,20 +24,34 @@ require_once __DIR__ . '/Maintenance.php'; +use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\BlobAccessException; +use MediaWiki\Storage\SqlBlobStore; + /** * Maintenance script used to fetch page text in a subprocess. * * @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 @@ -49,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 ); @@ -57,38 +70,31 @@ 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 Database $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"; +$maintClass = FetchText::class; require_once RUN_MAINTENANCE_IF_MAIN;