Manual:Hooks/FormatAutocomments
FormatAutocomments | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> When an autocomment is formatted by the Linker. | |
<translate> Define function:</translate> | public static function onFormatAutocomments( &$comment, $pre, $auto, $post, $title, $local, $wikiId ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"FormatAutocomments": "MediaWiki\\Extension\\MyExtension\\Hooks::onFormatAutocomments"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> CommentFormatter/CommentParser.php |
<translate> Interface:</translate> | FormatAutocommentsHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:FormatAutocomments extensions</tvar>.</translate>
Given a comment (e.g. edit summary) like /* foo */ bar /* baz */ boom
, the parsed comment will be <output of FormatAutocomments hook with $auto being "foo"> bar <output of FormatAutocomments hook with $auto being "baz"> boom
. Unhandled autocomments will be assumed to be section IDs and turned into links.
Details
- &$comment: Reference to the accumulated comment. Initially null, when set the default code for formatting autocomments will be skipped.
- $pre: True if the autocomment is the last part of the comment.
- $auto: The extracted part of the comment before the call to the hook.
- $post: True if the autocomment is the first part of the comment.
- $title: An optional title object identifying the page the comment belongs to. Can be null.
- $local: Boolean indicating whether the formatted comment will be displayed on the page it is about (e.g. in a diff view). When true, links to sections or other anchors should typically only contain the fragment, not the path or query part of the URL.
- $wikiId: The wiki ID of the wiki the comment belongs to.
The hook was added in MW 1.20 but the signature was significantly changed in 1.25.
Note that $pre
and $post
are the opposite of what one might expect. Before 1.25 these held the part of the comment before / after the autocomment; now they just say whether the part before / after the autocomment exists.