MediaWiki  master
CommentStoreComment.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\CommentStore;
22 
23 use InvalidArgumentException;
26 use Message;
27 
37 
39  public $id;
40 
42  public $text;
43 
45  public $message;
46 
48  public $data;
49 
57  public function __construct( $id, $text, Message $message = null, array $data = null ) {
58  $this->id = $id;
59  $this->text = $text;
60  $this->message = $message ?: new RawMessage( '$1', [ Message::plaintextParam( $text ) ] );
61  $this->data = $data;
62  }
63 
73  public static function newUnsavedComment( $comment, array $data = null ) {
74  if ( $comment instanceof CommentStoreComment ) {
75  return $comment;
76  }
77 
78  if ( $data !== null ) {
79  foreach ( $data as $k => $v ) {
80  if ( substr( $k, 0, 1 ) === '_' ) {
81  throw new InvalidArgumentException( 'Keys in $data beginning with "_" are reserved' );
82  }
83  }
84  }
85 
86  if ( $comment instanceof Message ) {
87  $message = clone $comment;
88  // Avoid $wgForceUIMsgAsContentMsg
89  $text = $message->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() )
90  ->setInterfaceMessageFlag( true )
91  ->text();
92  return new CommentStoreComment( null, $text, $message, $data );
93  } else {
94  return new CommentStoreComment( null, $comment, null, $data );
95  }
96  }
97 }
98 
99 class_alias( CommentStoreComment::class, 'CommentStoreComment' );
Value object for a comment stored by CommentStore.
__construct( $id, $text, Message $message=null, array $data=null)
string $text
Text version of the comment.
Message $message
Message version of the comment.
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
array null $data
Structured data of the comment.
Variant of the Message class.
Definition: RawMessage.php:40
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:143
static plaintextParam( $plaintext)
Definition: Message.php:1266
inLanguage( $lang)
Request the message in any language that is supported.
Definition: Message.php:834