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 $ex ) {
84  // XXX: log $ex to stderr?
85  $textLen = '-1';
86  $text = '';
87  } catch ( InvalidArgumentException $ex ) {
88  // XXX: log $ex to stderr?
89  $textLen = '-1';
90  $text = '';
91  }
92 
93  $this->output( $blobAddress . "\n" . $textLen . "\n" . $text );
94  }
95  }
96 
97 }
98 
99 $maintClass = FetchText::class;
100 require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:86
Maintenance script used to fetch page text in a subprocess.
Definition: fetchText.php:36
Exception representing a failure to access a data blob.
__construct()
Definition: fetchText.php:38
addDescription( $text)
Set the description text.
output( $out, $channel=null)
Throw some output to the user.
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition: fetchText.php:65
getBlobStore()
Definition: fetchText.php:51
$maintClass
Definition: fetchText.php:99
$line
Definition: mcc.php:119
getStdin( $len=null)
Return input from stdin.