65 'table' =>
'revision_comment_temp',
66 'pk' =>
'revcomment_rev',
67 'field' =>
'revcomment_comment_id',
70 'deprecatedIn' =>
null,
72 'img_description' => [
74 'deprecatedIn' =>
'1.32',
108 throw new InvalidArgumentException(
'$stage must include a write mode' );
111 throw new InvalidArgumentException(
'$stage must include a read mode' );
128 MediaWikiServices::getInstance()->getContentLanguage(),
MIGRATION_NEW
140 return MediaWikiServices::getInstance()->getCommentStore();
149 private function getKey( $methodKey =
null ) {
150 $key = $this->key ?? $methodKey;
151 if (
$key ===
null ) {
153 throw new InvalidArgumentException(
'$key should not be null' );
179 $fields[
"{$key}_text"] =
$key;
180 $fields[
"{$key}_data"] =
'NULL';
181 $fields[
"{$key}_cid"] =
'NULL';
184 $fields[
"{$key}_old"] =
$key;
187 $tempTableStage = isset( $this->tempTables[
$key] )
190 $fields[
"{$key}_pk"] = $this->tempTables[
$key][
'joinPK'];
193 $fields[
"{$key}_id"] =
"{$key}_id";
218 if ( !array_key_exists(
$key, $this->joinCache ) ) {
224 $fields[
"{$key}_text"] =
$key;
225 $fields[
"{$key}_data"] =
'NULL';
226 $fields[
"{$key}_cid"] =
'NULL';
230 $tempTableStage = isset( $this->tempTables[
$key] )
233 $t = $this->tempTables[
$key];
234 $alias =
"temp_$key";
235 $tables[$alias] =
$t[
'table'];
236 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
238 $joinField =
"{$alias}.{$t['field']}";
244 $joins[$alias][0] =
'LEFT JOIN';
245 $joinField =
"(CASE WHEN {$key}_id != 0 THEN {$key}_id ELSE {$alias}.{$t['field']} END)";
246 throw new LogicException(
'Nothing should reach this code path at this time' );
250 $joinField =
"{$key}_id";
253 $alias =
"comment_$key";
254 $tables[$alias] =
'comment';
255 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
258 $fields[
"{$key}_text"] =
"{$alias}.comment_text";
260 $fields[
"{$key}_text"] =
"COALESCE( {$alias}.comment_text, $key )";
262 $fields[
"{$key}_data"] =
"{$alias}.comment_data";
263 $fields[
"{$key}_cid"] =
"{$alias}.comment_id";
266 $this->joinCache[
$key] = [
273 return $this->joinCache[
$key];
290 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
291 $cid = $row[
"{$key}_cid"] ??
null;
292 $text = $row[
"{$key}_text"];
293 $data = $row[
"{$key}_data"];
297 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
301 "Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD / READ_OLD"
307 $tempTableStage = isset( $this->tempTables[
$key] )
312 throw new InvalidArgumentException(
313 "\$row does not contain fields needed for comment $key and getComment(), but "
314 .
"does have fields for getCommentLegacy()"
317 $id = $row[
"{$key}_id"];
318 $row2 = $db->selectRow(
320 [
'comment_id',
'comment_text',
'comment_data' ],
321 [
'comment_id' => $id ],
326 array_key_exists(
"{$key}_pk", $row )
329 throw new InvalidArgumentException(
330 "\$row does not contain fields needed for comment $key and getComment(), but "
331 .
"does have fields for getCommentLegacy()"
334 $t = $this->tempTables[
$key];
335 $id = $row[
"{$key}_pk"];
336 $row2 = $db->selectRow(
337 [
$t[
'table'],
'comment' ],
338 [
'comment_id',
'comment_text',
'comment_data' ],
342 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
346 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
347 $row2 = (object)[
'comment_text' => $row[
$key],
'comment_data' =>
null ];
349 if ( $row2 ===
null ) {
350 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
354 $cid = $row2->comment_id;
355 $text = $row2->comment_text;
356 $data = $row2->comment_data;
358 array_key_exists(
"{$key}_old", $row )
361 $text = $row[
"{$key}_old"];
374 if ( $data !==
null ) {
376 if ( !is_array( $data ) ) {
378 wfLogWarning(
"Invalid JSON object in comment: $data" );
382 if ( isset( $data[
'_message'] ) ) {
384 ->setInterfaceMessageFlag(
true );
386 if ( !empty( $data[
'_null'] ) ) {
389 foreach ( $data as $k => $v ) {
390 if ( substr( $k, 0, 1 ) ===
'_' ) {
419 if ( $this->key !==
null ) {
424 if ( $row ===
null ) {
426 throw new InvalidArgumentException(
'$row must not be null' );
453 if ( $this->key !==
null ) {
458 if ( $row ===
null ) {
460 throw new InvalidArgumentException(
'$row must not be null' );
489 # Truncate comment in a Unicode-sensitive manner
490 $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT );
493 $dbData = $comment->data;
494 if ( !$comment->message instanceof
RawMessage ) {
495 if ( $dbData ===
null ) {
496 $dbData = [
'_null' =>
true ];
500 if ( $dbData !==
null ) {
502 $len = strlen( $dbData );
503 if ( $len > self::MAX_DATA_LENGTH ) {
505 throw new OverflowException(
"Comment data is too long ($len bytes, maximum is $max)" );
509 $hash =
self::hash( $comment->text, $dbData );
514 'comment_hash' => $hash,
515 'comment_text' => $comment->text,
516 'comment_data' => $dbData,
520 if ( !$comment->id ) {
524 'comment_hash' => $hash,
525 'comment_text' => $comment->text,
526 'comment_data' => $dbData,
553 $fields[
$key] = $this->lang->truncateForDatabase( $comment->text, 255 );
557 $tempTableStage = isset( $this->tempTables[
$key] )
560 $t = $this->tempTables[
$key];
562 $commentId = $comment->id;
563 $callback =
function ( $id ) use ( $dbw, $commentId,
$t, $func ) {
568 $t[
'field'] => $commentId,
575 $fields[
"{$key}_id"] = $comment->id;
579 return [ $fields, $callback ];
599 if ( $this->key !==
null ) {
604 if ( $comment ===
null ) {
606 throw new InvalidArgumentException(
'$comment can not be null' );
610 $tempTableStage = isset( $this->tempTables[
$key] )
613 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $key" );
643 if ( $this->key !==
null ) {
648 if ( $comment ===
null ) {
650 throw new InvalidArgumentException(
'$comment can not be null' );
654 if ( !isset( $this->tempTables[
$key] ) ) {
655 throw new InvalidArgumentException(
"Must use insert() for $key" );
656 } elseif ( isset( $this->tempTables[
$key][
'deprecatedIn'] ) ) {
657 wfDeprecated( __METHOD__ .
" for $key", $this->tempTables[
$key][
'deprecatedIn'] );
662 $callback =
function () {
666 return [ $fields, $callback ];
675 $key = count( $msg->getKeysToTry() ) > 1 ? $msg->getKeysToTry() : $msg->getKey();
676 $params = $msg->getParams();
677 foreach ( $params as &$param ) {
678 if ( $param instanceof
Message ) {
684 array_unshift( $params,
$key );
694 $key = array_shift( $data );
695 foreach ( $data as &$param ) {
696 if ( is_object( $param ) ) {
697 $param = (array)$param;
699 if ( is_array( $param ) && count( $param ) === 1 && isset( $param[
'message'] ) ) {
712 public static function hash( $text, $data ) {
713 $hash = crc32( $text ) ^ crc32( (
string)$data );
717 if ( $hash >= 0x80000000 ) {