| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
use MediaWiki\Storage\SqlBlobStore; |
| 23 |
use Wikimedia\Rdbms\IExpression; |
| 24 |
use Wikimedia\Rdbms\LikeValue; |
| 25 |
|
| 26 |
|
| 27 |
require_once __DIR__ . '/moveToExternal.php'; |
| 28 |
|
| 29 |
|
| 30 |
class FixLegacyEncoding extends MoveToExternal { |
| 31 |
public function __construct() { |
| 32 |
parent::__construct(); |
| 33 |
$this->addDescription( 'Change encoding of stored content from legacy encoding to UTF-8' ); |
| 34 |
} |
| 35 |
|
| 36 |
protected function getConditions( $blockStart, $blockEnd, $dbr ) { |
| 37 |
return [ |
| 38 |
$dbr->expr( 'old_id', '>=', $blockStart ), |
| 39 |
$dbr->expr( 'old_id', '<=', $blockEnd ), |
| 40 |
$dbr->expr( 'old_flags', IExpression::NOT_LIKE, |
| 41 |
new LikeValue( $dbr->anyString(), 'utf-8', $dbr->anyString() ) ), |
| 42 |
$dbr->expr( 'old_flags', IExpression::NOT_LIKE, |
| 43 |
new LikeValue( $dbr->anyString(), 'utf8', $dbr->anyString() ) ), |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
protected function resolveText( $text, $flags ) { |
| 48 |
if ( in_array( 'error', $flags ) ) { |
| 49 |
return [ $text, $flags ]; |
| 50 |
} |
| 51 |
$blobStore = $this->getServiceContainer()->getBlobStore(); |
| 52 |
if ( in_array( 'external', $flags ) && $blobStore instanceof SqlBlobStore ) { |
| 53 |
$newText = $blobStore->expandBlob( $text, $flags ); |
| 54 |
if ( $newText === false ) { |
| 55 |
return [ false, $flags ]; |
| 56 |
} |
| 57 |
$text = $newText; |
| 58 |
|
| 59 |
$flags = array_diff( $flags, [ 'external' ] ); |
| 60 |
} |
| 61 |
if ( in_array( 'gzip', $flags ) ) { |
| 62 |
$newText = gzinflate( $text ); |
| 63 |
if ( $newText === false ) { |
| 64 |
return [ false, $flags ]; |
| 65 |
} |
| 66 |
$text = $newText; |
| 67 |
$flags = array_diff( $flags, [ 'gzip' ] ); |
| 68 |
} |
| 69 |
return [ $text, $flags ]; |
| 70 |
} |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
$maintClass = FixLegacyEncoding::class; |
| 76 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 77 |
|