Manual:Hooks/ParserSectionCreate

From Linux Web Expert

ParserSectionCreate
<translate> Available from <tvar name=1><translate> version <tvar (r92506, codereview)</tvar></translate>
<translate> Removed in <tvar name=1><translate> version <tvar (Gerrit change 861504)</tvar></translate>
Called each time the parser creates a document section from wikitext.
<translate> Define function:</translate>
public static function onParserSectionCreate( $parser, $section, &$sectionContent, $showEditLinks ) { ... }
<translate> Attach hook:</translate> <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
	"Hooks": {
		"ParserSectionCreate": "MediaWiki\\Extension\\MyExtension\\Hooks::onParserSectionCreate"
	}
}
<translate> Called from:</translate> <translate> File(s):</translate> parser/Parser.php
<translate> Interface:</translate> ParserSectionCreateHook.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:ParserSectionCreate extensions</tvar>.</translate>


Details

Use this to apply per-section modifications to HTML (like wrapping the section in a DIV). Caveat: DIVs are valid wikitext, and a DIV can begin in one section and end in another. Make sure your code can handle that case gracefully.

  • $parser: the calling Parser instance.
  • $section: the section number, zero-based, but section 0 is usually empty.
  • &$sectionContent: ref to the content of the section. modify this.
  • $showEditLinks: boolean describing whether this section has an edit link.