MediaWiki master
fetchText.php
Go to the documentation of this file.
1<?php
25require_once __DIR__ . '/Maintenance.php';
26
32
38class FetchText extends Maintenance {
39
40 public function __construct() {
41 parent::__construct();
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
49 public function finalSetup( SettingsBuilder $settingsBuilder ) {
50 // This script should always try to run all db queries in the 'dump' group if such
51 // a group exists, just like the BackupDumper and TextPassDumper modules.
52 // To account for parts of MediaWiki that get their own db connection outside of
53 // Maintenance::getDB(), we set this global variable so that they will attempt
54 // to use this group.
55 $settingsBuilder->putConfigValue( MainConfigNames::DBDefaultGroup, 'dump' );
56 // do this last so that options can override
57
58 parent::finalSetup( $settingsBuilder );
59 }
60
64 private function getBlobStore() {
65 return $this->getServiceContainer()->getBlobStore();
66 }
67
78 public function execute() {
79 $stdin = $this->getStdin();
80 while ( !feof( $stdin ) ) {
81 $line = fgets( $stdin );
82 if ( $line === false ) {
83 // We appear to have lost contact...
84 break;
85 }
86 $blobAddress = trim( $line );
87
88 // Plain integers are supported for backwards compatibility with pre-MCR dumps.
89 if ( strpos( $blobAddress, ':' ) === false && is_numeric( $blobAddress ) ) {
90 $blobAddress = SqlBlobStore::makeAddressFromTextId( intval( $blobAddress ) );
91 }
92
93 try {
94 $text = $this->getBlobStore()->getBlob( $blobAddress );
95 $textLen = strlen( $text );
96 } catch ( BlobAccessException | InvalidArgumentException $ex ) {
97 // XXX: log $ex to stderr?
98 $textLen = '-1';
99 $text = '';
100 }
101
102 $this->output( $blobAddress . "\n" . $textLen . "\n" . $text );
103 }
104 }
105
106}
107
108$maintClass = FetchText::class;
109require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script used to fetch page text in a subprocess.
Definition fetchText.php:38
finalSetup(SettingsBuilder $settingsBuilder)
Handle some last-minute setup here.
Definition fetchText.php:49
__construct()
Default constructor.
Definition fetchText.php:40
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition fetchText.php:78
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.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
A class containing constants representing the names of configuration variables.
Builder class for constructing a Config object from a set of sources during bootstrap.
putConfigValue(string $key, $value)
Puts a value into a config variable.
Exception representing a failure to access a data blob.
Service for storing and loading Content objects representing revision data blobs.
$maintClass
Service for loading and storing data blobs.
Definition BlobStore.php:33