62 'table' =>
'revision_comment_temp',
63 'pk' =>
'revcomment_rev',
64 'field' =>
'revcomment_comment_id',
67 'img_description' => [
68 'table' =>
'image_comment_temp',
69 'pk' =>
'imgcomment_name',
70 'field' =>
'imgcomment_description_id',
71 'joinPK' =>
'img_name',
133 $fields[
"{$this->key}_data"] =
'NULL';
134 $fields[
"{$this->key}_cid"] =
'NULL';
139 if ( isset( self::$tempTables[$this->
key] ) ) {
140 $fields[
"{$this->key}_pk"] = self::$tempTables[
$this->key][
'joinPK'];
142 $fields[
"{$this->key}_id"] =
"{$this->key}_id";
161 if ( $this->joinCache ===
null ) {
168 $fields[
"{$this->key}_data"] =
'NULL';
169 $fields[
"{$this->key}_cid"] =
'NULL';
171 $join = $this->stage ===
MIGRATION_NEW ?
'JOIN' :
'LEFT JOIN';
173 if ( isset( self::$tempTables[$this->
key] ) ) {
175 $alias =
"temp_$this->key";
177 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
178 $joinField =
"{$alias}.{$t['field']}";
180 $joinField =
"{$this->key}_id";
183 $alias =
"comment_$this->key";
185 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
188 $fields[
"{$this->key}_text"] =
"{$alias}.comment_text";
190 $fields[
"{$this->key}_text"] =
"COALESCE( {$alias}.comment_text, $this->key )";
192 $fields[
"{$this->key}_data"] =
"{$alias}.comment_data";
193 $fields[
"{$this->key}_cid"] =
"{$alias}.comment_id";
219 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
220 $cid = isset( $row[
"{$key}_cid"] ) ? $row[
"{$key}_cid"] :
null;
221 $text = $row[
"{$key}_text"];
222 $data = $row[
"{$key}_data"];
226 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
229 wfLogWarning(
"Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD" );
234 if ( isset( self::$tempTables[
$key] ) ) {
235 if ( array_key_exists(
"{$key}_pk", $row ) ) {
237 throw new InvalidArgumentException(
238 "\$row does not contain fields needed for comment $key and getComment(), but "
239 .
"does have fields for getCommentLegacy()"
242 $t = self::$tempTables[
$key];
243 $id = $row[
"{$key}_pk"];
244 $row2 = $db->selectRow(
245 [
$t[
'table'],
'comment' ],
246 [
'comment_id',
'comment_text',
'comment_data' ],
250 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
253 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
254 $row2 = (
object)[
'comment_text' => $row[
$key],
'comment_data' =>
null ];
256 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
259 if ( array_key_exists(
"{$key}_id", $row ) ) {
261 throw new InvalidArgumentException(
262 "\$row does not contain fields needed for comment $key and getComment(), but "
263 .
"does have fields for getCommentLegacy()"
266 $id = $row[
"{$key}_id"];
267 $row2 = $db->selectRow(
269 [
'comment_id',
'comment_text',
'comment_data' ],
270 [
'comment_id' => $id ],
274 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
275 $row2 = (
object)[
'comment_text' => $row[
$key],
'comment_data' =>
null ];
277 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
282 $cid = $row2->comment_id;
283 $text = $row2->comment_text;
284 $data = $row2->comment_data;
285 } elseif ( $this->stage <
MIGRATION_NEW && array_key_exists(
"{$key}_old", $row ) ) {
287 $text = $row[
"{$key}_old"];
300 if ( $data !==
null ) {
302 if ( !is_object( $data ) ) {
304 wfLogWarning(
"Invalid JSON object in comment: $data" );
308 $data = (
array)$data;
309 if ( isset( $data[
'_message'] ) ) {
311 ->setInterfaceMessageFlag(
true );
313 if ( !empty( $data[
'_null'] ) ) {
316 foreach ( $data
as $k => $v ) {
317 if ( substr( $k, 0, 1 ) ===
'_' ) {
386 # Truncate comment in a Unicode-sensitive manner
387 $comment->text = $this->lang->truncate( $comment->text, self::MAX_COMMENT_LENGTH );
388 if ( mb_strlen( $comment->text,
'UTF-8' ) > self::COMMENT_CHARACTER_LIMIT ) {
389 $ellipsis =
wfMessage(
'ellipsis' )->inLanguage( $this->lang )->escaped();
390 if ( mb_strlen( $ellipsis ) >= self::COMMENT_CHARACTER_LIMIT ) {
394 $maxLength = self::COMMENT_CHARACTER_LIMIT - mb_strlen( $ellipsis,
'UTF-8' );
395 $comment->text = mb_substr( $comment->text, 0, $maxLength,
'UTF-8' ) . $ellipsis;
399 $dbData = $comment->data;
400 if ( !$comment->message instanceof
RawMessage ) {
401 if ( $dbData ===
null ) {
402 $dbData = [
'_null' =>
true ];
406 if ( $dbData !==
null ) {
408 $len = strlen( $dbData );
409 if ( $len > self::MAX_DATA_LENGTH ) {
411 throw new OverflowException(
"Comment data is too long ($len bytes, maximum is $max)" );
415 $hash =
self::hash( $comment->text, $dbData );
420 'comment_hash' => $hash,
421 'comment_text' => $comment->text,
422 'comment_data' => $dbData,
426 if ( !$comment->id ) {
430 'comment_hash' => $hash,
431 'comment_text' => $comment->text,
432 'comment_data' => $dbData,
457 $fields[
$this->key] = $this->lang->truncate( $comment->text, 255 );
461 if ( isset( self::$tempTables[$this->
key] ) ) {
464 $commentId = $comment->id;
465 $callback =
function ( $id )
use ( $dbw, $commentId,
$t, $func ) {
470 $t[
'field'] => $commentId,
476 $fields[
"{$this->key}_id"] = $comment->id;
480 return [ $fields, $callback ];
494 if ( isset( self::$tempTables[$this->
key] ) ) {
495 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $this->key" );
519 if ( isset( self::$formerTempTables[$this->
key] ) ) {
520 wfDeprecated( __METHOD__ .
" for $this->key", self::$formerTempTables[$this->key] );
521 } elseif ( !isset( self::$tempTables[$this->key] ) ) {
522 throw new InvalidArgumentException(
"Must use insert() for $this->key" );
527 $callback =
function () {
531 return [ $fields, $callback ];
540 $key =
count( $msg->getKeysToTry() ) > 1 ? $msg->getKeysToTry() : $msg->getKey();
543 if ( $param instanceof Message ) {
559 $key = array_shift( $data );
560 foreach ( $data
as &$param ) {
561 if ( is_object( $param ) ) {
562 $param = (
array)$param;
564 if ( is_array( $param ) &&
count( $param ) === 1 && isset( $param[
'message'] ) ) {
568 return new Message(
$key, $data );
577 public static function hash( $text, $data ) {
578 $hash = crc32( $text ) ^ crc32( (
string)$data );
582 if ( $hash >= 0x80000000 ) {