]> git.proxmox.com Git - pve-docs.git/blob - debian/tree/pve-docs-mediawiki/pvedocs-include.php
fix typo
[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
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
22 $parser->setHook('pvehide', 'renderTagPveHideContent' );
23
24 return true;
25 }
26
27 // Render <pvehide>
28 function renderTagPveHideContent($input, array $args, Parser $parser,
29 PPFrame $frame ) {
30 // simply return nothing
31 return '';
32 }
33
34
35 function efPvedocsParserFunction_Magic(&$magicWords, $langCode) {
36 # Add the magic word
37 # The first array element is whether to be case sensitive,
38 # in this case (0) it is not case sensitive, 1 would be sensitive
39 # All remaining elements are synonyms for our parser function
40 $magicWords['pvedocs'] = array( 0, 'pvedocs' );
41
42 # unless we return true, other parser functions extensions won't get loaded.
43 return true;
44 }
45
46 function encodeURI($uri) {
47 return preg_replace_callback("{[^0-9a-z_.!~*'();,/?:@&=+$#-]}i",
48 function ($m) { return sprintf('%%%02X', ord($m[0])); }, $uri);
49 }
50
51 function efPvedocsParserFunction_Render($parser, $param1 = '', $param2 = '') {
52
53 $parser->disableCache();
54
55 # only allow simply names, so that users can only include
56 # files from within "/usr/share/pve-docs/"
57 if (!preg_match("/[a-z0-9.-]+\.html/i", $param1)) {
58 die("no such manual page");
59 }
60
61 $content = file_get_contents("/usr/share/pve-docs/$param1");
62
63 $output = "<noscript><div><p>" .
64 "This page requires java-script. To view " .
65 "this page without java-script goto " .
66 "<a href='/pve-docs/$param1'>$param1</a>" .
67 "</div></noscript>\n";
68
69 # hack to inject html without modifications my mediawiki parser
70 $encHtml = encodeURI($content);
71 $output .= "<div id='pve_embed_data'></div>";
72 $output .= "<script>" .
73 "var data = decodeURI(\"".$encHtml."\");" .
74 "document.getElementById('pve_embed_data').innerHTML = data;" .
75 "</script>";
76
77 return array($output, 'noparse' => true, 'isHTML' => true);
78 }
79
80 ?>