MediaWiki  master
MediaWiki\CommentFormatter\CommentFormatter Class Reference

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

Inheritance diagram for MediaWiki\CommentFormatter\CommentFormatter:
Collaboration diagram for MediaWiki\CommentFormatter\CommentFormatter:

Public Member Functions

 __construct (CommentParserFactory $parserFactory)
 
 createBatch ()
 Format comments using a fluent interface. More...
 
 createRevisionBatch ()
 Format a batch of revision comments using a fluent interface. More...
 
 format (string $comment, LinkTarget $selfLinkTarget=null, $samePage=false, $wikiId=false)
 Format a single comment. More...
 
 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. More...
 
 formatItems ( $items)
 Format an iterator over CommentItem objects. More...
 
 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. More...
 
 formatLinksUnsafe (string $comment, LinkTarget $selfLinkTarget=null, $samePage=false, $wikiId=false)
 Format a comment, passing through HTML in the input to the output. More...
 
 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. More...
 
 formatRevisions ( $revisions, Authority $authority, $samePage=false, $isPublic=false, $useParentheses=true, $indexById=false)
 Format multiple revision comments. More...
 
 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. More...
 
 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. More...
 

Protected Member Functions

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

Protected Attributes

CommentParserFactory $parserFactory
 

Private Member Functions

 formatInternal ( $comment, $enableSectionLinks, $useBlock, $useParentheses, $selfLinkTarget=null, $samePage=false, $wikiId=false)
 Format a single comment with many ugly boolean parameters. More...
 
 preprocessRevComment (CommentParser $parser, Authority $authority, RevisionRecord $revRecord, $samePage=false, $isPublic=false, $useParentheses=true)
 Preprocess and wrap a revision comment. More...
 

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)

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

References MediaWiki\CommentFormatter\CommentFormatter\formatInternal().

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

References MediaWiki\CommentFormatter\CommentFormatter\formatInternal().

◆ formatInternal()

MediaWiki\CommentFormatter\CommentFormatter::formatInternal (   $comment,
  $enableSectionLinks,
  $useBlock,
  $useParentheses,
  $selfLinkTarget = null,
  $samePage = false,
  $wikiId = false 
)
private

Format a single comment with many ugly boolean parameters.

Parameters
string$comment
bool$enableSectionLinks
bool$useBlock
bool$useParentheses
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|string[]

Definition at line 139 of file CommentFormatter.php.

References MediaWiki\CommentFormatter\CommentFormatter\wrapCommentWithBlock().

Referenced by MediaWiki\CommentFormatter\CommentFormatter\format(), MediaWiki\CommentFormatter\CommentFormatter\formatBlock(), and MediaWiki\CommentFormatter\CommentFormatter\formatLinks().

◆ 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 292 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 310 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.

References MediaWiki\CommentFormatter\CommentFormatter\formatInternal().

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

References MediaWiki\CommentFormatter\CommentFormatter\preprocessRevComment().

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

References MediaWiki\CommentFormatter\CommentFormatter\preprocessRevComment().

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

◆ preprocessRevComment()

MediaWiki\CommentFormatter\CommentFormatter::preprocessRevComment ( CommentParser  $parser,
Authority  $authority,
RevisionRecord  $revRecord,
  $samePage = false,
  $isPublic = false,
  $useParentheses = true 
)
private

◆ 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 344 of file CommentFormatter.php.

References wfMessage().

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

Member Data Documentation

◆ $parserFactory

CommentParserFactory MediaWiki\CommentFormatter\CommentFormatter::$parserFactory
protected

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