MediaWiki  1.34.0
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 }
CommentStoreComment\newUnsavedComment
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
Definition: CommentStoreComment.php:66
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
Message
CommentStoreComment\$text
string $text
Text version of the comment.
Definition: CommentStoreComment.php:35
CommentStoreComment\$data
array null $data
Structured data of the comment.
Definition: CommentStoreComment.php:41
CommentStoreComment\$message
Message $message
Message version of the comment.
Definition: CommentStoreComment.php:38
CommentStoreComment\__construct
__construct( $id, $text, Message $message=null, array $data=null)
Definition: CommentStoreComment.php:50
CommentStoreComment\$id
int null $id
Comment ID, if any.
Definition: CommentStoreComment.php:32
RawMessage
Variant of the Message class.
Definition: RawMessage.php:34
CommentStoreComment
CommentStoreComment represents a comment stored by CommentStore.
Definition: CommentStoreComment.php:29