63 'table' =>
'revision_comment_temp',
64 'pk' =>
'revcomment_rev',
65 'field' =>
'revcomment_comment_id',
68 'img_description' => [
69 'table' =>
'image_comment_temp',
70 'pk' =>
'imgcomment_name',
71 'field' =>
'imgcomment_description_id',
72 'joinPK' =>
'img_name',
105 $this->stage = $migrationStage;
131 return MediaWikiServices::getInstance()->getCommentStore();
140 private function getKey( $methodKey =
null ) {
141 $key = $this->
key !==
null ? $this->
key : $methodKey;
142 if (
$key ===
null ) {
144 throw new InvalidArgumentException(
'$key should not be null' );
170 $fields[
"{$key}_text"] =
$key;
171 $fields[
"{$key}_data"] =
'NULL';
172 $fields[
"{$key}_cid"] =
'NULL';
175 $fields[
"{$key}_old"] =
$key;
177 if ( isset( self::$tempTables[
$key] ) ) {
178 $fields[
"{$key}_pk"] = self::$tempTables[
$key][
'joinPK'];
180 $fields[
"{$key}_id"] =
"{$key}_id";
204 if ( !array_key_exists(
$key, $this->joinCache ) ) {
210 $fields[
"{$key}_text"] =
$key;
211 $fields[
"{$key}_data"] =
'NULL';
212 $fields[
"{$key}_cid"] =
'NULL';
214 $join = $this->stage ===
MIGRATION_NEW ?
'JOIN' :
'LEFT JOIN';
216 if ( isset( self::$tempTables[
$key] ) ) {
217 $t = self::$tempTables[
$key];
218 $alias =
"temp_$key";
220 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
221 $joinField =
"{$alias}.{$t['field']}";
223 $joinField =
"{$key}_id";
226 $alias =
"comment_$key";
228 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
231 $fields[
"{$key}_text"] =
"{$alias}.comment_text";
233 $fields[
"{$key}_text"] =
"COALESCE( {$alias}.comment_text, $key )";
235 $fields[
"{$key}_data"] =
"{$alias}.comment_data";
236 $fields[
"{$key}_cid"] =
"{$alias}.comment_id";
239 $this->joinCache[
$key] = [
246 return $this->joinCache[
$key];
263 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
264 $cid = isset( $row[
"{$key}_cid"] ) ? $row[
"{$key}_cid"] :
null;
265 $text = $row[
"{$key}_text"];
266 $data = $row[
"{$key}_data"];
270 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
273 wfLogWarning(
"Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD" );
278 if ( isset( self::$tempTables[
$key] ) ) {
279 if ( array_key_exists(
"{$key}_pk", $row ) ) {
281 throw new InvalidArgumentException(
282 "\$row does not contain fields needed for comment $key and getComment(), but "
283 .
"does have fields for getCommentLegacy()"
286 $t = self::$tempTables[
$key];
287 $id = $row[
"{$key}_pk"];
288 $row2 = $db->selectRow(
289 [
$t[
'table'],
'comment' ],
290 [
'comment_id',
'comment_text',
'comment_data' ],
294 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
297 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
298 $row2 = (
object)[
'comment_text' => $row[
$key],
'comment_data' =>
null ];
300 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
303 if ( array_key_exists(
"{$key}_id", $row ) ) {
305 throw new InvalidArgumentException(
306 "\$row does not contain fields needed for comment $key and getComment(), but "
307 .
"does have fields for getCommentLegacy()"
310 $id = $row[
"{$key}_id"];
311 $row2 = $db->selectRow(
313 [
'comment_id',
'comment_text',
'comment_data' ],
314 [
'comment_id' => $id ],
318 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
319 $row2 = (
object)[
'comment_text' => $row[
$key],
'comment_data' =>
null ];
321 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
326 $cid = $row2->comment_id;
327 $text = $row2->comment_text;
328 $data = $row2->comment_data;
329 } elseif ( $this->stage <
MIGRATION_NEW && array_key_exists(
"{$key}_old", $row ) ) {
331 $text = $row[
"{$key}_old"];
344 if ( $data !==
null ) {
346 if ( !is_object( $data ) ) {
348 wfLogWarning(
"Invalid JSON object in comment: $data" );
352 $data = (
array)$data;
353 if ( isset( $data[
'_message'] ) ) {
355 ->setInterfaceMessageFlag(
true );
357 if ( !empty( $data[
'_null'] ) ) {
360 foreach ( $data
as $k => $v ) {
361 if ( substr( $k, 0, 1 ) ===
'_' ) {
390 if ( $this->
key !==
null ) {
395 if ( $row ===
null ) {
397 throw new InvalidArgumentException(
'$row must not be null' );
424 if ( $this->
key !==
null ) {
429 if ( $row ===
null ) {
431 throw new InvalidArgumentException(
'$row must not be null' );
460 # Truncate comment in a Unicode-sensitive manner
461 $comment->text = $this->lang->truncate( $comment->text, self::MAX_COMMENT_LENGTH );
462 if ( mb_strlen( $comment->text,
'UTF-8' ) > self::COMMENT_CHARACTER_LIMIT ) {
463 $ellipsis =
wfMessage(
'ellipsis' )->inLanguage( $this->lang )->escaped();
464 if ( mb_strlen( $ellipsis ) >= self::COMMENT_CHARACTER_LIMIT ) {
468 $maxLength = self::COMMENT_CHARACTER_LIMIT - mb_strlen( $ellipsis,
'UTF-8' );
469 $comment->text = mb_substr( $comment->text, 0, $maxLength,
'UTF-8' ) . $ellipsis;
473 $dbData = $comment->data;
474 if ( !$comment->message instanceof
RawMessage ) {
475 if ( $dbData ===
null ) {
476 $dbData = [
'_null' =>
true ];
480 if ( $dbData !==
null ) {
482 $len = strlen( $dbData );
483 if ( $len > self::MAX_DATA_LENGTH ) {
485 throw new OverflowException(
"Comment data is too long ($len bytes, maximum is $max)" );
489 $hash =
self::hash( $comment->text, $dbData );
494 'comment_hash' => $hash,
495 'comment_text' => $comment->text,
496 'comment_data' => $dbData,
500 if ( !$comment->id ) {
504 'comment_hash' => $hash,
505 'comment_text' => $comment->text,
506 'comment_data' => $dbData,
533 $fields[
$key] = $this->lang->truncate( $comment->text, 255 );
537 if ( isset( self::$tempTables[
$key] ) ) {
538 $t = self::$tempTables[
$key];
540 $commentId = $comment->id;
541 $callback =
function ( $id )
use ( $dbw, $commentId,
$t, $func ) {
546 $t[
'field'] => $commentId,
552 $fields[
"{$key}_id"] = $comment->id;
556 return [ $fields, $callback ];
576 if ( $this->
key !==
null ) {
581 if ( $comment ===
null ) {
583 throw new InvalidArgumentException(
'$comment can not be null' );
587 if ( isset( self::$tempTables[
$key] ) ) {
588 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $key" );
618 if ( $this->
key !==
null ) {
623 if ( $comment ===
null ) {
625 throw new InvalidArgumentException(
'$comment can not be null' );
629 if ( isset( self::$formerTempTables[
$key] ) ) {
631 } elseif ( !isset( self::$tempTables[
$key] ) ) {
632 throw new InvalidArgumentException(
"Must use insert() for $key" );
637 $callback =
function () {
641 return [ $fields, $callback ];
653 if ( $param instanceof
Message ) {
669 $key = array_shift( $data );
670 foreach ( $data
as &$param ) {
671 if ( is_object( $param ) ) {
672 $param = (
array)$param;
674 if ( is_array( $param ) && count( $param ) === 1 && isset( $param[
'message'] ) ) {
687 public static function hash( $text, $data ) {
688 $hash = crc32( $text ) ^ crc32( (
string)$data );
692 if ( $hash >= 0x80000000 ) {