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 {
47 IkiWiki::loadplugins();
48 IkiWiki::checkconfig();
52 error "ikiwiki has not built this wiki yet, cannot transition";
55 foreach my $page (values %pagesources) {
56 next unless defined pagetype($page) &&
57 -f $config{srcdir}."/".$page;
58 my $content=readfile($config{srcdir}."/".$page);
59 my $oldcontent=$content;
60 $content=~s{$regex}{handle_directive($1, $2, $3, $4)}eg;
61 if ($oldcontent ne $content) {
62 writefile($page, $config{srcdir}, $content);
70 # Note: No lockwiki here because ikiwiki already locks it
71 # before calling this.
72 if (! IkiWiki::oldloadindex()) {
73 die "failed to load index\n";
75 if (! IkiWiki::saveindex()) {
76 die "failed to save indexdb\n"
78 if (! IkiWiki::loadindex()) {
79 die "transition failed, cannot load new indexdb\n";
81 if (! unlink("$config{wikistatedir}/index")) {
82 die "unlink failed: $!\n";
89 eval q{use IkiWiki::UserInfo};
90 eval q{use Authen::Passphrase::BlowfishCrypt};
92 error("ikiwiki-transition hashpassword: failed to load Authen::Passphrase, passwords not hashed");
96 IkiWiki::loadplugin("passwordauth");
97 my $userinfo = IkiWiki::userinfo_retrieve();
98 foreach my $user (keys %{$userinfo}) {
99 if (ref $userinfo->{$user} &&
100 exists $userinfo->{$user}->{password} &&
101 length $userinfo->{$user}->{password} &&
102 ! exists $userinfo->{$user}->{cryptpassword}) {
103 IkiWiki::Plugin::passwordauth::setpassword($user, $userinfo->{$user}->{password});
108 sub aggregateinternal {
110 require IkiWiki::Plugin::aggregate;
111 IkiWiki::checkconfig();
112 IkiWiki::Plugin::aggregate::migrate_to_internal();
119 IkiWiki::checkconfig();
121 # unpack old-format wrappers setting into new fields
124 foreach my $wrapper (@{$config{wrappers}}) {
125 if ($wrapper->{cgi}) {
127 die "don't know what to do with second cgi wrapper ".$wrapper->{wrapper}."\n";
130 print "setting cgi_wrapper to ".$wrapper->{wrapper}."\n";
131 $config{cgi_wrapper}=$wrapper->{wrapper};
132 $config{cgi_wrappermode}=$wrapper->{wrappermode}
133 if exists $wrapper->{wrappermode};
135 elsif ($config{rcs}) {
137 die "don't know what to do with second rcs wrapper ".$wrapper->{wrapper}."\n";
140 print "setting $config{rcs}_wrapper to ".$wrapper->{wrapper}."\n";
141 $config{$config{rcs}."_wrapper"}=$wrapper->{wrapper};
142 $config{$config{rcs}."_wrappermode"}=$wrapper->{wrappermode}
143 if exists $wrapper->{wrappermode};
146 die "don't know what to do with wrapper ".$wrapper->{wrapper}."\n";
150 IkiWiki::Setup::dump($setup);
157 IkiWiki::checkconfig();
159 eval q{use IkiWiki::UserInfo};
162 foreach my $field (qw{allowed_attachments locked_pages}) {
163 my $orig=$config{$field};
164 foreach my $admin (@{$config{adminuser}}) {
165 my $a=IkiWiki::userinfo_get($admin, $field);
166 if (defined $a && length $a &&
167 # might already have been moved
168 (! defined $orig || $a ne $orig)) {
169 if (defined $config{$field} &&
170 length $config{$field}) {
171 $config{$field}=IkiWiki::pagespec_merge($config{$field}, $a);
180 my %banned=map { $_ => 1 } @{$config{banned_users}}, IkiWiki::get_banned_users();
181 $config{banned_users}=[sort keys %banned];
183 IkiWiki::Setup::dump($setup);
188 IkiWiki::loadindex();
189 foreach my $page (keys %links) {
191 $l{$_}=1 foreach @{$links{$page}};
192 $links{$page}=[keys %l]
194 IkiWiki::saveindex();
198 my $dirorsetup=shift;
200 if (! defined $dirorsetup) {
204 if (-d $dirorsetup) {
205 $config{wikistatedir}=$dirorsetup."/.ikiwiki";
207 elsif (-f $dirorsetup) {
208 loadsetup($dirorsetup);
211 error("ikiwiki-transition: $dirorsetup does not exist");
214 if (! -d $config{wikistatedir}) {
215 error("ikiwiki-transition: $config{wikistatedir} does not exist");
221 if (! defined $setup) {
225 require IkiWiki::Setup;
227 %config = IkiWiki::defaultconfig();
228 IkiWiki::Setup::load($setup);
232 print STDERR "Usage: ikiwiki-transition type ...\n";
233 print STDERR "Currently supported transition subcommands:\n";
234 print STDERR "\tprefix_directives setupfile ...\n";
235 print STDERR "\taggregateinternal setupfile\n";
236 print STDERR "\tsetupformat setupfile\n";
237 print STDERR "\tmoveprefs setupfile\n";
238 print STDERR "\thashpassword setupfile|srcdir\n";
239 print STDERR "\tindexdb setupfile|srcdir\n";
240 print STDERR "\tdeduplinks setupfile|srcdir\n";
244 usage() unless @ARGV;
247 if ($mode eq 'prefix_directives') {
248 prefix_directives(@ARGV);
250 elsif ($mode eq 'hashpassword') {
253 elsif ($mode eq 'indexdb') {
256 elsif ($mode eq 'aggregateinternal') {
257 aggregateinternal(@ARGV);
259 elsif ($mode eq 'setupformat') {
262 elsif ($mode eq 'moveprefs') {
265 elsif ($mode eq 'deduplinks') {
274 # A slightly modified version of the old loadindex function.
276 %oldrenderedfiles=%pagectime=();
277 if (! $config{rebuild}) {
278 %pagesources=%pagemtime=%oldlinks=%links=%depends=
279 %destsources=%renderedfiles=%pagecase=%pagestate=();
281 open (my $in, "<", "$config{wikistatedir}/index") || return;
287 foreach my $i (split(/ /, $_)) {
288 my ($item, $val)=split(/=/, $i, 2);
289 push @{$items{$item}}, decode_entities($val);
292 next unless exists $items{src}; # skip bad lines for now
294 my $page=pagename($items{src}[0]);
295 if (! $config{rebuild}) {
296 $pagesources{$page}=$items{src}[0];
297 $pagemtime{$page}=$items{mtime}[0];
298 $oldlinks{$page}=[@{$items{link}}];
299 $links{$page}=[@{$items{link}}];
300 $depends{$page}=$items{depends}[0] if exists $items{depends};
301 $destsources{$_}=$page foreach @{$items{dest}};
302 $renderedfiles{$page}=[@{$items{dest}}];
303 $pagecase{lc $page}=$page;
304 foreach my $k (grep /_/, keys %items) {
305 my ($id, $key)=split(/_/, $k, 2);
306 $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
309 $oldrenderedfiles{$page}=[@{$items{dest}}];
310 $pagectime{$page}=$items{ctime}[0];
313 # saveindex relies on %hooks being populated, else it won't save
314 # the page state owned by a given hook. But no plugins are loaded
315 # by this program, so populate %hooks with all hook ids that
316 # currently have page state.
317 foreach my $page (keys %pagemtime) {
318 foreach my $id (keys %{$pagestate{$page}}) {
319 $hooks{_dummy}{$id}=1;
326 # Used to be in IkiWiki/UserInfo, but only used here now.
327 sub get_banned_users () {
329 my $userinfo=userinfo_retrieve();
330 foreach my $user (keys %{$userinfo}) {
331 push @ret, $user if $userinfo->{$user}->{banned};