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