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