Extension:HTMLets
HTMLets Release status: stable |
|||
---|---|---|---|
Implementation | Tag | ||
Description | Lets you inline HTML snippets from files | ||
Author(s) | Daniel Kinzler (DuesentriebTalk) | ||
Last version | continuous updates | ||
MediaWiki | 1.9+ | ||
Database changes | no | ||
License | GPL v2 or later | ||
Download |
Download snapshot
Git [?]: repo summary • tree • code changes SVN [?]: checkout-url • tree • code changes README CHANGELOG |
||
|
|||
|
|||
|
|||
Check usage (experimental) |
The HTMLets extension provides a way to include (inline) static HTML snippets into wiki pages without changing the default setting of $wgRawHtml. Snippets are located in files in a special directory on the web server. This addresses the demand for a simple way to insert special JavaScript code, an <iframe>, or an HTML form, without allowing users to insert arbitrary and potentially harmful code.
Including a HTML snippets is done using a special tag, <htmlet>. For example, if you put this on a wiki page:
<htmlet>foobar</htmlet>
This will include the contents of the file foobar.html from the htmlet directory. If the snippet may change often, and you want those changes reflected on the wiki page right away, you can tell HTMLets to disable the parser cache for this page:
<htmlet nocache="yes">foobar</htmlet>
The htmlet directory can be configured using $wgHTMLetsDirectory; it defaults to "$IP/htmlets", i.e. the directory htmlets in the installation root of MediaWiki. $wgHTMLetsDirectory may also refer to a place on a webserver, for example, you can set it to http://localhost/htmlets/, if you provide htmlets in that location - note that the .html ending is enforced, query strings are not allowed in the htmlet's name.
[edit] Installation
- Download the files from SVN or download a snapshot (select your version of MediaWiki)
- Create a directory
HTMLets
in the$IP/extensions
directory of your MediaWiki installation - Extract the files to this
$IP/extensions/HTMLets
directory - Add to the end of LocalSettings.php:
require_once("$IP/extensions/HTMLets/HTMLets.php");
$wgHTMLetsDirectory = "$IP/htmlets"; - Installation can now be verified through Special:Version on your wiki
[edit] Parser issues and hacks
Currently, the mediawiki parser doesn't leave the output of parser hooks alone as it should (bugzilla:8997). This means that the HTML from your snipped file would be mangled under some circumstances (for example, if it contained indented or blank lines).
As of revision 19966, HTMLets works around this by supplying "hack modes". Which hack is applied can be controlled using the hack attribute for the <htmlet> tag, the global default can be set using the $wgHTMLetsHack setting in LocalSettings.php. The following values are defined (the first is the name to use with the hack attribute, the second is the constant name to use in LocalSettings.php):
- "bypass" (HTMLETS_BYPASS_HACK)
- should work safely; Works by outputting a Base64 encoded version of the HTML from your snippet file, and then decoding it an ParserAfterTidy hook. This is the default.
- "strip" (HTMLETS_STRIP_HACK)
- strip or encode anything that might trigger mangling. This will break any <pre> formatted text, and might also interfere with JavaScript code under some circumstances.
- "none" (HTMLETS_NO_HACK)
- just leave the content of the snippet file to the parser's mercy. In a perfect world, this should be fine. Right now, it will lead to unexpected results if you are not very careful not to trigger mangling. Known triggers are blank lines, and lines starting with blanks, "#", "*", ";", or ":". Blanks before a colon (":") anywhere in the line are also a problem. The cases mentioned here are the ones handled by HTMLETS_STRIP_HACK. There may be others, and the parser's behavior might change.
[edit] See also
- Extension:RawMsg - similar, uses system messages
- Extension:SecureHTML
- Extension:SecureWidgets
- Extension:Widgets
Language: | English • 日本語 |
---|