From: Dietmar Maurer Date: Mon, 17 Oct 2016 08:06:39 +0000 (+0200) Subject: pvedocs-include.php: avoid to use javascript X-Git-Url: https://git.proxmox.com/?p=pve-docs.git;a=commitdiff_plain;h=208f75bc96cef33decf0df8a33c8af8a36a04246;hp=349e8c55b51b369c5c7d7e49c6febdecade46fb3 pvedocs-include.php: avoid to use javascript Use a ParserAfterTidy hook to avoid JS. This hack was found in the htmlet tag extension. --- diff --git a/debian/tree/pve-docs-mediawiki/pvedocs-include.php b/debian/tree/pve-docs-mediawiki/pvedocs-include.php index 7f75b5a..07ccf1c 100644 --- a/debian/tree/pve-docs-mediawiki/pvedocs-include.php +++ b/debian/tree/pve-docs-mediawiki/pvedocs-include.php @@ -4,26 +4,37 @@ $wgExtensionCredits['parserhook'][] = array( 'name' => "PVE Documentation Pages", - 'description' => "Display PVE Documentation Pages", + 'description' => "Display PVE Documentation Pages", 'author' => "Dietmar Maurer", ); - + # Define a setup function $wgHooks['ParserFirstCallInit'][] = 'efPvedocsParserFunction_Setup'; +$wgHooks['ParserAfterTidy'][] = 'efPvedocsPostProcessFunction'; # 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' ); + $parser->setFunctionHook('pvedocs', 'efPvedocsParserFunction_Render'); - $parser->setHook('pvehide', 'renderTagPveHideContent' ); + $parser->setHook('pvehide', 'renderTagPveHideContent'); return true; } +# similar code as in tag... +function efPvedocsPostProcessFunction($parser, &$text) { + $text = preg_replace_callback( + '/<--- @PVEDOCSHACK@ ([0-9a-zA-Z\\+\\/]+=*) @PVEDOCSHACK@ -->/sm', + function ($m) { return base64_decode("$m[1]"); }, + $text); + + return true; +} + // Render function renderTagPveHideContent($input, array $args, Parser $parser, PPFrame $frame ) { @@ -31,7 +42,7 @@ PPFrame $frame ) { return ''; } - + function efPvedocsParserFunction_Magic(&$magicWords, $langCode) { # Add the magic word # The first array element is whether to be case sensitive, @@ -43,11 +54,6 @@ function efPvedocsParserFunction_Magic(&$magicWords, $langCode) { 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(); @@ -56,25 +62,12 @@ function efPvedocsParserFunction_Render($parser, $param1 = '', $param2 = '') { # 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"); - $output = "\n"; - - # hack to inject html without modifications my mediawiki parser - $encHtml = encodeURI($content); - $output .= "
"; - $output .= ""; - - return array($output, 'noparse' => true, 'isHTML' => true); + $output = '<--- @PVEDOCSHACK@ '.base64_encode($content).' @PVEDOCSHACK@ -->'; + return array($output, 'noparse' => true, 'isHTML' => true); } ?>