Movatterモバイル変換


[0]ホーム

URL:


Jump to content
MediaWiki
Search

Manual:Hooks/BeforePageDisplay

From mediawiki.org
<Manual:Hooks
If you are adding JavaScript or CSS to the page please consider usingOutputPageBeforeHTML so that your modules also get added to API responses.
BeforePageDisplay
Available from version 1.7.0 (r14420,CodeReview archive)
Allows last minute changes to the output page, e.g. adding of CSS or JavaScript by extensions.
Define function:
publicstaticfunctiononBeforePageDisplay(MediaWiki\Output\OutputPage$out,Skin$skin){...}
Attach hook:Inextension.json:
{"Hooks":{"BeforePageDisplay":"MediaWiki\\Extension\\MyExtension\\Hooks::onBeforePageDisplay"}}
Called from:File(s):Output/OutputPage.php
Function(s):output
Interface:BeforePageDisplayHook.php

For more information about attaching hooks, seeManual:Hooks.
For examples of extensions using this hook, seeCategory:BeforePageDisplay extensions.

Details

[edit]
  • This hook was in SkinTemplate.php until version 1.12.0
  • $out - The OutputPage object.
  • $skin - Skin object that will be used to generate the page, added in 1.13.

Usage

[edit]

Scripts, styles, and other header elements can be added to the OutputObject at this point.

  • $out->addMeta($name,$value) - Add a‎<meta> tag.
MediaWiki version:
1.17

For adding scripts and styles on MediaWiki 1.17 and above, useResourceLoader modules.

  • $out->addModules([/*modules*/]) - For modules with both scripts and styles
  • $out->addModuleStyles([/*modules*/]) - For modules with styles only
MediaWiki version:
1.16

For adding scripts and styles on MediaWiki 1.16 and below:

  • $out->addScriptFile($path) - Add a JS file. $path is the path to the JS file, such as$wgScriptPath/extensions/MyExtension/MyCoolScript.js
  • $out->addScript($html) - Add a JS file. $html is a full script tag:'<script type="text/javascript" src="..."></script>'
  • $out->addStyle($src) - Add a CSS file. $src is a URL to a stylesheet.
  • $out->addInlineScript($script) - Add inline JS.
  • $out->addLink($title,$id) - Add a link for the keyword‎<link> tag.

See also

[edit]
Retrieved from "https://www.mediawiki.org/w/index.php?title=Manual:Hooks/BeforePageDisplay&oldid=7855550"
Categories:

[8]ページ先頭

©2009-2025 Movatter.jp