]>
git.proxmox.com Git - pve-docs.git/blob - pve-docs-mediawiki-import.in
15 while (<main
::DATA
>) { $data_str .= $_; }
17 my $fileinfo = decode_json
($data_str);
19 my $config_fn = "/root/.pve-docs"; # format 'username:pw'
21 my $fh = IO
::File-
>new("$config_fn") ||
22 die "Please configure the mediawiki user/passswd in '$config_fn'\n";
24 my $api_url = "https://pve.proxmox.com/mediawiki/api.php";
29 my ($username, $passwd) = split(':', $config, 2);
31 my $mw = MediaWiki
::API-
>new();
32 $mw->{config
}->{api_url
} = $api_url;
35 $mw->login({ lgname
=> $username, lgpassword
=> $passwd })
36 || die $mw->{error
}->{code
} . ': ' . $mw->{error
}->{details
};
39 my ($pagename, $filename, $category) = @_;
41 print "update mediawiki page: $pagename\n";
43 my $ref = $mw->get_page( { title
=> $pagename } );
44 my $page = $ref->{'*'} || '';
46 my $pve_content = "<!-- Do not edit - this is autogenerated content -->\n";
48 $pve_content .= "{{#pvedocs:$filename}}\n";
49 $pve_content .= "[[Category:$category]]\n" if $category;
51 my $starttag = '<!--PVE_IMPORT_START_MARKER-->';
52 my $endtag = '<!--PVE_IMPORT_END_MARKER-->';
54 $pve_content .= "<pvehide>\n";
58 text_h
=> [ sub { $pve_content .= shift }, "text" ],
60 my $parser = HTML
::Parser-
>new(%$parser_opts);
61 $parser->ignore_elements(qw(script style));
63 my $fh = IO
::File-
>new("/usr/share/pve-docs/$filename", "r") or
64 die "unable to open file '$filename' - $!\n";
65 while (defined(my $line = <$fh>)) {
66 $parser->parse($line);
68 $pve_content .= "</pvehide>\n";
70 $pve_content =~ s/\s+$//gm;
74 if ($page =~ m/^(.*)$starttag\n.*\n$endtag\n?(.*)$/s) {
75 my ($top_content, $bottom_content) = ($1, $2);
77 $page .= "$starttag\n";
78 $page .= $pve_content;
79 $page .= "\n$endtag\n";
80 $page .= $bottom_content;
81 } elsif ($page =~ m/(.*)\{\{#pvedocs:.*?\}\}(.*)$/) {
83 my ($top_content, $bottom_content) = ($1, $2);
85 chomp $bottom_content;
87 $page .= "$starttag\n";
88 $page .= $pve_content;
89 $page .= "\n$endtag\n";
90 $page .= $bottom_content;
92 $page = "$starttag\n$pve_content\n$endtag\n$page";
95 my $timestamp = $ref->{timestamp
};
99 basetimestamp
=> $timestamp, # to avoid edit conflicts
104 die $mw->{error
}->{code
} . ': ' . $mw->{error
}->{details
};
107 my $cat_refdoc = "Reference Documentation";
111 foreach my $source (sort keys %{$fileinfo->{toplevel
}->{wiki
}}) {
112 my $title = $fileinfo->{titles
}->{wiki
}->{$source};
113 my $filename = $fileinfo->{outfile
}->{wiki
}->{$source} ||
114 die "found no file name mapping for '$source'";
116 my $path = "/usr/share/pve-docs/$filename";
117 die "no such file '$path'" if ! -f
$path;
119 update_page
($title, $filename, $cat_refdoc);
122 # also update 'Get support' page, because this is used since a long
123 # time and is referenced from outside
124 update_page
("Get support", 'getting-help-plain.html', 'HOWTO');