MediaWiki
1.43.1
fetchText.php
Go to the documentation of this file.
1
<?php
25
// @codeCoverageIgnoreStart
26
require_once __DIR__ .
'/Maintenance.php'
;
27
// @codeCoverageIgnoreEnd
28
29
use
MediaWiki\MainConfigNames
;
30
use
MediaWiki\Settings\SettingsBuilder
;
31
use
MediaWiki\Storage\BlobAccessException
;
32
use
MediaWiki\Storage\BlobStore
;
33
use
MediaWiki\Storage\SqlBlobStore
;
34
40
class
FetchText
extends
Maintenance {
41
42
public
function
__construct
() {
43
parent::__construct();
44
$this->addDescription(
"Fetch the raw revision blob from a blob address.\n"
.
45
"Integer IDs are interpreted as referring to text.old_id for backwards compatibility.\n"
.
46
"NOTE: Export transformations are NOT applied. "
.
47
"This is left to dumpTextPass.php"
48
);
49
}
50
51
public
function
finalSetup
(
SettingsBuilder
$settingsBuilder ) {
52
// This script should always try to run all db queries in the 'dump' group if such
53
// a group exists, just like the BackupDumper and TextPassDumper modules.
54
// To account for parts of MediaWiki that get their own db connection outside of
55
// Maintenance::getDB(), we set this global variable so that they will attempt
56
// to use this group.
57
$settingsBuilder->
putConfigValue
( MainConfigNames::DBDefaultGroup,
'dump'
);
58
// do this last so that options can override
59
60
parent::finalSetup( $settingsBuilder );
61
}
62
66
private
function
getBlobStore() {
67
return
$this->getServiceContainer()->getBlobStore();
68
}
69
80
public
function
execute
() {
81
$stdin = $this->getStdin();
82
while
( !feof( $stdin ) ) {
83
$line = fgets( $stdin );
84
if
( $line ===
false
) {
85
// We appear to have lost contact...
86
break
;
87
}
88
$blobAddress = trim( $line );
89
90
// Plain integers are supported for backwards compatibility with pre-MCR dumps.
91
if
( strpos( $blobAddress,
':'
) ===
false
&& is_numeric( $blobAddress ) ) {
92
$blobAddress = SqlBlobStore::makeAddressFromTextId( intval( $blobAddress ) );
93
}
94
95
try
{
96
$text = $this->getBlobStore()->getBlob( $blobAddress );
97
$textLen = strlen( $text );
98
}
catch
(
BlobAccessException
| InvalidArgumentException $ex ) {
99
// XXX: log $ex to stderr?
100
$textLen =
'-1'
;
101
$text =
''
;
102
}
103
104
$this->output( $blobAddress .
"\n"
. $textLen .
"\n"
. $text );
105
}
106
}
107
108
}
109
110
// @codeCoverageIgnoreStart
111
$maintClass
= FetchText::class;
112
require_once RUN_MAINTENANCE_IF_MAIN;
113
// @codeCoverageIgnoreEnd
FetchText
Maintenance script used to fetch page text in a subprocess.
Definition
fetchText.php:40
FetchText\finalSetup
finalSetup(SettingsBuilder $settingsBuilder)
Definition
fetchText.php:51
FetchText\__construct
__construct()
Definition
fetchText.php:42
FetchText\execute
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition
fetchText.php:80
MediaWiki\MainConfigNames
A class containing constants representing the names of configuration variables.
Definition
MainConfigNames.php:22
MediaWiki\Settings\SettingsBuilder
Builder class for constructing a Config object from a set of sources during bootstrap.
Definition
SettingsBuilder.php:55
MediaWiki\Settings\SettingsBuilder\putConfigValue
putConfigValue(string $key, $value)
Puts a value into a config variable.
Definition
SettingsBuilder.php:670
MediaWiki\Storage\BlobAccessException
Exception representing a failure to access a data blob.
Definition
BlobAccessException.php:31
MediaWiki\Storage\SqlBlobStore
Service for storing and loading Content objects representing revision data blobs.
Definition
SqlBlobStore.php:50
$maintClass
$maintClass
Definition
fetchText.php:111
MediaWiki\Storage\BlobStore
Service for loading and storing data blobs.
Definition
BlobStore.php:33
maintenance
fetchText.php
Generated on Thu Apr 10 2025 18:15:53 for MediaWiki by
1.10.0