69 'table' =>
'revision_comment_temp',
70 'pk' =>
'revcomment_rev',
71 'field' =>
'revcomment_comment_id',
74 'deprecatedIn' =>
null,
76 'img_description' => [
78 'deprecatedIn' =>
'1.32',
105 throw new InvalidArgumentException(
'$stage must include a write mode' );
108 throw new InvalidArgumentException(
'$stage must include a read mode' );
121 return MediaWikiServices::getInstance()->getCommentStore();
143 $fields[
"{$key}_text"] = $key;
144 $fields[
"{$key}_data"] =
'NULL';
145 $fields[
"{$key}_cid"] =
'NULL';
148 $fields[
"{$key}_old"] = $key;
151 $tempTableStage = isset( $this->tempTables[$key] )
154 $fields[
"{$key}_pk"] = $this->tempTables[$key][
'joinPK'];
157 $fields[
"{$key}_id"] =
"{$key}_id";
181 if ( !array_key_exists( $key, $this->joinCache ) ) {
187 $fields[
"{$key}_text"] = $key;
188 $fields[
"{$key}_data"] =
'NULL';
189 $fields[
"{$key}_cid"] =
'NULL';
193 $tempTableStage = isset( $this->tempTables[$key] )
196 $t = $this->tempTables[$key];
197 $alias =
"temp_$key";
198 $tables[$alias] =
$t[
'table'];
199 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
201 $joinField =
"{$alias}.{$t['field']}";
207 $joins[$alias][0] =
'LEFT JOIN';
208 $joinField =
"(CASE WHEN {$key}_id != 0 THEN {$key}_id ELSE {$alias}.{$t['field']} END)";
209 throw new LogicException(
'Nothing should reach this code path at this time' );
213 $joinField =
"{$key}_id";
216 $alias =
"comment_$key";
217 $tables[$alias] =
'comment';
218 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
221 $fields[
"{$key}_text"] =
"{$alias}.comment_text";
223 $fields[
"{$key}_text"] =
"COALESCE( {$alias}.comment_text, $key )";
225 $fields[
"{$key}_data"] =
"{$alias}.comment_data";
226 $fields[
"{$key}_cid"] =
"{$alias}.comment_id";
229 $this->joinCache[$key] = [
236 return $this->joinCache[$key];
253 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
254 $cid = $row[
"{$key}_cid"] ??
null;
255 $text = $row[
"{$key}_text"];
256 $data = $row[
"{$key}_data"];
259 if (
$fallback && isset( $row[$key] ) ) {
260 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
264 "Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD / READ_OLD"
270 $tempTableStage = isset( $this->tempTables[$key] )
275 throw new InvalidArgumentException(
276 "\$row does not contain fields needed for comment $key and getComment(), but "
277 .
"does have fields for getCommentLegacy()"
280 $id = $row[
"{$key}_id"];
283 [
'comment_id',
'comment_text',
'comment_data' ],
284 [
'comment_id' => $id ],
289 array_key_exists(
"{$key}_pk", $row )
292 throw new InvalidArgumentException(
293 "\$row does not contain fields needed for comment $key and getComment(), but "
294 .
"does have fields for getCommentLegacy()"
297 $t = $this->tempTables[$key];
298 $id = $row[
"{$key}_pk"];
300 [
$t[
'table'],
'comment' ],
301 [
'comment_id',
'comment_text',
'comment_data' ],
305 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
308 if ( $row2 ===
null &&
$fallback && isset( $row[$key] ) ) {
309 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
310 $row2 = (object)[
'comment_text' => $row[$key],
'comment_data' =>
null ];
312 if ( $row2 ===
null ) {
313 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
317 $cid = $row2->comment_id;
318 $text = $row2->comment_text;
319 $data = $row2->comment_data;
321 array_key_exists(
"{$key}_old", $row )
324 $text = $row[
"{$key}_old"];
337 if ( $data !==
null ) {
339 if ( !is_array( $data ) ) {
341 wfLogWarning(
"Invalid JSON object in comment: $data" );
345 if ( isset( $data[
'_message'] ) ) {
347 ->setInterfaceMessageFlag(
true );
349 if ( !empty( $data[
'_null'] ) ) {
352 foreach ( $data as $k => $v ) {
353 if ( substr( $k, 0, 1 ) ===
'_' ) {
381 if ( $row ===
null ) {
383 throw new InvalidArgumentException(
'$row must not be null' );
409 if ( $row ===
null ) {
411 throw new InvalidArgumentException(
'$row must not be null' );
440 # Truncate comment in a Unicode-sensitive manner
441 $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT );
444 $dbData = $comment->data;
445 if ( !$comment->message instanceof
RawMessage ) {
446 if ( $dbData ===
null ) {
447 $dbData = [
'_null' =>
true ];
451 if ( $dbData !==
null ) {
453 $len = strlen( $dbData );
454 if ( $len > self::MAX_DATA_LENGTH ) {
456 throw new OverflowException(
"Comment data is too long ($len bytes, maximum is $max)" );
460 $hash =
self::hash( $comment->text, $dbData );
465 'comment_hash' => $hash,
466 'comment_text' => $comment->text,
467 'comment_data' => $dbData,
471 if ( !$comment->id ) {
475 'comment_hash' => $hash,
476 'comment_text' => $comment->text,
477 'comment_data' => $dbData,
504 $fields[$key] = $this->lang->truncateForDatabase( $comment->text, 255 );
508 $tempTableStage = isset( $this->tempTables[$key] )
511 $t = $this->tempTables[$key];
513 $commentId = $comment->id;
514 $callback =
function ( $id ) use ( $dbw, $commentId,
$t, $func ) {
519 $t[
'field'] => $commentId,
526 $fields[
"{$key}_id"] = $comment->id;
530 return [ $fields, $callback ];
549 if ( $comment ===
null ) {
551 throw new InvalidArgumentException(
'$comment can not be null' );
555 $tempTableStage = isset( $this->tempTables[$key] )
558 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $key" );
561 list( $fields ) = $this->
insertInternal( $dbw, $key, $comment, $data );
587 if ( $comment ===
null ) {
589 throw new InvalidArgumentException(
'$comment can not be null' );
593 if ( !isset( $this->tempTables[$key] ) ) {
594 throw new InvalidArgumentException(
"Must use insert() for $key" );
595 } elseif ( isset( $this->tempTables[$key][
'deprecatedIn'] ) ) {
596 wfDeprecated( __METHOD__ .
" for $key", $this->tempTables[$key][
'deprecatedIn'] );
599 list( $fields, $callback ) = $this->
insertInternal( $dbw, $key, $comment, $data );
601 $callback =
function () {
605 return [ $fields, $callback ];
616 foreach ( $params as &$param ) {
617 if ( $param instanceof
Message ) {
623 array_unshift( $params, $key );
633 $key = array_shift( $data );
634 foreach ( $data as &$param ) {
635 if ( is_object( $param ) ) {
636 $param = (array)$param;
638 if ( is_array( $param ) && count( $param ) === 1 && isset( $param[
'message'] ) ) {
642 return new Message( $key, $data );
651 public static function hash( $text, $data ) {
652 $hash = crc32( $text ) ^ crc32( (
string)$data );
656 if ( $hash >= 0x80000000 ) {