MediaWiki master
fetchText.php
Go to the documentation of this file.
1<?php
10
11// @codeCoverageIgnoreStart
12require_once __DIR__ . '/Maintenance.php';
13// @codeCoverageIgnoreEnd
14
20
26class FetchText extends Maintenance {
27
28 public function __construct() {
29 parent::__construct();
30 $this->addDescription( "Fetch the raw revision blob from a blob address.\n" .
31 "Integer IDs are interpreted as referring to text.old_id for backwards compatibility.\n" .
32 "NOTE: Export transformations are NOT applied. " .
33 "This is left to dumpTextPass.php"
34 );
35 }
36
40 private function getBlobStore() {
41 return $this->getServiceContainer()->getBlobStore();
42 }
43
54 public function execute() {
55 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->setDefaultGroupName( 'dump' );
56 $stdin = $this->getStdin();
57 while ( !feof( $stdin ) ) {
58 $line = fgets( $stdin );
59 if ( $line === false ) {
60 // We appear to have lost contact...
61 break;
62 }
63 $blobAddress = trim( $line );
64
65 // Plain integers are supported for backwards compatibility with pre-MCR dumps.
66 if ( !str_contains( $blobAddress, ':' ) && is_numeric( $blobAddress ) ) {
67 $blobAddress = SqlBlobStore::makeAddressFromTextId( intval( $blobAddress ) );
68 }
69
70 try {
71 $text = $this->getBlobStore()->getBlob( $blobAddress );
72 $textLen = strlen( $text );
73 } catch ( BlobAccessException | InvalidArgumentException ) {
74 // XXX: log $ex to stderr?
75 $textLen = '-1';
76 $text = '';
77 }
78
79 $this->output( $blobAddress . "\n" . $textLen . "\n" . $text );
80 }
81 }
82
83}
84
85// @codeCoverageIgnoreStart
86$maintClass = FetchText::class;
87require_once RUN_MAINTENANCE_IF_MAIN;
88// @codeCoverageIgnoreEnd
$maintClass
Maintenance script used to fetch page text in a subprocess.
Definition fetchText.php:26
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition fetchText.php:54
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
Exception representing a failure to access a data blob.
Service for storing and loading Content objects representing revision data blobs.
static makeAddressFromTextId( $id)
Returns an address referring to content stored in the text table row with the given ID.
Service for loading and storing data blobs.
Definition BlobStore.php:19