Manual:Hooks/FormatAutocomments

From mediawiki.org
FormatAutocomments
Available from version 1.20.0
When an autocomment is formatted by the Linker.
Define function:
public static function onFormatAutocomments( &$comment, $pre, $auto, $post, $title, $local, $wikiId ) { ... }
Attach hook: In extension.json:
{
	"Hooks": {
		"FormatAutocomments": "MediaWiki\\Extension\\MyExtension\\Hooks::onFormatAutocomments"
	}
}
Called from: File(s): CommentFormatter/CommentParser.php
Interface: FormatAutocommentsHook.php

For more information about attaching hooks, see Manual:Hooks .
For examples of extensions using this hook, see Category:FormatAutocomments extensions.


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[edit]

  • &$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.