X-Git-Url: https://git.proxmox.com/?p=pve-docs.git;a=blobdiff_plain;f=doc-debian%2Fpvedocs-include.php;fp=doc-debian%2Fpvedocs-include.php;h=f039a3c0dfa9ac04283c3cd4078d3db1cb0e5854;hp=0000000000000000000000000000000000000000;hb=0e25828e13c1ab2cd8725f01608758ff3aa41465;hpb=b74af7b618785743b85cb86b7bb6e5341bd2d3ef diff --git a/doc-debian/pvedocs-include.php b/doc-debian/pvedocs-include.php new file mode 100644 index 0000000..f039a3c --- /dev/null +++ b/doc-debian/pvedocs-include.php @@ -0,0 +1,63 @@ + "PVE Documenation Pages", + 'description' => "Display PVE Documentation Pages", + 'author' => "Dietmar Maurer", +); + +# Define a setup function +$wgHooks['ParserFirstCallInit'][] = 'efPvedocsParserFunction_Setup'; + +# Add a hook to initialise the magic word +$wgHooks['LanguageGetMagic'][] = 'efPvedocsParserFunction_Magic'; + +function efPvedocsParserFunction_Setup(&$parser) { + # Set a function hook associating the "pvedocs" magic + # word with our function + $parser->setFunctionHook( 'pvedocs', 'efPvedocsParserFunction_Render' ); + return true; +} + +function efPvedocsParserFunction_Magic(&$magicWords, $langCode) { + # Add the magic word + # The first array element is whether to be case sensitive, + # in this case (0) it is not case sensitive, 1 would be sensitive + # All remaining elements are synonyms for our parser function + $magicWords['pvedocs'] = array( 0, 'pvedocs' ); + + # unless we return true, other parser functions extensions won't get loaded. + return true; +} + +function encodeURI($uri) { + return preg_replace_callback("{[^0-9a-z_.!~*'();,/?:@&=+$#-]}i", + function ($m) { return sprintf('%%%02X', ord($m[0])); }, $uri); +} + +function efPvedocsParserFunction_Render($parser, $param1 = '', $param2 = '') { + + $parser->disableCache(); + + # only allow simply names, so that users can only include + # files from within "/usr/share/pve-docs/" + if (!preg_match("/[a-z0-9.-]+\.html/i", $param1)) { + die("no such manual page"); + } + + $content = file_get_contents("/usr/share/pve-docs/$param1"); + + # hack to inject html without modifications my mediawiki parser + $encHtml = encodeURI($content); + $output .= "
"; + $output .= ""; + + return array($output, 'noparse' => true, 'isHTML' => true); +} + +?>