MediaWiki
master
fixLegacyEncoding.php
Go to the documentation of this file.
1
<?php
22
use
MediaWiki\Storage\SqlBlobStore
;
23
use
Wikimedia\Rdbms\IExpression
;
24
use
Wikimedia\Rdbms\LikeValue
;
25
26
require_once __DIR__ .
'/moveToExternal.php'
;
27
28
class
FixLegacyEncoding
extends
MoveToExternal
{
29
public
function
__construct
() {
30
parent::__construct();
31
$this->
addDescription
(
'Change encoding of stored content from legacy encoding to UTF-8'
);
32
}
33
34
protected
function
getConditions
( $blockStart, $blockEnd, $dbr ) {
35
return
[
36
$dbr->expr(
'old_id'
,
'>='
, $blockStart ),
37
$dbr->expr(
'old_id'
,
'<='
, $blockEnd ),
38
$dbr->expr(
'old_flags'
, IExpression::NOT_LIKE,
39
new
LikeValue
( $dbr->anyString(),
'utf-8'
, $dbr->anyString() ) ),
40
$dbr->expr(
'old_flags'
, IExpression::NOT_LIKE,
41
new
LikeValue
( $dbr->anyString(),
'utf8'
, $dbr->anyString() ) ),
42
];
43
}
44
45
protected
function
resolveText
( $text, $flags ) {
46
if
( in_array(
'error'
, $flags ) ) {
47
return
[ $text, $flags ];
48
}
49
$blobStore = $this->
getServiceContainer
()->getBlobStore();
50
if
( in_array(
'external'
, $flags ) && $blobStore instanceof
SqlBlobStore
) {
51
$newText = $blobStore->expandBlob( $text, $flags );
52
if
( $newText ===
false
) {
53
return
[
false
, $flags ];
54
}
55
$text = $newText;
56
// It will be put back in external storage again
57
$flags = array_diff( $flags, [
'external'
] );
58
}
59
if
( in_array(
'gzip'
, $flags ) ) {
60
$newText = gzinflate( $text );
61
if
( $newText ===
false
) {
62
return
[
false
, $flags ];
63
}
64
$text = $newText;
65
$flags = array_diff( $flags, [
'gzip'
] );
66
}
67
return
[ $text, $flags ];
68
}
69
70
}
71
72
$maintClass
= FixLegacyEncoding::class;
73
require_once RUN_MAINTENANCE_IF_MAIN;
FixLegacyEncoding
Definition
fixLegacyEncoding.php:28
FixLegacyEncoding\__construct
__construct()
Default constructor.
Definition
fixLegacyEncoding.php:29
FixLegacyEncoding\resolveText
resolveText( $text, $flags)
Definition
fixLegacyEncoding.php:45
FixLegacyEncoding\getConditions
getConditions( $blockStart, $blockEnd, $dbr)
Definition
fixLegacyEncoding.php:34
Maintenance\getServiceContainer
getServiceContainer()
Returns the main service container.
Definition
Maintenance.php:641
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition
Maintenance.php:329
MediaWiki\Storage\SqlBlobStore
Service for storing and loading Content objects representing revision data blobs.
Definition
SqlBlobStore.php:50
MoveToExternal
Definition
moveToExternal.php:33
Wikimedia\Rdbms\LikeValue
Content of like value.
Definition
LikeValue.php:14
$maintClass
$maintClass
Definition
fixLegacyEncoding.php:72
Wikimedia\Rdbms\IExpression
Definition
IExpression.php:10
maintenance
storage
fixLegacyEncoding.php
Generated on Fri May 3 2024 17:26:22 for MediaWiki by
1.10.0