]> git.proxmox.com Git - pve-docs.git/blobdiff - debian/tree/pve-docs-mediawiki/pvedocs-include.php
mediawiki: bring doc includer again in line with the HTMLets plug it bases on
[pve-docs.git] / debian / tree / pve-docs-mediawiki / pvedocs-include.php
index 6a37f9aa98770335c1f7d7237b86ae6e63a7d992..78a6829ffea7e6279d2136e2a1b77c1718fe33d9 100644 (file)
@@ -4,34 +4,45 @@
 
 $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 <htmlet> tag...
+function efPvedocsPostProcessFunction($parser, &$text) {
+       $text = preg_replace_callback(
+               '/<!--- @PVEDOCS_BASE64@ ([0-9a-zA-Z\\+\\/]+=*) @PVEDOCS_BASE64@ -->/sm',
+               function ($m) { return base64_decode("$m[1]"); },
+               $text);
+
+       return true;
+}
+
 // Render <pvehide>
 function renderTagPveHideContent($input, array $args, Parser $parser,
 PPFrame $frame ) {
-    // simpry return nothing
+    // simply return nothing
     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,13 @@ 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 = "<noscript><div><p>" .
-        "This page requires java-script. To view " .
-        "this page without java-script goto " .
-        "<a href='/pve-docs/$param1'>$param1</a>" .
-        "</div></noscript>\n";
-
-       # hack to inject html without modifications my mediawiki parser
-       $encHtml = encodeURI($content);
-       $output .= "<div id='pve_embed_data'></div>";
-       $output .= "<script>" .
-        "var data = decodeURI(\"".$encHtml."\");" .
-        "document.getElementById('pve_embed_data').innerHTML = data;" .
-        "</script>";
-       
-       return array($output, 'noparse' => true, 'isHTML' => true);
+    # from https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/HTMLets/+/11e5ef1ea2820319458dc67174ca76d6e00b10cc/HTMLets.php#140
+    $output = '<!--- @PVEDOCS_BASE64@ '.base64_encode($content).' @PVEDOCS_BASE64@ -->';
+    return array($output, 'noparse' => true, 'isHTML' => true);
 }
 
 ?>