Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F5984470
RowCommentFormatter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
RowCommentFormatter.php
View Options
<?php
namespace
MediaWiki\CommentFormatter
;
use
MediaWiki\CommentStore\CommentStore
;
use
Traversable
;
use
Wikimedia\Rdbms\IResultWrapper
;
/**
* This is basically a CommentFormatter with a CommentStore dependency, allowing
* it to retrieve comment texts directly from database result wrappers.
*
* @since 1.38
*/
class
RowCommentFormatter
extends
CommentFormatter
{
/** @var CommentStore */
private
$commentStore
;
/**
* @internal Use MediaWikiServices::getRowCommentFormatter()
*
* @param CommentParserFactory $commentParserFactory
* @param CommentStore $commentStore
*/
public
function
__construct
(
CommentParserFactory
$commentParserFactory
,
CommentStore
$commentStore
)
{
parent
::
__construct
(
$commentParserFactory
);
$this
->
commentStore
=
$commentStore
;
}
/**
* Format DB rows using a fluent interface. Pass the return value of this
* function to CommentBatch::comments().
*
* Example:
* $comments = $rowCommentFormatter->createBatch()
* ->comments(
* $rowCommentFormatter->rows( $rows )
* ->commentField( 'img_comment' )
* )
* ->useBlock( true )
* ->execute();
*
* @param Traversable|array $rows
* @return RowCommentIterator
*/
public
function
rows
(
$rows
)
{
return
new
RowCommentIterator
(
$this
->
commentStore
,
$rows
);
}
/**
* Format DB rows using a parametric interface.
*
* @param iterable<\stdClass>|IResultWrapper $rows
* @param string $commentKey The comment key to pass through to CommentStore,
* typically a legacy field name.
* @param string|null $namespaceField The namespace field for the self-link
* target, or null to have no self-link target.
* @param string|null $titleField The title field for the self-link target,
* or null to have no self-link target.
* @param string|null $indexField The field to use for array keys in the
* result, or null to use the same keys as in the input $rows
* @param bool $useBlock Wrap the output in standard punctuation and
* formatting if it's non-empty.
* @param bool $useParentheses Wrap the output with parentheses. Has no
* effect if $useBlock is false.
* @return string[] The formatted comment. The key will be the value of the
* index field if an index field was specified, or the key from the
* corresponding element of $rows if no index field was specified.
*/
public
function
formatRows
(
$rows
,
$commentKey
,
$namespaceField
=
null
,
$titleField
=
null
,
$indexField
=
null
,
$useBlock
=
false
,
$useParentheses
=
true
)
{
return
$this
->
createBatch
()
->
comments
(
$this
->
rows
(
$rows
)
->
commentKey
(
$commentKey
)
->
namespaceField
(
$namespaceField
)
->
titleField
(
$titleField
)
->
indexField
(
$indexField
)
)
->
useBlock
(
$useBlock
)
->
useParentheses
(
$useParentheses
)
->
execute
();
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Oct 3, 23:22 (2 w, 22 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
02/cc/b5fb6fe87325e718d1731649db09
Default Alt Text
RowCommentFormatter.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment