MediaWiki master
CommentStoreComment.php
Go to the documentation of this file.
1<?php
8
9use InvalidArgumentException;
13
23
25 public $id;
26
28 public $text;
29
31 public $message;
32
34 public $data;
35
43 public function __construct( $id, string $text, ?Message $message = null, ?array $data = null ) {
44 $this->id = (int)$id;
45 $this->text = $text;
46 $this->message = $message
47 ?: new RawMessage(
48 '$1',
49 [ Message::plaintextParam( $this->text ) ]
50 );
51 $this->data = $data;
52 }
53
63 public static function newUnsavedComment( $comment, ?array $data = null ) {
64 if ( $comment instanceof CommentStoreComment ) {
65 return $comment;
66 }
67
68 if ( $data !== null ) {
69 foreach ( $data as $k => $v ) {
70 if ( str_starts_with( $k, '_' ) ) {
71 throw new InvalidArgumentException( 'Keys in $data beginning with "_" are reserved' );
72 }
73 }
74 }
75
76 if ( $comment instanceof Message ) {
77 $message = clone $comment;
78 // Avoid $wgForceUIMsgAsContentMsg
79 $text = $message->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() )
80 ->setInterfaceMessageFlag( true )
81 ->text();
82 return new CommentStoreComment( null, $text, $message, $data );
83 } else {
84 return new CommentStoreComment( null, $comment, null, $data );
85 }
86 }
87}
88
89// This alias can not be removed, because serialized instances of this class are stored in Echo
90// tables, until we either migrate to JSON serialization (T325703) or expire those events (T383948).
92class_alias( CommentStoreComment::class, 'CommentStoreComment' );
Value object for a comment stored by CommentStore.
__construct( $id, string $text, ?Message $message=null, ?array $data=null)
static newUnsavedComment( $comment, ?array $data=null)
Create a new, unsaved CommentStoreComment.
string $text
Text version of the comment.
Message $message
Message version of the comment.
array null $data
Structured data of the comment.
Variant of the Message class.
Service locator for MediaWiki core services.
static getInstance()
Returns the global default instance of the top level service locator.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:144
inLanguage( $lang)
Request the message in any language that is supported.
Definition Message.php:890
static plaintextParam( $plaintext)
Definition Message.php:1341