X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FfetchText.php;h=8d04adc6688c245fc840e397a6a12dda34f04e9f;hb=12a75b2f2600073d86cdeaf194e6b4c5c659b53f;hp=9c5a375154aa3f3cca84066c86b7624468d37cb3;hpb=dc1632d58ee3b016697667bfc003338141bc3ce7;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/fetchText.php b/maintenance/fetchText.php index 9c5a375154..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,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 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"; +$maintClass = FetchText::class; require_once RUN_MAINTENANCE_IF_MAIN;