MediaWiki
master
fetchText.php
Go to the documentation of this file.
1
<?php
11
// @codeCoverageIgnoreStart
12
require_once __DIR__ .
'/Maintenance.php'
;
13
// @codeCoverageIgnoreEnd
14
15
use
MediaWiki\Maintenance\Maintenance
;
16
use
MediaWiki\MediaWikiServices
;
17
use
MediaWiki\Storage\BlobAccessException
;
18
use
MediaWiki\Storage\BlobStore
;
19
use
MediaWiki\Storage\SqlBlobStore
;
20
26
class
FetchText
extends
Maintenance
{
27
28
public
function
__construct
() {
29
parent::__construct();
30
$this->
addDescription
(
"Fetch the raw revision blob from a blob address.\n"
.
31
"Integer IDs are interpreted as referring to text.old_id for backwards compatibility.\n"
.
32
"NOTE: Export transformations are NOT applied. "
.
33
"This is left to dumpTextPass.php"
34
);
35
}
36
40
private
function
getBlobStore() {
41
return
$this->
getServiceContainer
()->getBlobStore();
42
}
43
54
public
function
execute
() {
55
MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->setDefaultGroupName(
'dump'
);
56
$stdin = $this->
getStdin
();
57
while
( !feof( $stdin ) ) {
58
$line = fgets( $stdin );
59
if
( $line ===
false
) {
60
// We appear to have lost contact...
61
break
;
62
}
63
$blobAddress = trim( $line );
64
65
// Plain integers are supported for backwards compatibility with pre-MCR dumps.
66
if
( !str_contains( $blobAddress,
':'
) && is_numeric( $blobAddress ) ) {
67
$blobAddress = SqlBlobStore::makeAddressFromTextId( intval( $blobAddress ) );
68
}
69
70
try
{
71
$text = $this->getBlobStore()->getBlob( $blobAddress );
72
$textLen = strlen( $text );
73
}
catch
(
BlobAccessException
| InvalidArgumentException ) {
74
// XXX: log $ex to stderr?
75
$textLen =
'-1'
;
76
$text =
''
;
77
}
78
79
$this->
output
( $blobAddress .
"\n"
. $textLen .
"\n"
. $text );
80
}
81
}
82
83
}
84
85
// @codeCoverageIgnoreStart
86
$maintClass
= FetchText::class;
87
require_once RUN_MAINTENANCE_IF_MAIN;
88
// @codeCoverageIgnoreEnd
FetchText
Maintenance script used to fetch page text in a subprocess.
Definition
fetchText.php:26
FetchText\__construct
__construct()
Default constructor.
Definition
fetchText.php:28
FetchText\execute
execute()
returns a string containing the following in order: textid \n length of text (-1 on error = failure t...
Definition
fetchText.php:54
MediaWiki\Maintenance\Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition
Maintenance.php:65
MediaWiki\Maintenance\Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition
Maintenance.php:486
MediaWiki\Maintenance\Maintenance\getServiceContainer
getServiceContainer()
Returns the main service container.
Definition
Maintenance.php:680
MediaWiki\Maintenance\Maintenance\getStdin
getStdin( $len=null)
Return input from stdin.
Definition
Maintenance.php:458
MediaWiki\Maintenance\Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:336
MediaWiki\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:257
MediaWiki\Storage\BlobAccessException
Exception representing a failure to access a data blob.
Definition
BlobAccessException.php:17
MediaWiki\Storage\SqlBlobStore
Service for storing and loading Content objects representing revision data blobs.
Definition
SqlBlobStore.php:36
$maintClass
$maintClass
Definition
fetchText.php:86
MediaWiki\Storage\BlobStore
Service for loading and storing data blobs.
Definition
BlobStore.php:19
maintenance
fetchText.php
Generated on Thu Jan 15 2026 16:28:05 for MediaWiki by
1.10.0