MediaWiki  master
CommentStoreComment.php
Go to the documentation of this file.
1 <?php
23 
30 
32  public $id;
33 
35  public $text;
36 
38  public $message;
39 
41  public $data;
42 
50  public function __construct( $id, $text, Message $message = null, array $data = null ) {
51  $this->id = $id;
52  $this->text = $text;
53  $this->message = $message ?: new RawMessage( '$1', [ Message::plaintextParam( $text ) ] );
54  $this->data = $data;
55  }
56 
66  public static function newUnsavedComment( $comment, array $data = null ) {
67  if ( $comment instanceof CommentStoreComment ) {
68  return $comment;
69  }
70 
71  if ( $data !== null ) {
72  foreach ( $data as $k => $v ) {
73  if ( substr( $k, 0, 1 ) === '_' ) {
74  throw new InvalidArgumentException( 'Keys in $data beginning with "_" are reserved' );
75  }
76  }
77  }
78 
79  if ( $comment instanceof Message ) {
80  $message = clone $comment;
81  // Avoid $wgForceUIMsgAsContentMsg
82  $text = $message->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() )
83  ->setInterfaceMessageFlag( true )
84  ->text();
85  return new CommentStoreComment( null, $text, $message, $data );
86  } else {
87  return new CommentStoreComment( null, $comment, null, $data );
88  }
89  }
90 }
__construct( $id, $text, Message $message=null, array $data=null)
The Message class provides methods which fulfil two basic services:
Definition: Message.php:162
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
int null $id
Comment ID, if any.
string $text
Text version of the comment.
inLanguage( $lang)
Request the message in any language that is supported.
Definition: Message.php:732
Message $message
Message version of the comment.
Variant of the Message class.
Definition: RawMessage.php:34
array null $data
Structured data of the comment.
static plaintextParam( $plaintext)
Definition: Message.php:1104