MediaWiki master
fixLegacyEncoding.php
Go to the documentation of this file.
1<?php
25
26require_once __DIR__ . '/moveToExternal.php';
27
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;
73require_once RUN_MAINTENANCE_IF_MAIN;
__construct()
Default constructor.
resolveText( $text, $flags)
getConditions( $blockStart, $blockEnd, $dbr)
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
Service for storing and loading Content objects representing revision data blobs.
Content of like value.
Definition LikeValue.php:14