]> git.proxmox.com Git - pve-docs.git/blame - debian/tree/pve-docs-mediawiki/PVEDocs/include/PVEDocs.php
mediawiki: transform into new-style add-on
[pve-docs.git] / debian / tree / pve-docs-mediawiki / PVEDocs / include / PVEDocs.php
CommitLineData
51b09382
TL
1<?php
2// see http://www.mediawiki.org/wiki/Manual:Parser_functions
3
4class PVEDocs {
5 public static function onParserFirstCallInit(Parser $parser ) {
6 $parser->setFunctionHook('pvedocs', [ self::class, 'efPvedocsParserFunction_Render' ]);
7 $parser->setHook('pvehide', [ self::class, 'renderTagPveHideContent' ]);
8
9 return true;
10 }
11
12 // similar code as in <htmlet> tag...
13 public static function efPvedocsPostProcessFunction($parser, &$text) {
14 $text = preg_replace_callback(
15 '/<!--- @PVEDOCS_BASE64@ ([0-9a-zA-Z\\+\\/]+=*) @PVEDOCS_BASE64@ -->/sm',
16 function ($m) { return base64_decode("$m[1]"); },
17 $text
18 );
19 return true;
20 }
21
22 // "Render" <pvehide>
23 public static function renderTagPveHideContent($input, array $args, Parser $parser, PPFrame $frame ) {
24 return ''; // simply return nothing
25 }
26
27
28 # Render the output of {{#pvedocs:chapter}}.
29 public static function efPvedocsParserFunction_Render(Parser $parser, $doc = '') {
30 $parser->getOutput()->updateCacheExpiry(0); // disableCache() was dropped in MW 1.34
31
32 // only allow simple names, so that jist files from within "/usr/share/pve-docs/" can be included
33 if (!preg_match("/[a-z0-9.-]+\.html/i", $doc)) {
34 die("no such manual page");
35 }
36
37 $content = file_get_contents("/usr/share/pve-docs/$doc");
38
39 // from https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/HTMLets/+/11e5ef1ea2820319458dc67174ca76d6e00b10cc/HTMLets.php#140
40 $output = '<!--- @PVEDOCS_BASE64@ '.base64_encode($content).' @PVEDOCS_BASE64@ -->';
41 return array($output, 'noparse' => true, 'isHTML' => true);
42 }
43}