]> git.proxmox.com Git - pve-docs.git/blob - debian/tree/pve-docs-mediawiki/pvedocs-include.php
f8d62d42d9ea0d5f0d4ecc4095d93e3c3ac2bf8f
[pve-docs.git] / debian / tree / pve-docs-mediawiki / pvedocs-include.php
1 <?php
2
3 # see http://www.mediawiki.org/wiki/Manual:Parser_functions
4
5 $wgExtensionCredits['parserhook'][] = array(
6 'name' => "PVE Documentation Pages",
7 'description' => "Display PVE Documentation Pages",
8 'author' => "Dietmar Maurer",
9 );
10
11 # Define a setup function
12 $wgHooks['ParserFirstCallInit'][] = 'efPvedocsParserFunction_Setup';
13 $wgHooks['ParserAfterTidy'][] = 'efPvedocsPostProcessFunction';
14
15 # Add a hook to initialise the magic word
16 $wgHooks['LanguageGetMagic'][] = 'efPvedocsParserFunction_Magic';
17
18 function efPvedocsParserFunction_Setup(&$parser) {
19 # Set a function hook associating the "pvedocs" magic
20 # word with our function
21 $parser->setFunctionHook('pvedocs', 'efPvedocsParserFunction_Render');
22
23 $parser->setHook('pvehide', 'renderTagPveHideContent');
24
25 return true;
26 }
27
28 # similar code as in <htmlet> tag...
29 function efPvedocsPostProcessFunction($parser, &$text) {
30 $text = preg_replace_callback(
31 '/-_- @PVEDOCS_BASE64@ ([0-9a-zA-Z\\+\\/]+=*) @PVEDOCS_BASE64@ -_-/sm',
32 function ($m) { return base64_decode("$m[1]"); },
33 $text);
34
35 return true;
36 }
37
38 // Render <pvehide>
39 function renderTagPveHideContent($input, array $args, Parser $parser,
40 PPFrame $frame ) {
41 // simply return nothing
42 return '';
43 }
44
45
46 function efPvedocsParserFunction_Magic(&$magicWords, $langCode) {
47 # Add the magic word
48 # The first array element is whether to be case sensitive,
49 # in this case (0) it is not case sensitive, 1 would be sensitive
50 # All remaining elements are synonyms for our parser function
51 $magicWords['pvedocs'] = array( 0, 'pvedocs' );
52
53 # unless we return true, other parser functions extensions won't get loaded.
54 return true;
55 }
56
57 function efPvedocsParserFunction_Render($parser, $param1 = '', $param2 = '') {
58
59 $parser->disableCache();
60
61 # only allow simply names, so that users can only include
62 # files from within "/usr/share/pve-docs/"
63 if (!preg_match("/[a-z0-9.-]+\.html/i", $param1)) {
64 die("no such manual page");
65 }
66
67 $content = file_get_contents("/usr/share/pve-docs/$param1");
68
69 # do not use '<' or '>', it seems newer mediawiki converts it to '&lt;' and '&gt;'
70 # and then the regex for the decode in efPvedocsPostProcessFunction does not matches..
71 $output = '-_- @PVEDOCS_BASE64@ '.base64_encode($content).' @PVEDOCS_BASE64@ -_-';
72 return array($output, 'noparse' => true, 'isHTML' => true);
73 }
74
75 ?>