]> git.proxmox.com Git - pve-docs.git/blob - doc-debian/pvedocs-include.php
5fc53784a0b00341491ea97b3d7540b40578964e
[pve-docs.git] / doc-debian / pvedocs-include.php
1 <?php
2
3 # see http://www.mediawiki.org/wiki/Manual:Parser_functions
4
5 $wgExtensionCredits['parserhook'][] = array(
6 'name' => "PVE Documenation Pages",
7 'description' => "Display PVE Documentation Pages",
8 'author' => "Dietmar Maurer",
9 );
10
11 # Define a setup function
12 $wgHooks['ParserFirstCallInit'][] = 'efPvedocsParserFunction_Setup';
13
14 # Add a hook to initialise the magic word
15 $wgHooks['LanguageGetMagic'][] = 'efPvedocsParserFunction_Magic';
16
17 function efPvedocsParserFunction_Setup(&$parser) {
18 # Set a function hook associating the "pvedocs" magic
19 # word with our function
20 $parser->setFunctionHook( 'pvedocs', 'efPvedocsParserFunction_Render' );
21 return true;
22 }
23
24 function efPvedocsParserFunction_Magic(&$magicWords, $langCode) {
25 # Add the magic word
26 # The first array element is whether to be case sensitive,
27 # in this case (0) it is not case sensitive, 1 would be sensitive
28 # All remaining elements are synonyms for our parser function
29 $magicWords['pvedocs'] = array( 0, 'pvedocs' );
30
31 # unless we return true, other parser functions extensions won't get loaded.
32 return true;
33 }
34
35 function encodeURI($uri) {
36 return preg_replace_callback("{[^0-9a-z_.!~*'();,/?:@&=+$#-]}i",
37 function ($m) { return sprintf('%%%02X', ord($m[0])); }, $uri);
38 }
39
40 function efPvedocsParserFunction_Render($parser, $param1 = '', $param2 = '') {
41
42 $parser->disableCache();
43
44 # only allow simply names, so that users can only include
45 # files from within "/usr/share/pve-docs/"
46 if (!preg_match("/[a-z0-9.-]+\.html/i", $param1)) {
47 die("no such manual page");
48 }
49
50 $content = file_get_contents("/usr/share/pve-docs/$param1");
51
52 $output = "<noscript><div><p>" .
53 "This page requires java-script. To view " .
54 "this page without java-script goto " .
55 "<a href='/pve-docs/$param1'>$param1</a>" .
56 "</div></noscript>\n";
57
58 # hack to inject html without modifications my mediawiki parser
59 $encHtml = encodeURI($content);
60 $output .= "<div id='pve_embed_data'></div>";
61 $output .= "<script>" .
62 "var data = decodeURI(\"".$encHtml."\");" .
63 "document.getElementById('pve_embed_data').innerHTML = data;" .
64 "</script>";
65
66 return array($output, 'noparse' => true, 'isHTML' => true);
67 }
68
69 ?>