58 'table' =>
'revision_comment_temp',
59 'pk' =>
'revcomment_rev',
60 'field' =>
'revcomment_comment_id',
63 'deprecatedIn' =>
null,
65 'img_description' => [
67 'deprecatedIn' =>
'1.32',
94 throw new InvalidArgumentException(
'$stage must include a write mode' );
97 throw new InvalidArgumentException(
'$stage must include a read mode' );
110 return MediaWikiServices::getInstance()->getCommentStore();
132 $fields[
"{$key}_text"] = $key;
133 $fields[
"{$key}_data"] =
'NULL';
134 $fields[
"{$key}_cid"] =
'NULL';
137 $fields[
"{$key}_old"] = $key;
140 $tempTableStage = isset( $this->tempTables[$key] )
143 $fields[
"{$key}_pk"] = $this->tempTables[$key][
'joinPK'];
146 $fields[
"{$key}_id"] =
"{$key}_id";
170 if ( !array_key_exists( $key, $this->joinCache ) ) {
176 $fields[
"{$key}_text"] = $key;
177 $fields[
"{$key}_data"] =
'NULL';
178 $fields[
"{$key}_cid"] =
'NULL';
182 $tempTableStage = isset( $this->tempTables[$key] )
185 $t = $this->tempTables[$key];
186 $alias =
"temp_$key";
187 $tables[$alias] =
$t[
'table'];
188 $joins[$alias] = [ $join,
"{$alias}.{$t['pk']} = {$t['joinPK']}" ];
190 $joinField =
"{$alias}.{$t['field']}";
196 $joins[$alias][0] =
'LEFT JOIN';
197 $joinField =
"(CASE WHEN {$key}_id != 0 THEN {$key}_id ELSE {$alias}.{$t['field']} END)";
198 throw new LogicException(
'Nothing should reach this code path at this time' );
202 $joinField =
"{$key}_id";
205 $alias =
"comment_$key";
206 $tables[$alias] =
'comment';
207 $joins[$alias] = [ $join,
"{$alias}.comment_id = {$joinField}" ];
210 $fields[
"{$key}_text"] =
"{$alias}.comment_text";
212 $fields[
"{$key}_text"] =
"COALESCE( {$alias}.comment_text, $key )";
214 $fields[
"{$key}_data"] =
"{$alias}.comment_data";
215 $fields[
"{$key}_cid"] =
"{$alias}.comment_id";
218 $this->joinCache[$key] = [
225 return $this->joinCache[$key];
242 if ( array_key_exists(
"{$key}_text", $row ) && array_key_exists(
"{$key}_data", $row ) ) {
243 $cid = $row[
"{$key}_cid"] ??
null;
244 $text = $row[
"{$key}_text"];
245 $data = $row[
"{$key}_data"];
248 if (
$fallback && isset( $row[$key] ) ) {
249 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
253 "Missing {$key}_text and {$key}_data fields in row with MIGRATION_OLD / READ_OLD"
259 $tempTableStage = isset( $this->tempTables[$key] )
264 throw new InvalidArgumentException(
265 "\$row does not contain fields needed for comment $key and getComment(), but "
266 .
"does have fields for getCommentLegacy()"
269 $id = $row[
"{$key}_id"];
272 [
'comment_id',
'comment_text',
'comment_data' ],
273 [
'comment_id' => $id ],
278 array_key_exists(
"{$key}_pk", $row )
281 throw new InvalidArgumentException(
282 "\$row does not contain fields needed for comment $key and getComment(), but "
283 .
"does have fields for getCommentLegacy()"
286 $t = $this->tempTables[$key];
287 $id = $row[
"{$key}_pk"];
289 [
$t[
'table'],
'comment' ],
290 [
'comment_id',
'comment_text',
'comment_data' ],
294 [
'comment' => [
'JOIN', [
"comment_id = {$t['field']}" ] ] ]
297 if ( $row2 ===
null &&
$fallback && isset( $row[$key] ) ) {
298 wfLogWarning(
"Using deprecated fallback handling for comment $key" );
299 $row2 = (object)[
'comment_text' => $row[$key],
'comment_data' =>
null ];
301 if ( $row2 ===
null ) {
302 throw new InvalidArgumentException(
"\$row does not contain fields needed for comment $key" );
306 $cid = $row2->comment_id;
307 $text = $row2->comment_text;
308 $data = $row2->comment_data;
310 array_key_exists(
"{$key}_old", $row )
313 $text = $row[
"{$key}_old"];
326 if ( $data !==
null ) {
327 $data = FormatJson::decode( $data,
true );
328 if ( !is_array( $data ) ) {
330 wfLogWarning(
"Invalid JSON object in comment: $data" );
334 if ( isset( $data[
'_message'] ) ) {
335 $msg = self::decodeMessage( $data[
'_message'] )
336 ->setInterfaceMessageFlag(
true );
338 if ( !empty( $data[
'_null'] ) ) {
341 foreach ( $data as $k => $v ) {
342 if ( substr( $k, 0, 1 ) ===
'_' ) {
370 if ( $row ===
null ) {
372 throw new InvalidArgumentException(
'$row must not be null' );
398 if ( $row ===
null ) {
400 throw new InvalidArgumentException(
'$row must not be null' );
427 $comment = CommentStoreComment::newUnsavedComment( $comment, $data );
429 # Truncate comment in a Unicode-sensitive manner
430 $comment->text = $this->lang->truncateForVisual( $comment->text, self::COMMENT_CHARACTER_LIMIT );
433 $dbData = $comment->data;
434 if ( !$comment->message instanceof
RawMessage ) {
435 if ( $dbData ===
null ) {
436 $dbData = [
'_null' =>
true ];
438 $dbData[
'_message'] = self::encodeMessage( $comment->message );
440 if ( $dbData !==
null ) {
441 $dbData = FormatJson::encode( (
object)$dbData,
false, FormatJson::ALL_OK );
442 $len = strlen( $dbData );
443 if ( $len > self::MAX_DATA_LENGTH ) {
444 $max = self::MAX_DATA_LENGTH;
445 throw new OverflowException(
"Comment data is too long ($len bytes, maximum is $max)" );
449 $hash = self::hash( $comment->text, $dbData );
454 'comment_hash' => $hash,
455 'comment_text' => $comment->text,
456 'comment_data' => $dbData,
460 if ( !$comment->id ) {
464 'comment_hash' => $hash,
465 'comment_text' => $comment->text,
466 'comment_data' => $dbData,
493 $fields[$key] = $this->lang->truncateForDatabase( $comment->text, 255 );
497 $tempTableStage = isset( $this->tempTables[$key] )
500 $t = $this->tempTables[$key];
502 $commentId = $comment->id;
503 $callback =
function ( $id ) use ( $dbw, $commentId,
$t, $func ) {
508 $t[
'field'] => $commentId,
515 $fields[
"{$key}_id"] = $comment->id;
519 return [ $fields, $callback ];
538 if ( $comment ===
null ) {
540 throw new InvalidArgumentException(
'$comment can not be null' );
544 $tempTableStage = isset( $this->tempTables[$key] )
547 throw new InvalidArgumentException(
"Must use insertWithTempTable() for $key" );
550 list( $fields ) = $this->
insertInternal( $dbw, $key, $comment, $data );
576 if ( $comment ===
null ) {
578 throw new InvalidArgumentException(
'$comment can not be null' );
582 if ( !isset( $this->tempTables[$key] ) ) {
583 throw new InvalidArgumentException(
"Must use insert() for $key" );
584 } elseif ( isset( $this->tempTables[$key][
'deprecatedIn'] ) ) {
585 wfDeprecated( __METHOD__ .
" for $key", $this->tempTables[$key][
'deprecatedIn'] );
588 list( $fields, $callback ) = $this->
insertInternal( $dbw, $key, $comment, $data );
590 $callback =
function () {
594 return [ $fields, $callback ];
605 foreach ( $params as &$param ) {
606 if ( $param instanceof
Message ) {
608 'message' => self::encodeMessage( $param )
612 array_unshift( $params, $key );
622 $key = array_shift( $data );
623 foreach ( $data as &$param ) {
624 if ( is_object( $param ) ) {
625 $param = (array)$param;
627 if ( is_array( $param ) && count( $param ) === 1 && isset( $param[
'message'] ) ) {
628 $param = self::decodeMessage( $param[
'message'] );
631 return new Message( $key, $data );
640 public static function hash( $text, $data ) {
641 $hash = crc32( $text ) ^ crc32( (
string)$data );
645 if ( $hash >= 0x80000000 ) {
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 $function is deprecated.
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.
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
if(!isset( $args[0])) $lang