69 'table' =>
'revision_comment_temp',
70 'pk' =>
'revcomment_rev',
71 'field' =>
'revcomment_comment_id',
74 'deprecatedIn' =>
null,
76 'img_description' => [
78 'deprecatedIn' =>
'1.32',
91 private $joinCache = [];
105 throw new InvalidArgumentException(
'$stage must include a write mode' );
108 throw new InvalidArgumentException(
'$stage must include a read mode' );
111 $this->stage = $stage;
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;
154 $fields[
"{$key}_pk"] = static::TEMP_TABLES[$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 = static::TEMP_TABLES[$key][
'stage'] ??
MIGRATION_NEW;
195 $t = static::TEMP_TABLES[$key];
196 $alias =
"temp_$key";
198 $tables[$alias] =
$t[
'table'];
200 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
203 $joinField =
"{$alias}.{$t['field']}";
209 $joins[$alias][0] =
'LEFT JOIN';
211 $joinField =
"(CASE WHEN {$key}_id != 0 THEN {$key}_id ELSE {$alias}.{$t['field']} END)";
212 throw new LogicException(
'Nothing should reach this code path at this time' );
216 $joinField =
"{$key}_id";
219 $alias =
"comment_$key";
220 $tables[$alias] =
'comment';
221 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
224 $fields[
"{$key}_text"] =
"{$alias}.comment_text";
226 $fields[
"{$key}_text"] =
"COALESCE( {$alias}.comment_text, $key )";
228 $fields[
"{$key}_data"] =
"{$alias}.comment_data";
229 $fields[
"{$key}_cid"] =
"{$alias}.comment_id";
232 $this->joinCache[$key] = [
239 return $this->joinCache[$key];
254 private function getCommentInternal( ?
IDatabase $db, $key, $row,
$fallback =
false ) {
256 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
257 $cid = $row[
"{$key}_cid"] ??
null;
258 $text = $row[
"{$key}_text"];
259 $data = $row[
"{$key}_data"];
262 if (
$fallback && isset( $row[$key] ) ) {
263 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
267 "Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD / READ_OLD"
273 $tempTableStage = static::TEMP_TABLES[$key][
'stage'] ??
MIGRATION_NEW;
277 throw new InvalidArgumentException(
278 "\$row does not contain fields needed for comment $key and getComment(), but "
279 .
"does have fields for getCommentLegacy()"
282 $id = $row[
"{$key}_id"];
285 [
'comment_id',
'comment_text',
'comment_data' ],
286 [
'comment_id' => $id ],
291 array_key_exists(
"{$key}_pk", $row )
294 throw new InvalidArgumentException(
295 "\$row does not contain fields needed for comment $key and getComment(), but "
296 .
"does have fields for getCommentLegacy()"
299 $t = static::TEMP_TABLES[$key];
300 $id = $row[
"{$key}_pk"];
303 [
$t[
'table'],
'comment' ],
304 [
'comment_id',
'comment_text',
'comment_data' ],
310 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
313 if ( $row2 ===
null &&
$fallback && isset( $row[$key] ) ) {
314 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
315 $row2 = (object)[
'comment_text' => $row[$key],
'comment_data' =>
null ];
317 if ( $row2 ===
null ) {
318 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
322 $cid = $row2->comment_id;
323 $text = $row2->comment_text;
324 $data = $row2->comment_data;
326 array_key_exists(
"{$key}_old", $row )
329 $text = $row[
"{$key}_old"];
343 if ( $data !==
null ) {
345 if ( !is_array( $data ) ) {
347 wfLogWarning(
"Invalid JSON object in comment: $data" );
351 if ( isset( $data[
'_message'] ) ) {
352 $msg = self::decodeMessage( $data[
'_message'] )
355 if ( !empty( $data[
'_null'] ) ) {
358 foreach ( $data as $k => $v ) {
359 if ( substr( $k, 0, 1 ) ===
'_' ) {
387 if ( $row ===
null ) {
389 throw new InvalidArgumentException(
'$row must not be null' );
392 return $this->getCommentInternal(
null, $key, $row,
$fallback );
415 if ( $row ===
null ) {
417 throw new InvalidArgumentException(
'$row must not be null' );
420 return $this->getCommentInternal( $db, $key, $row,
$fallback );
444 $comment = CommentStoreComment::newUnsavedComment( $comment, $data );
446 # Truncate comment in a Unicode-sensitive manner
447 $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT );
450 $dbData = $comment->data;
451 if ( !$comment->message instanceof
RawMessage ) {
452 if ( $dbData ===
null ) {
453 $dbData = [
'_null' =>
true ];
455 $dbData[
'_message'] = self::encodeMessage( $comment->message );
457 if ( $dbData !==
null ) {
458 $dbData = FormatJson::encode( (
object)$dbData,
false, FormatJson::ALL_OK );
459 $len = strlen( $dbData );
460 if ( $len > self::MAX_DATA_LENGTH ) {
461 $max = self::MAX_DATA_LENGTH;
462 throw new OverflowException(
"Comment data is too long ($len bytes, maximum is $max)" );
466 $hash = self::hash( $comment->text, $dbData );
471 'comment_hash' => $hash,
472 'comment_text' => $comment->text,
473 'comment_data' => $dbData,
481 'comment_hash' => $hash,
482 'comment_text' => $comment->text,
483 'comment_data' => $dbData,
489 $comment->id = (int)$commentId;
504 private function insertInternal(
IDatabase $dbw, $key, $comment, $data ) {
508 $comment = $this->createComment( $dbw, $comment, $data );
511 $fields[$key] = $this->lang->truncateForDatabase( $comment->text, 255 );
515 $tempTableStage = static::TEMP_TABLES[$key][
'stage'] ??
MIGRATION_NEW;
517 $t = static::TEMP_TABLES[$key];
519 $commentId = $comment->id;
520 $callback =
static function ( $id ) use ( $dbw, $commentId,
$t, $func ) {
528 $t[
'field'] => $commentId,
535 $fields[
"{$key}_id"] = $comment->id;
539 return [ $fields, $callback ];
558 if ( $comment ===
null ) {
560 throw new InvalidArgumentException(
'$comment can not be null' );
564 $tempTableStage = static::TEMP_TABLES[$key][
'stage'] ??
MIGRATION_NEW;
566 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $key" );
569 list( $fields ) = $this->insertInternal( $dbw, $key, $comment, $data );
595 if ( $comment ===
null ) {
597 throw new InvalidArgumentException(
'$comment can not be null' );
601 if ( !isset( static::TEMP_TABLES[$key] ) ) {
602 throw new InvalidArgumentException(
"Must use insert() for $key" );
603 } elseif ( isset( static::TEMP_TABLES[$key][
'deprecatedIn'] ) ) {
604 wfDeprecated( __METHOD__ .
" for $key", static::TEMP_TABLES[$key][
'deprecatedIn'] );
607 list( $fields, $callback ) = $this->insertInternal( $dbw, $key, $comment, $data );
609 $callback =
static function () {
613 return [ $fields, $callback ];
621 private static function encodeMessage(
Message $msg ) {
624 foreach ( $params as &$param ) {
625 if ( $param instanceof
Message ) {
627 'message' => self::encodeMessage( $param )
631 array_unshift( $params, $key );
640 private static function decodeMessage( $data ) {
641 $key = array_shift( $data );
642 foreach ( $data as &$param ) {
643 if ( is_object( $param ) ) {
644 $param = (array)$param;
646 if ( is_array( $param ) && count( $param ) === 1 && isset( $param[
'message'] ) ) {
647 $param = self::decodeMessage( $param[
'message'] );
650 return new Message( $key, $data );
659 public static function hash( $text, $data ) {
660 $hash = crc32( $text ) ^ crc32( (
string)$data );
664 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.
Base class for language-specific code.
The Message class deals with fetching and processing of interface message into a variety of formats.
getParams()
Returns the message parameters.
setInterfaceMessageFlag( $interface)
Allows manipulating the interface message flag directly.
getKey()
Returns the message key.
Variant of the Message class.
if(!isset( $args[0])) $lang