]>
git.proxmox.com Git - pve-docs.git/blob - debian/tree/pve-docs-mediawiki/pvedocs-include.php
3 # see http://www.mediawiki.org/wiki/Manual:Parser_functions
5 $wgExtensionCredits['parserhook'][] = array(
6 'name' => "PVE Documentation Pages",
7 'description' => "Display PVE Documentation Pages",
8 'author' => "Dietmar Maurer",
11 # Define a setup function
12 $wgHooks['ParserFirstCallInit'][] = 'efPvedocsParserFunction_Setup';
14 # Add a hook to initialise the magic word
15 $wgHooks['LanguageGetMagic'][] = 'efPvedocsParserFunction_Magic';
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' );
22 $parser->setHook('pvehide', 'renderTagPveHideContent' );
28 function renderTagPveHideContent($input, array $args, Parser
$parser,
30 // simply return nothing
35 function efPvedocsParserFunction_Magic(&$magicWords, $langCode) {
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' );
42 # unless we return true, other parser functions extensions won't get loaded.
46 function encodeURI($uri) {
47 return preg_replace_callback("{[^0-9a-z_.!~*'();,/?:@&=+$#-]}i",
48 function ($m) { return sprintf('%%%02X', ord($m[0])); }, $uri);
51 function efPvedocsParserFunction_Render($parser, $param1 = '', $param2 = '') {
53 $parser->disableCache();
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");
61 $content = file_get_contents("/usr/share/pve-docs/$param1");
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";
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;" .
77 return array($output, 'noparse' => true, 'isHTML' => true);