X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/CommentStoreComment.php diff --git a/includes/CommentStoreComment.php b/includes/CommentStoreComment.php new file mode 100644 index 00000000..3920ba08 --- /dev/null +++ b/includes/CommentStoreComment.php @@ -0,0 +1,92 @@ +id = $id; + $this->text = $text; + $this->message = $message ?: new RawMessage( '$1', [ $text ] ); + $this->data = $data; + } + + /** + * Create a new, unsaved CommentStoreComment + * + * @param string|Message|CommentStoreComment $comment Comment text or Message object. + * A CommentStoreComment is also accepted here, in which case it is returned unchanged. + * @param array|null $data Structured data to store. Keys beginning with '_' are reserved. + * Ignored if $comment is a CommentStoreComment. + * @return CommentStoreComment + */ + public static function newUnsavedComment( $comment, array $data = null ) { + global $wgContLang; + + if ( $comment instanceof CommentStoreComment ) { + return $comment; + } + + if ( $data !== null ) { + foreach ( $data as $k => $v ) { + if ( substr( $k, 0, 1 ) === '_' ) { + throw new InvalidArgumentException( 'Keys in $data beginning with "_" are reserved' ); + } + } + } + + if ( $comment instanceof Message ) { + $message = clone $comment; + $text = $message->inLanguage( $wgContLang ) // Avoid $wgForceUIMsgAsContentMsg + ->setInterfaceMessageFlag( true ) + ->text(); + return new CommentStoreComment( null, $text, $message, $data ); + } else { + return new CommentStoreComment( null, $comment, null, $data ); + } + } +}