MediaWiki  master
MediaWiki\CommentFormatter\CommentBatch Class Reference

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

Collaboration diagram for MediaWiki\CommentFormatter\CommentBatch:

Public Member Functions

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

Private Attributes

iterable< CommentItem > Traversable $comments
 
bool null $enableSectionLinks
 
CommentFormatter $formatter
 
bool null $samePage
 
LinkTarget null $selfLinkTarget
 
bool null $useBlock
 
bool null $useParentheses
 
string false null $wikiId
 

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.

References MediaWiki\CommentFormatter\CommentBatch\$formatter.

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\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.

Referenced by MediaWiki\CommentFormatter\CommentBatch\disableSectionLinks(), 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().

◆ 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().

◆ 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().

◆ 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().

◆ 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().

Member Data Documentation

◆ $comments

iterable<CommentItem> Traversable MediaWiki\CommentFormatter\CommentBatch::$comments
private

Definition at line 17 of file CommentBatch.php.

Referenced by MediaWiki\CommentFormatter\CommentBatch\comments().

◆ $enableSectionLinks

bool null MediaWiki\CommentFormatter\CommentBatch::$enableSectionLinks
private

Definition at line 29 of file CommentBatch.php.

◆ $formatter

CommentFormatter MediaWiki\CommentFormatter\CommentBatch::$formatter
private

◆ $samePage

bool null MediaWiki\CommentFormatter\CommentBatch::$samePage
private

Definition at line 25 of file CommentBatch.php.

Referenced by MediaWiki\CommentFormatter\CommentBatch\samePage().

◆ $selfLinkTarget

LinkTarget null MediaWiki\CommentFormatter\CommentBatch::$selfLinkTarget
private

◆ $useBlock

bool null MediaWiki\CommentFormatter\CommentBatch::$useBlock
private

Definition at line 19 of file CommentBatch.php.

Referenced by MediaWiki\CommentFormatter\CommentBatch\useBlock().

◆ $useParentheses

bool null MediaWiki\CommentFormatter\CommentBatch::$useParentheses
private

◆ $wikiId

string false null MediaWiki\CommentFormatter\CommentBatch::$wikiId
private

Definition at line 27 of file CommentBatch.php.

Referenced by MediaWiki\CommentFormatter\CommentBatch\wikiId().


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