MediaWiki REL1_34
fetchText.php
Go to the documentation of this file.
1<?php
25require_once __DIR__ . '/Maintenance.php';
26
30
36class 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;
100require_once RUN_MAINTENANCE_IF_MAIN;
const RUN_MAINTENANCE_IF_MAIN
$line
Definition cdb.php:59
Maintenance script used to fetch page text in a subprocess.
Definition fetchText.php:36
__construct()
Default constructor.
Definition fetchText.php:38
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition fetchText.php:65
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:99