MediaWiki REL1_41
fixLegacyEncoding.php
Go to the documentation of this file.
1<?php
23
24require_once __DIR__ . '/moveToExternal.php';
25
27 public function __construct() {
28 parent::__construct();
29 $this->addDescription( 'Change encoding of stored content from legacy encoding to UTF-8' );
30 }
31
32 protected function getConditions( $blockStart, $blockEnd, $dbr ) {
33 return [
34 "old_id BETWEEN $blockStart AND $blockEnd",
35 'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'utf-8', $dbr->anyString() ),
36 'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'utf8', $dbr->anyString() ),
37 ];
38 }
39
40 protected function resolveText( $text, $flags ) {
41 if ( in_array( 'error', $flags ) ) {
42 return [ $text, $flags ];
43 }
44 $blobStore = $this->getServiceContainer()->getBlobStore();
45 if ( in_array( 'external', $flags ) && $blobStore instanceof SqlBlobStore ) {
46 $text = $blobStore->expandBlob( $text, $flags );
47 // It will be put back in external storage again
48 $flags = array_diff( $flags, [ 'external' ] );
49 }
50 if ( in_array( 'gzip', $flags ) ) {
51 $text = gzinflate( $text );
52 $flags = array_diff( $flags, [ 'gzip' ] );
53 }
54 return [ $text, $flags ];
55 }
56
57}
58
59$maintClass = FixLegacyEncoding::class;
60require_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.