]> git.proxmox.com Git - pve2-api-doc.git/blob - data/pve-man-include.php
imported from svn 'pve2-api-doc/trunk'
[pve2-api-doc.git] / data / pve-man-include.php
1 <?php
2
3 # see http://www.mediawiki.org/wiki/Manual:Parser_functions
4
5 $wgExtensionCredits['parserhook'][] = array(
6 'name' => "PVE Manual Pages",
7 'description' => "Display PVE manual pages",
8 'author' => "Dietmar Maurer",
9 );
10
11 # Define a setup function
12 $wgHooks['ParserFirstCallInit'][] = 'efPvemanParserFunction_Setup';
13 # Add a hook to initialise the magic word
14 $wgHooks['LanguageGetMagic'][] = 'efPvemanParserFunction_Magic';
15
16 function efPvemanParserFunction_Setup( &$parser ) {
17 # Set a function hook associating the "pveman" magic word with our function
18 $parser->setFunctionHook( 'pveman', 'efPvemanParserFunction_Render' );
19 return true;
20 }
21
22 function efPvemanParserFunction_Magic( &$magicWords, $langCode ) {
23 # Add the magic word
24 # The first array element is whether to be case sensitive, in this case (0) it is not case sensitive, 1 would be sensitive
25 # All remaining elements are synonyms for our parser function
26 $magicWords['pveman'] = array( 0, 'pveman' );
27 # unless we return true, other parser functions extensions won't get loaded.
28 return true;
29 }
30
31 function efPvemanParserFunction_Render( $parser, $param1 = '', $param2 = '' ) {
32 # The parser function itself
33 # The input parameters are wikitext with templates expanded
34 # The output should be wikitext too
35
36 $parser->disableCache();
37
38 $allowed = array(
39 'pvecm.1.html' => 1,
40 'qm.1.html' => 1,
41 'datacenter.cfg.5.html' => 1,
42 'vm.conf.5.html' => 1,
43 );
44
45 if (!$allowed[$param1]) {
46 die ("no such manual page");
47 }
48
49 $output = file_get_contents("/usr/share/pve2-api-doc/man/$param1");
50
51 $output = preg_replace('|^.*(<h1><a name="name">NAME</a></h1>)|s', '\1', $output);
52 $output = preg_replace('|</body>.*$|s', '', $output);
53 $output = preg_replace('|<p>\s*\n\s*</p>\n?|m', '', $output);
54 $output = preg_replace('|<hr\s*/>\n?|', '', $output);
55 $output = preg_replace('|^\n|m', '', $output);
56
57 return array( $output, 'noparse' => true, 'isHTML' => true );
58 }
59
60 ?>