MediaWiki master
fetchText.php
Go to the documentation of this file.
1<?php
25// @codeCoverageIgnoreStart
26require_once __DIR__ . '/Maintenance.php';
27// @codeCoverageIgnoreEnd
28
35
41class FetchText extends Maintenance {
42
43 public function __construct() {
44 parent::__construct();
45 $this->addDescription( "Fetch the raw revision blob from a blob address.\n" .
46 "Integer IDs are interpreted as referring to text.old_id for backwards compatibility.\n" .
47 "NOTE: Export transformations are NOT applied. " .
48 "This is left to dumpTextPass.php"
49 );
50 }
51
52 public function finalSetup( SettingsBuilder $settingsBuilder ) {
53 // This script should always try to run all db queries in the 'dump' group if such
54 // a group exists, just like the BackupDumper and TextPassDumper modules.
55 // To account for parts of MediaWiki that get their own db connection outside of
56 // Maintenance::getDB(), we set this global variable so that they will attempt
57 // to use this group.
58 $settingsBuilder->putConfigValue( MainConfigNames::DBDefaultGroup, 'dump' );
59 // do this last so that options can override
60
61 parent::finalSetup( $settingsBuilder );
62 }
63
67 private function getBlobStore() {
68 return $this->getServiceContainer()->getBlobStore();
69 }
70
81 public function execute() {
82 $stdin = $this->getStdin();
83 while ( !feof( $stdin ) ) {
84 $line = fgets( $stdin );
85 if ( $line === false ) {
86 // We appear to have lost contact...
87 break;
88 }
89 $blobAddress = trim( $line );
90
91 // Plain integers are supported for backwards compatibility with pre-MCR dumps.
92 if ( strpos( $blobAddress, ':' ) === false && is_numeric( $blobAddress ) ) {
93 $blobAddress = SqlBlobStore::makeAddressFromTextId( intval( $blobAddress ) );
94 }
95
96 try {
97 $text = $this->getBlobStore()->getBlob( $blobAddress );
98 $textLen = strlen( $text );
99 } catch ( BlobAccessException | InvalidArgumentException $ex ) {
100 // XXX: log $ex to stderr?
101 $textLen = '-1';
102 $text = '';
103 }
104
105 $this->output( $blobAddress . "\n" . $textLen . "\n" . $text );
106 }
107 }
108
109}
110
111// @codeCoverageIgnoreStart
112$maintClass = FetchText::class;
113require_once RUN_MAINTENANCE_IF_MAIN;
114// @codeCoverageIgnoreEnd
Maintenance script used to fetch page text in a subprocess.
Definition fetchText.php:41
finalSetup(SettingsBuilder $settingsBuilder)
Handle some last-minute setup here.
Definition fetchText.php:52
__construct()
Default constructor.
Definition fetchText.php:43
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition fetchText.php:81
A class containing constants representing the names of configuration variables.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
getServiceContainer()
Returns the main service container.
getStdin( $len=null)
Return input from stdin.
addDescription( $text)
Set the description text.
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