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