MediaWiki  master
fetchText.php
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/Maintenance.php';
26 
31 
37 class FetchText extends Maintenance {
38 
39  public function __construct() {
40  parent::__construct();
41 
42  $this->addDescription( "Fetch the raw revision blob from a blob address.\n" .
43  "Integer IDs are interpreted as referring to text.old_id for backwards compatibility.\n" .
44  "NOTE: Export transformations are NOT applied. " .
45  "This is left to dumpTextPass.php"
46  );
47  }
48 
52  private function getBlobStore() {
53  return MediaWikiServices::getInstance()->getBlobStore();
54  }
55 
66  public function execute() {
67  $stdin = $this->getStdin();
68  while ( !feof( $stdin ) ) {
69  $line = fgets( $stdin );
70  if ( $line === false ) {
71  // We appear to have lost contact...
72  break;
73  }
74  $blobAddress = trim( $line );
75 
76  // Plain integers are supported for backwards compatibility with pre-MCR dumps.
77  if ( strpos( $blobAddress, ':' ) === false && is_numeric( $blobAddress ) ) {
78  $blobAddress = SqlBlobStore::makeAddressFromTextId( intval( $blobAddress ) );
79  }
80 
81  try {
82  $text = $this->getBlobStore()->getBlob( $blobAddress );
83  $textLen = strlen( $text );
84  } catch ( BlobAccessException | InvalidArgumentException $ex ) {
85  // XXX: log $ex to stderr?
86  $textLen = '-1';
87  $text = '';
88  }
89 
90  $this->output( $blobAddress . "\n" . $textLen . "\n" . $text );
91  }
92  }
93 
94 }
95 
96 $maintClass = FetchText::class;
97 require_once RUN_MAINTENANCE_IF_MAIN;
FetchText
Maintenance script used to fetch page text in a subprocess.
Definition: fetchText.php:37
MediaWiki\Storage\BlobAccessException
Exception representing a failure to access a data blob.
Definition: BlobAccessException.php:33
Maintenance\getStdin
getStdin( $len=null)
Return input from stdin.
Definition: Maintenance.php:407
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:200
MediaWiki\Storage\SqlBlobStore
Service for storing and loading Content objects.
Definition: SqlBlobStore.php:52
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:329
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:59
FetchText\execute
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition: fetchText.php:66
$maintClass
$maintClass
Definition: fetchText.php:96
$line
$line
Definition: mcc.php:119
FetchText\getBlobStore
getBlobStore()
Definition: fetchText.php:52
MediaWiki\Storage\BlobStore
Service for loading and storing data blobs.
Definition: BlobStore.php:35
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:435
FetchText\__construct
__construct()
Default constructor.
Definition: fetchText.php:39