MediaWiki
master
Toggle main menu visibility
fetchText.php
Go to the documentation of this file.
1
<?php
10
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
$maintClass
$maintClass
Definition
addChangeTag.php:56
FetchText
Maintenance script used to fetch page text in a subprocess.
Definition
fetchText.php:26
FetchText\__construct
__construct()
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\MediaWikiServices
Service locator for MediaWiki core services.
Definition
MediaWikiServices.php:273
MediaWiki\MediaWikiServices\getInstance
static getInstance()
Returns the global default instance of the top level service locator.
Definition
MediaWikiServices.php:361
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
MediaWiki\Storage\SqlBlobStore\makeAddressFromTextId
static makeAddressFromTextId( $id)
Returns an address referring to content stored in the text table row with the given ID.
Definition
SqlBlobStore.php:724
MediaWiki\Storage\BlobStore
Service for loading and storing data blobs.
Definition
BlobStore.php:19
MediaWiki\Maintenance
Definition
applyChangeTag.php:11
maintenance
fetchText.php
Generated on
for MediaWiki by
1.18.0