MediaWiki master
fixLegacyEncoding.php
Go to the documentation of this file.
1<?php
25
26// @codeCoverageIgnoreStart
27require_once __DIR__ . '/moveToExternal.php';
28// @codeCoverageIgnoreEnd
29
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 // It will be put back in external storage again
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// @codeCoverageIgnoreStart
75$maintClass = FixLegacyEncoding::class;
76require_once RUN_MAINTENANCE_IF_MAIN;
77// @codeCoverageIgnoreEnd
resolveText( $text, $flags)
getConditions( $blockStart, $blockEnd, $dbr)
Service for storing and loading Content objects representing revision data blobs.
Content of like value.
Definition LikeValue.php:14