MediaWiki master
MediaWiki\CommentFormatter\CommentBatch Class Reference

This class provides a fluent interface for formatting a batch of comments. More...

Public Member Functions

 __construct (CommentFormatter $formatter)
 
 comments ( $comments)
 Set the comments to be formatted.
 
 disableSectionLinks ()
 Disable section links formatted as C-style comments, as used in revision comments to indicate the section which was edited.
 
 enableSectionLinks ( $enable)
 Set the option to enable/disable section links formatted as C-style comments, as used in revision comments to indicate the section which was edited.
 
 execute ()
 Format the comments and produce an array of HTML fragments.
 
 samePage ( $samePage=true)
 Set the same-page option.
 
 selfLinkTarget (LinkTarget $selfLinkTarget)
 Set the title to be used for self links in the comments.
 
 strings (array $strings)
 Specify the comments to be formatted as an array of strings.
 
 useBlock ( $useBlock=true)
 Wrap each comment in standard punctuation and formatting if it's non-empty.
 
 useParentheses ( $useParentheses=true)
 Wrap each comment with parentheses.
 
 wikiId ( $wikiId)
 ID of the wiki to link to (if not the local wiki), as used by WikiMap.
 

Detailed Description

This class provides a fluent interface for formatting a batch of comments.

Since
1.38

Definition at line 13 of file CommentBatch.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\CommentFormatter\CommentBatch::__construct ( CommentFormatter $formatter)
Access: internal
Use CommentFormatter::createBatch()
Parameters
CommentFormatter$formatter

Definition at line 36 of file CommentBatch.php.

Member Function Documentation

◆ comments()

MediaWiki\CommentFormatter\CommentBatch::comments ( $comments)

Set the comments to be formatted.

This can be an array of CommentItem objects, or it can be an iterator which generates CommentItem objects.

Theoretically iterable should imply Traversable, but PHPStorm gives an error when RowCommentIterator is passed as iterable<CommentItem>.

Parameters
iterable<CommentItem>|Traversable$comments
Returns
$this

Definition at line 50 of file CommentBatch.php.

References MediaWiki\CommentFormatter\CommentBatch\comments().

Referenced by MediaWiki\CommentFormatter\CommentBatch\comments(), MediaWiki\CommentFormatter\CommentBatch\execute(), and MediaWiki\CommentFormatter\CommentBatch\strings().

◆ disableSectionLinks()

MediaWiki\CommentFormatter\CommentBatch::disableSectionLinks ( )

Disable section links formatted as C-style comments, as used in revision comments to indicate the section which was edited.

Calling this approximately emulates Linker::formatLinksInComment() except that HTML in the input is escaped.

Returns
$this

Definition at line 139 of file CommentBatch.php.

References MediaWiki\CommentFormatter\CommentBatch\enableSectionLinks().

◆ enableSectionLinks()

MediaWiki\CommentFormatter\CommentBatch::enableSectionLinks ( $enable)

Set the option to enable/disable section links formatted as C-style comments, as used in revision comments to indicate the section which was edited.

If the method is not called, the option is true. Setting this to false approximately emulates Linker::formatLinksInComment() except that HTML in the input is escaped.

Parameters
bool$enable
Returns
$this

Definition at line 126 of file CommentBatch.php.

References MediaWiki\CommentFormatter\CommentBatch\enableSectionLinks().

Referenced by MediaWiki\CommentFormatter\CommentBatch\disableSectionLinks(), MediaWiki\CommentFormatter\CommentBatch\enableSectionLinks(), and MediaWiki\CommentFormatter\CommentBatch\execute().

◆ execute()

◆ samePage()

MediaWiki\CommentFormatter\CommentBatch::samePage ( $samePage = true)

Set the same-page option.

If this is true, section links and fragment- only wikilinks are rendered with an href that is a fragment-only URL. If it is false (the default), such links go to the self link title.

This can also be set per-item using CommentItem::samePage().

This is equivalent to $local in the old Linker methods.

Parameters
bool$samePage
Returns
$this

Definition at line 156 of file CommentBatch.php.

References MediaWiki\CommentFormatter\CommentBatch\samePage().

Referenced by MediaWiki\CommentFormatter\CommentBatch\execute(), and MediaWiki\CommentFormatter\CommentBatch\samePage().

◆ selfLinkTarget()

MediaWiki\CommentFormatter\CommentBatch::selfLinkTarget ( LinkTarget $selfLinkTarget)

Set the title to be used for self links in the comments.

If there is no title specified either here or in the item, fragment links are not expanded.

Parameters
LinkTarget$selfLinkTarget
Returns
$this

Definition at line 109 of file CommentBatch.php.

References MediaWiki\CommentFormatter\CommentBatch\selfLinkTarget().

Referenced by MediaWiki\CommentFormatter\CommentBatch\execute(), and MediaWiki\CommentFormatter\CommentBatch\selfLinkTarget().

◆ strings()

MediaWiki\CommentFormatter\CommentBatch::strings ( array $strings)

Specify the comments to be formatted as an array of strings.

This is a simplified wrapper for comments() which does not allow you to set options on a per-comment basis.

$strings must be an array – use comments() if you want to use an iterator.

Parameters
string[]$strings
Returns
$this

Definition at line 65 of file CommentBatch.php.

References MediaWiki\CommentFormatter\CommentBatch\comments().

◆ useBlock()

MediaWiki\CommentFormatter\CommentBatch::useBlock ( $useBlock = true)

Wrap each comment in standard punctuation and formatting if it's non-empty.

Empty comments remain empty. This causes the batch to work like the old Linker::commentBlock().

If this function is not called, the option is false.

Parameters
bool$useBlock
Returns
$this

Definition at line 80 of file CommentBatch.php.

References MediaWiki\CommentFormatter\CommentBatch\useBlock().

Referenced by MediaWiki\CommentFormatter\CommentBatch\execute(), and MediaWiki\CommentFormatter\CommentBatch\useBlock().

◆ useParentheses()

MediaWiki\CommentFormatter\CommentBatch::useParentheses ( $useParentheses = true)

Wrap each comment with parentheses.

This has no effect if the useBlock option is not enabled.

Unlike the legacy Linker::commentBlock(), this option defaults to false if this method is not called, since that better preserves the fluent style.

Parameters
bool$useParentheses
Returns
$this

Definition at line 96 of file CommentBatch.php.

References MediaWiki\CommentFormatter\CommentBatch\useParentheses().

Referenced by MediaWiki\CommentFormatter\CommentBatch\execute(), and MediaWiki\CommentFormatter\CommentBatch\useParentheses().

◆ wikiId()

MediaWiki\CommentFormatter\CommentBatch::wikiId ( $wikiId)

ID of the wiki to link to (if not the local wiki), as used by WikiMap.

This is used to render comments which are loaded from a foreign wiki. This only affects links which are syntactically internal – it has no effect on interwiki links.

This can also be set per-item using CommentItem::wikiId().

Parameters
string | false | null$wikiId
Returns
$this

Definition at line 172 of file CommentBatch.php.

References MediaWiki\CommentFormatter\CommentBatch\wikiId().

Referenced by MediaWiki\CommentFormatter\CommentBatch\execute(), and MediaWiki\CommentFormatter\CommentBatch\wikiId().


The documentation for this class was generated from the following file: