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 = static::TEMP_TABLES[$key][
'stage'] ??
MIGRATION_NEW;
153 $fields[
"{$key}_pk"] = static::TEMP_TABLES[$key][
'joinPK'];
156 $fields[
"{$key}_id"] =
"{$key}_id";
180 if ( !array_key_exists( $key, $this->joinCache ) ) {
186 $fields[
"{$key}_text"] = $key;
187 $fields[
"{$key}_data"] =
'NULL';
188 $fields[
"{$key}_cid"] =
'NULL';
192 $tempTableStage = static::TEMP_TABLES[$key][
'stage'] ??
MIGRATION_NEW;
194 $t = static::TEMP_TABLES[$key];
195 $alias =
"temp_$key";
196 $tables[$alias] =
$t[
'table'];
197 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
199 $joinField =
"{$alias}.{$t['field']}";
205 $joins[$alias][0] =
'LEFT JOIN';
206 $joinField =
"(CASE WHEN {$key}_id != 0 THEN {$key}_id ELSE {$alias}.{$t['field']} END)";
207 throw new LogicException(
'Nothing should reach this code path at this time' );
211 $joinField =
"{$key}_id";
214 $alias =
"comment_$key";
215 $tables[$alias] =
'comment';
216 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
219 $fields[
"{$key}_text"] =
"{$alias}.comment_text";
221 $fields[
"{$key}_text"] =
"COALESCE( {$alias}.comment_text, $key )";
223 $fields[
"{$key}_data"] =
"{$alias}.comment_data";
224 $fields[
"{$key}_cid"] =
"{$alias}.comment_id";
227 $this->joinCache[$key] = [
234 return $this->joinCache[$key];
251 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
252 $cid = $row[
"{$key}_cid"] ??
null;
253 $text = $row[
"{$key}_text"];
254 $data = $row[
"{$key}_data"];
257 if (
$fallback && isset( $row[$key] ) ) {
258 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
262 "Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD / READ_OLD"
268 $tempTableStage = static::TEMP_TABLES[$key][
'stage'] ??
MIGRATION_NEW;
272 throw new InvalidArgumentException(
273 "\$row does not contain fields needed for comment $key and getComment(), but "
274 .
"does have fields for getCommentLegacy()"
277 $id = $row[
"{$key}_id"];
280 [
'comment_id',
'comment_text',
'comment_data' ],
281 [
'comment_id' => $id ],
286 array_key_exists(
"{$key}_pk", $row )
289 throw new InvalidArgumentException(
290 "\$row does not contain fields needed for comment $key and getComment(), but "
291 .
"does have fields for getCommentLegacy()"
294 $t = static::TEMP_TABLES[$key];
295 $id = $row[
"{$key}_pk"];
297 [
$t[
'table'],
'comment' ],
298 [
'comment_id',
'comment_text',
'comment_data' ],
302 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
305 if ( $row2 ===
null &&
$fallback && isset( $row[$key] ) ) {
306 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
307 $row2 = (object)[
'comment_text' => $row[$key],
'comment_data' =>
null ];
309 if ( $row2 ===
null ) {
310 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
314 $cid = $row2->comment_id;
315 $text = $row2->comment_text;
316 $data = $row2->comment_data;
318 array_key_exists(
"{$key}_old", $row )
321 $text = $row[
"{$key}_old"];
334 if ( $data !==
null ) {
335 $data = FormatJson::decode( $data,
true );
336 if ( !is_array( $data ) ) {
338 wfLogWarning(
"Invalid JSON object in comment: $data" );
342 if ( isset( $data[
'_message'] ) ) {
343 $msg = self::decodeMessage( $data[
'_message'] )
344 ->setInterfaceMessageFlag(
true );
346 if ( !empty( $data[
'_null'] ) ) {
349 foreach ( $data as $k => $v ) {
350 if ( substr( $k, 0, 1 ) ===
'_' ) {
378 if ( $row ===
null ) {
380 throw new InvalidArgumentException(
'$row must not be null' );
406 if ( $row ===
null ) {
408 throw new InvalidArgumentException(
'$row must not be null' );
435 $comment = CommentStoreComment::newUnsavedComment( $comment, $data );
437 # Truncate comment in a Unicode-sensitive manner
438 $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT );
441 $dbData = $comment->data;
442 if ( !$comment->message instanceof
RawMessage ) {
443 if ( $dbData ===
null ) {
444 $dbData = [
'_null' =>
true ];
446 $dbData[
'_message'] = self::encodeMessage( $comment->message );
448 if ( $dbData !==
null ) {
449 $dbData = FormatJson::encode( (
object)$dbData,
false, FormatJson::ALL_OK );
450 $len = strlen( $dbData );
451 if ( $len > self::MAX_DATA_LENGTH ) {
452 $max = self::MAX_DATA_LENGTH;
453 throw new OverflowException(
"Comment data is too long ($len bytes, maximum is $max)" );
457 $hash = self::hash( $comment->text, $dbData );
462 'comment_hash' => $hash,
463 'comment_text' => $comment->text,
464 'comment_data' => $dbData,
472 'comment_hash' => $hash,
473 'comment_text' => $comment->text,
474 'comment_data' => $dbData,
480 $comment->id = (int)$commentId;
502 $fields[$key] = $this->lang->truncateForDatabase( $comment->text, 255 );
506 $tempTableStage = static::TEMP_TABLES[$key][
'stage'] ??
MIGRATION_NEW;
508 $t = static::TEMP_TABLES[$key];
510 $commentId = $comment->id;
511 $callback =
static function ( $id ) use ( $dbw, $commentId,
$t, $func ) {
516 $t[
'field'] => $commentId,
523 $fields[
"{$key}_id"] = $comment->id;
527 return [ $fields, $callback ];
546 if ( $comment ===
null ) {
548 throw new InvalidArgumentException(
'$comment can not be null' );
552 $tempTableStage = static::TEMP_TABLES[$key][
'stage'] ??
MIGRATION_NEW;
554 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $key" );
557 list( $fields ) = $this->
insertInternal( $dbw, $key, $comment, $data );
583 if ( $comment ===
null ) {
585 throw new InvalidArgumentException(
'$comment can not be null' );
589 if ( !isset( static::TEMP_TABLES[$key] ) ) {
590 throw new InvalidArgumentException(
"Must use insert() for $key" );
591 } elseif ( isset( static::TEMP_TABLES[$key][
'deprecatedIn'] ) ) {
592 wfDeprecated( __METHOD__ .
" for $key", static::TEMP_TABLES[$key][
'deprecatedIn'] );
595 list( $fields, $callback ) = $this->
insertInternal( $dbw, $key, $comment, $data );
597 $callback =
static function () {
601 return [ $fields, $callback ];
612 foreach ( $params as &$param ) {
613 if ( $param instanceof
Message ) {
615 'message' => self::encodeMessage( $param )
619 array_unshift( $params, $key );
629 $key = array_shift( $data );
630 foreach ( $data as &$param ) {
631 if ( is_object( $param ) ) {
632 $param = (array)$param;
634 if ( is_array( $param ) && count( $param ) === 1 && isset( $param[
'message'] ) ) {
635 $param = self::decodeMessage( $param[
'message'] );
638 return new Message( $key, $data );
647 public static function hash( $text, $data ) {
648 $hash = crc32( $text ) ^ crc32( (
string)$data );
652 if ( $hash >= 0x80000000 ) {
const SCHEMA_COMPAT_WRITE_BOTH
const SCHEMA_COMPAT_READ_NEW
const SCHEMA_COMPAT_READ_BOTH
const SCHEMA_COMPAT_WRITE_OLD
const SCHEMA_COMPAT_READ_OLD
const SCHEMA_COMPAT_WRITE_NEW
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Internationalisation code See https://www.mediawiki.org/wiki/Special:MyLanguage/Localisation for more...
The Message class deals with fetching and processing of interface message into a variety of formats.
getParams()
Returns the message parameters.
getKey()
Returns the message key.
Variant of the Message class.
if(!isset( $args[0])) $lang