MediaWiki REL1_39
CommentStoreComment.php
Go to the documentation of this file.
1<?php
21
31
33 public $id;
34
36 public $text;
37
39 public $message;
40
42 public $data;
43
51 public function __construct( $id, $text, Message $message = null, array $data = null ) {
52 $this->id = $id;
53 $this->text = $text;
54 $this->message = $message ?: new RawMessage( '$1', [ Message::plaintextParam( $text ) ] );
55 $this->data = $data;
56 }
57
67 public static function newUnsavedComment( $comment, array $data = null ) {
68 if ( $comment instanceof CommentStoreComment ) {
69 return $comment;
70 }
71
72 if ( $data !== null ) {
73 foreach ( $data as $k => $v ) {
74 if ( substr( $k, 0, 1 ) === '_' ) {
75 throw new InvalidArgumentException( 'Keys in $data beginning with "_" are reserved' );
76 }
77 }
78 }
79
80 if ( $comment instanceof Message ) {
81 $message = clone $comment;
82 // Avoid $wgForceUIMsgAsContentMsg
83 $text = $message->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() )
84 ->setInterfaceMessageFlag( true )
85 ->text();
86 return new CommentStoreComment( null, $text, $message, $data );
87 } else {
88 return new CommentStoreComment( null, $comment, null, $data );
89 }
90 }
91}
Value object for a comment stored by CommentStore.
string $text
Text version of the comment.
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
int null $id
Comment ID, if any.
__construct( $id, $text, Message $message=null, array $data=null)
Message $message
Message version of the comment.
array null $data
Structured data of the comment.
Service locator for MediaWiki core services.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:140
static plaintextParam( $plaintext)
Definition Message.php:1266
inLanguage( $lang)
Request the message in any language that is supported.
Definition Message.php:832
Variant of the Message class.