MediaWiki 1.42.0
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, $text, Message $message = null, array $data = null ) {
58 if ( $text === null ) {
59 // TODO: Turn this warning into a proper type hint once we have
60 // found and fixed any offenders (T355751).
61 wfLogWarning( 'Comment text should not be null!' );
62 $text = '';
63 }
64
65 $this->id = (int)$id;
66 $this->text = (string)$text;
67 $this->message = $message
68 ?: new RawMessage(
69 '$1',
70 [ Message::plaintextParam( $this->text ) ]
71 );
72 $this->data = $data;
73 }
74
84 public static function newUnsavedComment( $comment, array $data = null ) {
85 if ( $comment instanceof CommentStoreComment ) {
86 return $comment;
87 }
88
89 if ( $data !== null ) {
90 foreach ( $data as $k => $v ) {
91 if ( substr( $k, 0, 1 ) === '_' ) {
92 throw new InvalidArgumentException( 'Keys in $data beginning with "_" are reserved' );
93 }
94 }
95 }
96
97 if ( $comment instanceof Message ) {
98 $message = clone $comment;
99 // Avoid $wgForceUIMsgAsContentMsg
100 $text = $message->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() )
101 ->setInterfaceMessageFlag( true )
102 ->text();
103 return new CommentStoreComment( null, $text, $message, $data );
104 } else {
105 return new CommentStoreComment( null, $comment, null, $data );
106 }
107 }
108}
109
111class_alias( CommentStoreComment::class, 'CommentStoreComment' );
wfLogWarning( $msg, $callerOffset=1, $level=E_USER_WARNING)
Send a warning as a PHP error and the debug log.
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.
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:157
inLanguage( $lang)
Request the message in any language that is supported.
Definition Message.php:865
static plaintextParam( $plaintext)
Definition Message.php:1321