MediaWiki REL1_40
MediaWiki\CommentFormatter\CommentFormatter Class Reference

This is the main service interface for converting single-line comments from various DB comment fields into HTML. More...

Inherited by MediaWiki\CommentFormatter\RowCommentFormatter.

Collaboration diagram for MediaWiki\CommentFormatter\CommentFormatter:

Public Member Functions

 __construct (CommentParserFactory $parserFactory)
 
 createBatch ()
 Format comments using a fluent interface.
 
 createRevisionBatch ()
 Format a batch of revision comments using a fluent interface.
 
 format (string $comment, LinkTarget $selfLinkTarget=null, $samePage=false, $wikiId=false)
 Format a single comment.
 
 formatBlock (string $comment, LinkTarget $selfLinkTarget=null, $samePage=false, $wikiId=false, $useParentheses=true)
 Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return an empty string.
 
 formatItems ( $items)
 Format an iterator over CommentItem objects.
 
 formatItemsInternal ( $items, $selfLinkTarget=null, $samePage=null, $wikiId=null, $enableSectionLinks=null, $useBlock=null, $useParentheses=null)
 
 formatLinks (string $comment, LinkTarget $selfLinkTarget=null, $samePage=false, $wikiId=false)
 Format links in a comment, ignoring section links in C-style comments.
 
 formatLinksUnsafe (string $comment, LinkTarget $selfLinkTarget=null, $samePage=false, $wikiId=false)
 Format a comment, passing through HTML in the input to the output.
 
 formatRevision (RevisionRecord $revision, Authority $authority, $samePage=false, $isPublic=false, $useParentheses=true)
 Wrap and format the given revision's comment block, if the specified user is allowed to view it.
 
 formatRevisions ( $revisions, Authority $authority, $samePage=false, $isPublic=false, $useParentheses=true, $indexById=false)
 Format multiple revision comments.
 
 formatStrings ( $strings, LinkTarget $selfLinkTarget=null, $samePage=false, $wikiId=false)
 Format comments which are provided as strings and all have the same self-link target and other options.
 
 formatStringsAsBlock ( $strings, LinkTarget $selfLinkTarget=null, $samePage=false, $wikiId=false, $useParentheses=true)
 Given an array of comments as strings which all have the same self link target, format the comments and wrap them in standard punctuation and formatting.
 

Protected Member Functions

 wrapCommentWithBlock ( $formatted, $useParentheses)
 Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return empty string.
 

Protected Attributes

CommentParserFactory $parserFactory
 

Detailed Description

This is the main service interface for converting single-line comments from various DB comment fields into HTML.

Since
1.38

Definition at line 16 of file CommentFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\CommentFormatter\CommentFormatter::__construct ( CommentParserFactory $parserFactory)
Access: internal
Use MediaWikiServices::getCommentFormatter()
Parameters
CommentParserFactory$parserFactory

Definition at line 25 of file CommentFormatter.php.

References MediaWiki\CommentFormatter\CommentFormatter\$parserFactory.

Member Function Documentation

◆ createBatch()

MediaWiki\CommentFormatter\CommentFormatter::createBatch ( )

Format comments using a fluent interface.

Returns
CommentBatch

Definition at line 34 of file CommentFormatter.php.

Referenced by MediaWiki\CommentFormatter\RowCommentFormatter\formatRows().

◆ createRevisionBatch()

MediaWiki\CommentFormatter\CommentFormatter::createRevisionBatch ( )

Format a batch of revision comments using a fluent interface.

Returns
RevisionCommentBatch

Definition at line 280 of file CommentFormatter.php.

◆ format()

MediaWiki\CommentFormatter\CommentFormatter::format ( string $comment,
LinkTarget $selfLinkTarget = null,
$samePage = false,
$wikiId = false )

Format a single comment.

Similar to the old Linker::formatComment().

Parameters
string$comment
LinkTarget | null$selfLinkTargetThe title used for fragment-only and section links, formerly $title.
bool$samePageIf true, self links are rendered with a fragment- only URL. Formerly $local.
string | false | null$wikiIdID of the wiki to link to (if not the local wiki), as used by WikiMap.
Returns
string

Definition at line 50 of file CommentFormatter.php.

◆ formatBlock()

MediaWiki\CommentFormatter\CommentFormatter::formatBlock ( string $comment,
LinkTarget $selfLinkTarget = null,
$samePage = false,
$wikiId = false,
$useParentheses = true )

Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return an empty string.

Parameters
string$comment
LinkTarget | null$selfLinkTargetThe title used for fragment-only and section links, formerly $title.
bool$samePageIf true, self links are rendered with a fragment- only URL. Formerly $local.
string | false | null$wikiIdID of the wiki to link to (if not the local wiki), as used by WikiMap.
bool$useParentheses
Returns
string

Definition at line 71 of file CommentFormatter.php.

◆ formatItems()

MediaWiki\CommentFormatter\CommentFormatter::formatItems ( $items)

Format an iterator over CommentItem objects.

A shortcut for createBatch()->comments()->execute() for when you need to pass no other options.

Parameters
iterable<CommentItem>|Traversable$items
Returns
string[]

Definition at line 293 of file CommentFormatter.php.

References MediaWiki\CommentFormatter\CommentFormatter\formatItemsInternal().

◆ formatItemsInternal()

MediaWiki\CommentFormatter\CommentFormatter::formatItemsInternal ( $items,
$selfLinkTarget = null,
$samePage = null,
$wikiId = null,
$enableSectionLinks = null,
$useBlock = null,
$useParentheses = null )
Access: internal
For use by CommentBatch

Format comments with nullable batch options.

Parameters
iterable<CommentItem>$items
LinkTarget | null$selfLinkTarget
bool | null$samePage
string | false | null$wikiId
bool | null$enableSectionLinks
bool | null$useBlock
bool | null$useParentheses
Returns
string[]

Definition at line 311 of file CommentFormatter.php.

References MediaWiki\CommentFormatter\CommentFormatter\wrapCommentWithBlock().

Referenced by MediaWiki\CommentFormatter\CommentFormatter\formatItems().

◆ formatLinks()

MediaWiki\CommentFormatter\CommentFormatter::formatLinks ( string $comment,
LinkTarget $selfLinkTarget = null,
$samePage = false,
$wikiId = false )

Format links in a comment, ignoring section links in C-style comments.

Parameters
string$comment
LinkTarget | null$selfLinkTargetThe title used for fragment-only and section links, formerly $title.
bool$samePageIf true, self links are rendered with a fragment- only URL. Formerly $local.
string | false | null$wikiIdID of the wiki to link to (if not the local wiki), as used by WikiMap.
Returns
string

Definition at line 117 of file CommentFormatter.php.

◆ formatLinksUnsafe()

MediaWiki\CommentFormatter\CommentFormatter::formatLinksUnsafe ( string $comment,
LinkTarget $selfLinkTarget = null,
$samePage = false,
$wikiId = false )

Format a comment, passing through HTML in the input to the output.

This is unsafe and exists only for backwards compatibility with Linker::formatLinksInComment().

In new code, use formatLinks() or createBatch()->disableSectionLinks().

Access: internal
Parameters
string$comment
LinkTarget | null$selfLinkTargetThe title used for fragment-only and section links, formerly $title.
bool$samePageIf true, self links are rendered with a fragment- only URL. Formerly $local.
string | false | null$wikiIdID of the wiki to link to (if not the local wiki), as used by WikiMap.
Returns
string

Definition at line 96 of file CommentFormatter.php.

◆ formatRevision()

MediaWiki\CommentFormatter\CommentFormatter::formatRevision ( RevisionRecord $revision,
Authority $authority,
$samePage = false,
$isPublic = false,
$useParentheses = true )

Wrap and format the given revision's comment block, if the specified user is allowed to view it.

This method produces HTML that requires CSS styles in mediawiki.interface.helpers.styles.

NOTE: revision comments are special. This is not the same as getting a revision comment as a string and then formatting it with format().

Parameters
RevisionRecord$revisionThe revision to extract the comment and title from. The title should always be populated, to avoid an additional DB query.
Authority$authorityThe user viewing the comment
bool$samePageIf true, self links are rendered with a fragment- only URL. Formerly $local.
bool$isPublicShow only if all users can see it
bool$useParenthesesWhether the comment is wrapped in parentheses
Returns
string

Definition at line 227 of file CommentFormatter.php.

◆ formatRevisions()

MediaWiki\CommentFormatter\CommentFormatter::formatRevisions ( $revisions,
Authority $authority,
$samePage = false,
$isPublic = false,
$useParentheses = true,
$indexById = false )

Format multiple revision comments.

See also
CommentFormatter::formatRevision()
Parameters
iterable<RevisionRecord>$revisions
Authority$authority
bool$samePage
bool$isPublic
bool$useParentheses
bool$indexById
Returns
string|string[]

Definition at line 252 of file CommentFormatter.php.

◆ formatStrings()

MediaWiki\CommentFormatter\CommentFormatter::formatStrings ( $strings,
LinkTarget $selfLinkTarget = null,
$samePage = false,
$wikiId = false )

Format comments which are provided as strings and all have the same self-link target and other options.

If you need a different title for each comment, use createBatch().

Parameters
string[]$strings
LinkTarget | null$selfLinkTargetThe title used for fragment-only and section links, formerly $title.
bool$samePageIf true, self links are rendered with a fragment- only URL. Formerly $local.
string | false | null$wikiIdID of the wiki to link to (if not the local wiki), as used by WikiMap.
Returns
string[]

Definition at line 167 of file CommentFormatter.php.

◆ formatStringsAsBlock()

MediaWiki\CommentFormatter\CommentFormatter::formatStringsAsBlock ( $strings,
LinkTarget $selfLinkTarget = null,
$samePage = false,
$wikiId = false,
$useParentheses = true )

Given an array of comments as strings which all have the same self link target, format the comments and wrap them in standard punctuation and formatting.

If you need a different title for each comment, use createBatch().

Parameters
string[]$strings
LinkTarget | null$selfLinkTargetThe title used for fragment-only and section links, formerly $title.
bool$samePageIf true, self links are rendered with a fragment- only URL. Formerly $local.
string | false | null$wikiIdID of the wiki to link to (if not the local wiki), as used by WikiMap.
bool$useParentheses
Returns
string[]

Definition at line 195 of file CommentFormatter.php.

References MediaWiki\CommentFormatter\CommentFormatter\wrapCommentWithBlock().

◆ wrapCommentWithBlock()

MediaWiki\CommentFormatter\CommentFormatter::wrapCommentWithBlock ( $formatted,
$useParentheses )
protected

Wrap a comment in standard punctuation and formatting if it's non-empty, otherwise return empty string.

Parameters
string$formatted
bool$useParenthesesWhether the comment is wrapped in parentheses
Returns
string

Definition at line 345 of file CommentFormatter.php.

References wfMessage().

Referenced by MediaWiki\CommentFormatter\CommentFormatter\formatItemsInternal(), and MediaWiki\CommentFormatter\CommentFormatter\formatStringsAsBlock().

Member Data Documentation

◆ $parserFactory

CommentParserFactory MediaWiki\CommentFormatter\CommentFormatter::$parserFactory
protected

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