]>
Commit | Line | Data |
---|---|---|
b18ac5f8 DM |
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( | |
d77877bc | 39 | 'dab.1.html' => 1, |
0f7ebb09 DM |
40 | 'pvecm.1.html' => 1, |
41 | 'qm.1.html' => 1, | |
42 | 'datacenter.cfg.5.html' => 1, | |
43 | 'vm.conf.5.html' => 1, | |
44 | 'ha-manager.1.html' => 1, | |
45 | 'pct.1.html' => 1, | |
46 | 'pct.conf.5.html' => 1, | |
47 | 'pve-firewall.8.html' => 1, | |
48 | 'pveceph.1.html' => 1, | |
49 | 'pvesm.1.html' => 1, | |
50 | 'pvesubscription.1.html' => 1, | |
51 | 'pveum.1.html' => 1, | |
52 | 'qmrestore.1.html' => 1, | |
53 | 'vzdump.1.html' => 1, | |
54 | ); | |
b18ac5f8 DM |
55 | |
56 | if (!$allowed[$param1]) { | |
57 | die ("no such manual page"); | |
58 | } | |
59 | ||
60 | $output = file_get_contents("/usr/share/pve2-api-doc/man/$param1"); | |
61 | ||
62 | $output = preg_replace('|^.*(<h1><a name="name">NAME</a></h1>)|s', '\1', $output); | |
63 | $output = preg_replace('|</body>.*$|s', '', $output); | |
64 | $output = preg_replace('|<p>\s*\n\s*</p>\n?|m', '', $output); | |
65 | $output = preg_replace('|<hr\s*/>\n?|', '', $output); | |
66 | $output = preg_replace('|^\n|m', '', $output); | |
67 | ||
68 | return array( $output, 'noparse' => true, 'isHTML' => true ); | |
69 | } | |
70 | ||
71 | ?> |