2017-06-06 17:39:14 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
2022-12-12 02:10:13 +00:00
|
|
|
|
2022-12-28 21:50:03 +00:00
|
|
|
namespace MediaWiki\CommentStore;
|
|
|
|
|
|
|
|
|
|
use InvalidArgumentException;
|
2022-12-12 02:10:13 +00:00
|
|
|
use MediaWiki\Language\RawMessage;
|
2018-07-29 12:24:54 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2024-02-08 18:57:07 +00:00
|
|
|
use MediaWiki\Message\Message;
|
2017-06-06 17:39:14 +00:00
|
|
|
|
|
|
|
|
/**
|
2020-07-24 18:46:44 +00:00
|
|
|
* Value object for a comment stored by CommentStore.
|
|
|
|
|
*
|
|
|
|
|
* The fields should be considered read-only.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup CommentStore
|
2017-06-06 17:39:14 +00:00
|
|
|
* @since 1.30
|
|
|
|
|
*/
|
|
|
|
|
class CommentStoreComment {
|
|
|
|
|
|
|
|
|
|
/** @var int|null Comment ID, if any */
|
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
|
|
/** @var string Text version of the comment */
|
|
|
|
|
public $text;
|
|
|
|
|
|
|
|
|
|
/** @var Message Message version of the comment. Might be a RawMessage */
|
|
|
|
|
public $message;
|
|
|
|
|
|
|
|
|
|
/** @var array|null Structured data of the comment */
|
|
|
|
|
public $data;
|
|
|
|
|
|
|
|
|
|
/**
|
2020-06-26 12:14:23 +00:00
|
|
|
* @internal For use by CommentStore only. Use self::newUnsavedComment() instead.
|
2017-06-06 17:39:14 +00:00
|
|
|
* @param int|null $id
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @param Message|null $message
|
|
|
|
|
* @param array|null $data
|
|
|
|
|
*/
|
2024-10-16 18:58:33 +00:00
|
|
|
public function __construct( $id, string $text, ?Message $message = null, ?array $data = null ) {
|
2024-01-25 09:00:26 +00:00
|
|
|
$this->id = (int)$id;
|
2024-07-24 21:58:05 +00:00
|
|
|
$this->text = $text;
|
2024-01-25 09:00:26 +00:00
|
|
|
$this->message = $message
|
|
|
|
|
?: new RawMessage(
|
|
|
|
|
'$1',
|
|
|
|
|
[ Message::plaintextParam( $this->text ) ]
|
|
|
|
|
);
|
2017-06-06 17:39:14 +00:00
|
|
|
$this->data = $data;
|
|
|
|
|
}
|
2017-09-11 18:27:01 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
|
*/
|
2024-10-16 18:58:33 +00:00
|
|
|
public static function newUnsavedComment( $comment, ?array $data = null ) {
|
2017-09-11 18:27:01 +00:00
|
|
|
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;
|
2018-07-29 12:24:54 +00:00
|
|
|
// Avoid $wgForceUIMsgAsContentMsg
|
|
|
|
|
$text = $message->inLanguage( MediaWikiServices::getInstance()->getContentLanguage() )
|
2017-09-11 18:27:01 +00:00
|
|
|
->setInterfaceMessageFlag( true )
|
|
|
|
|
->text();
|
|
|
|
|
return new CommentStoreComment( null, $text, $message, $data );
|
|
|
|
|
} else {
|
|
|
|
|
return new CommentStoreComment( null, $comment, null, $data );
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-06 17:39:14 +00:00
|
|
|
}
|
2022-12-28 21:50:03 +00:00
|
|
|
|
2024-03-07 21:56:58 +00:00
|
|
|
/** @deprecated class alias since 1.40 */
|
2022-12-28 21:50:03 +00:00
|
|
|
class_alias( CommentStoreComment::class, 'CommentStoreComment' );
|