MediaWiki REL1_37
fetchText.php
Go to the documentation of this file.
1<?php
25require_once __DIR__ . '/Maintenance.php';
26
31
37class 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;
97require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script used to fetch page text in a subprocess.
Definition fetchText.php:37
__construct()
Default constructor.
Definition fetchText.php:39
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition fetchText.php:66
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Exception representing a failure to access a data blob.
Service for storing and loading Content objects.
$maintClass
Definition fetchText.php:96
Service for loading and storing data blobs.
Definition BlobStore.php:35
$line
Definition mcc.php:119