require_once __DIR__ . '/../includes/export/WikiExporter.php';
use MediaWiki\MediaWikiServices;
+use MediaWiki\Storage\BlobAccessException;
+use MediaWiki\Storage\SqlBlobStore;
use Wikimedia\Rdbms\IMaintainableDatabase;
/**
}
}
+ /**
+ * @return SqlBlobStore
+ */
+ private function getBlobStore() {
+ return MediaWikiServices::getInstance()->getBlobStore();
+ }
+
function execute() {
$this->processOptions();
$this->dump( true );
}
/**
- * Tries to get the revision text for a revision id.
- * Export transformations are applied if the content model can is given or can be
+ * Tries to load revision text.
+ * Export transformations are applied if the content model is given or can be
* determined from the database.
*
* Upon errors, retries (Up to $this->maxFailures tries each call).
- * If still no good revision get could be found even after this retrying, "" is returned.
+ * If still no good revision could be found even after this retrying, "" is returned.
* If no good revision text could be returned for
* $this->maxConsecutiveFailedTextRetrievals consecutive calls to getText, MWException
* is thrown.
*
- * @param string $id The revision id to get the text for
+ * @param int|string $id Content address, or text row ID.
* @param string|bool|null $model The content model used to determine
* applicable export transformations.
* If $model is null, it will be determined from the database.
$consecutiveFailedTextRetrievals = 0;
if ( $model === null && $wgContentHandlerUseDB ) {
+ // TODO: MCR: use content table
$row = $this->db->selectRow(
'revision',
[ 'rev_content_model', 'rev_content_format' ],
}
/**
- * May throw a database error if, say, the server dies during query.
- * @param int $id
+ * Loads the serialized content from storage.
+ *
+ * @param int|string $id Content address, or text row ID.
* @return bool|string
- * @throws MWException
*/
private function getTextDb( $id ) {
- if ( !isset( $this->db ) ) {
- throw new MWException( __METHOD__ . "No database available" );
- }
- $row = $this->db->selectRow( 'text',
- [ 'old_text', 'old_flags' ],
- [ 'old_id' => $id ],
- __METHOD__ );
- $text = Revision::getRevisionText( $row );
- if ( $text === false ) {
+ $store = $this->getBlobStore();
+ $address = ( is_int( $id ) || strpos( $id, ':' ) === false )
+ ? SqlBlobStore::makeAddressFromTextId( (int)$id )
+ : $id;
+
+ try {
+ $text = $store->getBlob( $address );
+
+ $stripped = str_replace( "\r", "", $text );
+ $normalized = MediaWikiServices::getInstance()->getContentLanguage()
+ ->normalize( $stripped );
+
+ return $normalized;
+ } catch ( BlobAccessException $ex ) {
+ // XXX: log a warning?
return false;
}
- $stripped = str_replace( "\r", "", $text );
- $normalized = MediaWikiServices::getInstance()->getContentLanguage()->
- normalize( $stripped );
-
- return $normalized;
}
- private function getTextSpawned( $id ) {
+ /**
+ * @param int|string $address Content address, or text row ID.
+ * @return bool|string
+ */
+ private function getTextSpawned( $address ) {
Wikimedia\suppressWarnings();
if ( !$this->spawnProc ) {
// First time?
$this->openSpawn();
}
- $text = $this->getTextSpawnedOnce( $id );
+ $text = $this->getTextSpawnedOnce( $address );
Wikimedia\restoreWarnings();
return $text;
Wikimedia\restoreWarnings();
}
- private function getTextSpawnedOnce( $id ) {
- $ok = fwrite( $this->spawnWrite, "$id\n" );
+ /**
+ * @param int|string $address Content address, or text row ID.
+ * @return bool|string
+ */
+ private function getTextSpawnedOnce( $address ) {
+ if ( is_int( $address ) || intval( $address ) ) {
+ $address = SqlBlobStore::makeAddressFromTextId( (int)$address );
+ }
+
+ $ok = fwrite( $this->spawnWrite, "$address\n" );
// $this->progress( ">> $id" );
if ( !$ok ) {
return false;
return false;
}
- // check that the text id they are sending is the one we asked for
+ // check that the text address they are sending is the one we asked for
// this avoids out of sync revision text errors we have encountered in the past
- $newId = fgets( $this->spawnRead );
- if ( $newId === false ) {
+ $newAddress = fgets( $this->spawnRead );
+ if ( $newAddress === false ) {
return false;
}
- if ( $id != intval( $newId ) ) {
+ $newAddress = trim( $newAddress );
+ if ( strpos( $newAddress, ':' ) === false ) {
+ $newAddress = SqlBlobStore::makeAddressFromTextId( intval( $newAddress ) );
+ }
+
+ if ( $newAddress !== $address ) {
return false;
}