9 \[\[(!?) # directive open; 2: optional prefix
11 ( # 4: the parameters (including initial whitespace)
14 (?:[-\w]+=)? # named parameter key?
16 """.*?""" # triple-quoted value
18 "[^"]+" # single-quoted value
20 [^\s\]]+ # unquoted value
22 \s* # whitespace or end
25 *) # 0 or more parameters
26 \]\] # directive closed
29 sub handle_directive {
32 my $directive = shift;
36 return "${escape}[[${prefix}${directive}${args}]]"
38 if ($directive =~ m/^(if|more|table|template|toggleable)$/) {
39 $args =~ s{$regex}{handle_directive($1, $2, $3, $4)}eg;
41 return "[[!${directive}${args}]]"
44 sub prefix_directives {
46 if (! defined $setup) {
50 require IkiWiki::Setup;
51 require IkiWiki::Plugin::aggregate;
53 %config = IkiWiki::defaultconfig();
54 IkiWiki::Setup::load($setup);
55 IkiWiki::loadplugins();
56 IkiWiki::checkconfig();
60 error "ikiwiki has not built this wiki yet, cannot transition";
63 foreach my $page (values %pagesources) {
64 next unless defined pagetype($page) &&
65 -f $config{srcdir}."/".$page;
66 my $content=readfile($config{srcdir}."/".$page);
67 my $oldcontent=$content;
68 $content=~s{$regex}{handle_directive($1, $2, $3, $4)}eg;
69 if ($oldcontent ne $content) {
70 writefile($page, $config{srcdir}, $content);
78 # Note: No lockwiki here because ikiwiki already locks it
79 # before calling this.
80 if (! IkiWiki::oldloadindex()) {
81 die "failed to load index\n";
83 if (! IkiWiki::saveindex()) {
84 die "failed to save indexdb\n"
86 if (! IkiWiki::loadindex()) {
87 die "transition failed, cannot load new indexdb\n";
89 if (! unlink("$config{wikistatedir}/index")) {
90 die "unlink failed: $!\n";
97 eval q{use IkiWiki::UserInfo};
98 eval q{use Authen::Passphrase::BlowfishCrypt};
100 error("ikiwiki-transition hashpassword: failed to load Authen::Passphrase, passwords not hashed");
104 IkiWiki::loadplugin("passwordauth");
105 my $userinfo = IkiWiki::userinfo_retrieve();
106 foreach my $user (keys %{$userinfo}) {
107 if (ref $userinfo->{$user} &&
108 exists $userinfo->{$user}->{password} &&
109 length $userinfo->{$user}->{password} &&
110 ! exists $userinfo->{$user}->{cryptpassword}) {
111 IkiWiki::Plugin::passwordauth::setpassword($user, $userinfo->{$user}->{password});
116 sub aggregateinternal {
118 if (! defined $setup) {
122 require IkiWiki::Setup;
123 require IkiWiki::Plugin::aggregate;
125 %config = IkiWiki::defaultconfig();
126 IkiWiki::Setup::load($setup);
127 IkiWiki::checkconfig();
129 IkiWiki::Plugin::aggregate::migrate_to_internal();
134 if (! defined $setup) {
138 require IkiWiki::Setup;
140 %config = IkiWiki::defaultconfig();
141 IkiWiki::Setup::load($setup);
142 IkiWiki::checkconfig();
144 # unpack old-format wrappers setting into new fields
147 foreach my $wrapper (@{$config{wrappers}}) {
148 if ($wrapper->{cgi}) {
150 die "don't know what to do with second cgi wrapper ".$wrapper->{wrapper}."\n";
153 print "setting cgi_wrapper to ".$wrapper->{wrapper}."\n";
154 $config{cgi_wrapper}=$wrapper->{wrapper};
155 $config{cgi_wrappermode}=$wrapper->{wrappermode}
156 if exists $wrapper->{wrappermode};
158 elsif ($config{rcs}) {
160 die "don't know what to do with second rcs wrapper ".$wrapper->{wrapper}."\n";
163 print "setting $config{rcs}_wrapper to ".$wrapper->{wrapper}."\n";
164 $config{$config{rcs}."_wrapper"}=$wrapper->{wrapper};
165 $config{$config{rcs}."_wrappermode"}=$wrapper->{wrappermode}
166 if exists $wrapper->{wrappermode};
169 die "don't know what to do with wrapper ".$wrapper->{wrapper}."\n";
173 IkiWiki::Setup::dump($setup);
178 if (! defined $setup) {
182 require IkiWiki::Setup;
184 %config = IkiWiki::defaultconfig();
185 IkiWiki::Setup::load($setup);
186 IkiWiki::checkconfig();
188 eval q{use IkiWiki::UserInfo};
191 foreach my $field (qw{allowed_attachments locked_pages}) {
192 my $orig=$config{$field};
193 foreach my $admin (@{$config{adminuser}}) {
194 my $a=IkiWiki::userinfo_get($admin, $field);
195 if (defined $a && length $a &&
196 # might already have been moved
197 (! defined $orig || $a ne $orig)) {
198 if (defined $config{$field} &&
199 length $config{$field}) {
200 $config{$field}=IkiWiki::pagespec_merge($config{$field}, $a);
209 my %banned=map { $_ => 1 } @{$config{banned_users}}, IkiWiki::get_banned_users();
210 $config{banned_users}=[sort keys %banned];
212 IkiWiki::Setup::dump($setup);
217 IkiWiki::loadindex();
218 foreach my $page (keys %links) {
220 $l{$_}=1 foreach @{$links{$page}};
221 $links{$page}=[keys %l]
223 IkiWiki::saveindex();
229 if (! defined $dir) {
234 error("ikiwiki-transition: $dir does not exist");
237 $config{wikistatedir}=$dir."/.ikiwiki";
239 if (! -d $config{wikistatedir}) {
240 error("ikiwiki-transition: $config{wikistatedir} does not exist");
245 print STDERR "Usage: ikiwiki-transition type ...\n";
246 print STDERR "Currently supported transition subcommands:\n";
247 print STDERR "\tprefix_directives setupfile ...\n";
248 print STDERR "\taggregateinternal setupfile\n";
249 print STDERR "\tsetupformat setupfile\n";
250 print STDERR "\tmoveprefs setupfile\n";
251 print STDERR "\thashpassword srcdir\n";
252 print STDERR "\tindexdb srcdir\n";
253 print STDERR "\tdeduplinks srcdir\n";
257 usage() unless @ARGV;
260 if ($mode eq 'prefix_directives') {
261 prefix_directives(@ARGV);
263 elsif ($mode eq 'hashpassword') {
266 elsif ($mode eq 'indexdb') {
269 elsif ($mode eq 'aggregateinternal') {
270 aggregateinternal(@ARGV);
272 elsif ($mode eq 'setupformat') {
275 elsif ($mode eq 'moveprefs') {
278 elsif ($mode eq 'deduplinks') {
287 # A slightly modified version of the old loadindex function.
289 %oldrenderedfiles=%pagectime=();
290 if (! $config{rebuild}) {
291 %pagesources=%pagemtime=%oldlinks=%links=%depends=
292 %destsources=%renderedfiles=%pagecase=%pagestate=();
294 open (my $in, "<", "$config{wikistatedir}/index") || return;
300 foreach my $i (split(/ /, $_)) {
301 my ($item, $val)=split(/=/, $i, 2);
302 push @{$items{$item}}, decode_entities($val);
305 next unless exists $items{src}; # skip bad lines for now
307 my $page=pagename($items{src}[0]);
308 if (! $config{rebuild}) {
309 $pagesources{$page}=$items{src}[0];
310 $pagemtime{$page}=$items{mtime}[0];
311 $oldlinks{$page}=[@{$items{link}}];
312 $links{$page}=[@{$items{link}}];
313 $depends{$page}=$items{depends}[0] if exists $items{depends};
314 $destsources{$_}=$page foreach @{$items{dest}};
315 $renderedfiles{$page}=[@{$items{dest}}];
316 $pagecase{lc $page}=$page;
317 foreach my $k (grep /_/, keys %items) {
318 my ($id, $key)=split(/_/, $k, 2);
319 $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
322 $oldrenderedfiles{$page}=[@{$items{dest}}];
323 $pagectime{$page}=$items{ctime}[0];
326 # saveindex relies on %hooks being populated, else it won't save
327 # the page state owned by a given hook. But no plugins are loaded
328 # by this program, so populate %hooks with all hook ids that
329 # currently have page state.
330 foreach my $page (keys %pagemtime) {
331 foreach my $id (keys %{$pagestate{$page}}) {
332 $hooks{_dummy}{$id}=1;
339 # Used to be in IkiWiki/UserInfo, but only used here now.
340 sub get_banned_users () {
342 my $userinfo=userinfo_retrieve();
343 foreach my $user (keys %{$userinfo}) {
344 push @ret, $user if $userinfo->{$user}->{banned};