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 {
45 $/=undef; # process whole files at once
48 s{$regex}{handle_directive($1, $2, $3, $4)}eg;
58 $config{wikistatedir}=$dir."/.ikiwiki";
60 # Note: No lockwiki here because ikiwiki already locks it
61 # before calling this.
62 if (! IkiWiki::oldloadindex()) {
63 die "failed to load index\n";
65 if (! IkiWiki::saveindex()) {
66 die "failed to save indexdb\n"
68 if (! IkiWiki::loadindex()) {
69 die "transition failed, cannot load new indexdb\n";
71 if (! unlink("$config{wikistatedir}/index")) {
72 die "unlink failed: $!\n";
81 $config{wikistatedir}=$dir."/.ikiwiki";
83 eval q{use IkiWiki::UserInfo};
84 eval q{use Authen::Passphrase::BlowfishCrypt};
86 error("ikiwiki-transition hashpassword: failed to load Authen::Passphrase, passwords not hashed");
90 IkiWiki::loadplugin("passwordauth");
91 my $userinfo = IkiWiki::userinfo_retrieve();
92 foreach my $user (keys %{$userinfo}) {
93 if (ref $userinfo->{$user} &&
94 exists $userinfo->{$user}->{password} &&
95 length $userinfo->{$user}->{password} &&
96 ! exists $userinfo->{$user}->{cryptpassword}) {
97 IkiWiki::Plugin::passwordauth::setpassword($user, $userinfo->{$user}->{password});
102 sub aggregateinternal {
104 if (! defined $setup) {
108 require IkiWiki::Setup;
109 require IkiWiki::Plugin::aggregate;
111 %config = IkiWiki::defaultconfig();
112 IkiWiki::Setup::load();
113 IkiWiki::checkconfig();
115 IkiWiki::Plugin::aggregate::migrate_to_internal();
120 if (! defined $setup) {
124 require IkiWiki::Setup;
126 %config = IkiWiki::defaultconfig();
127 IkiWiki::Setup::load($setup);
128 IkiWiki::checkconfig();
130 # unpack old-format wrappers setting into new fields
133 foreach my $wrapper (@{$config{wrappers}}) {
134 if ($wrapper->{cgi}) {
136 die "don't know what to do with second cgi wrapper ".$wrapper->{wrapper}."\n";
139 print "setting cgi_wrapper to ".$wrapper->{wrapper}."\n";
140 $config{cgi_wrapper}=$wrapper->{wrapper};
141 $config{cgi_wrappermode}=$wrapper->{wrappermode}
142 if exists $wrapper->{wrappermode};
144 elsif ($config{rcs}) {
146 die "don't know what to do with second rcs wrapper ".$wrapper->{wrapper}."\n";
149 print "setting $config{rcs}_wrapper to ".$wrapper->{wrapper}."\n";
150 $config{$config{rcs}."_wrapper"}=$wrapper->{wrapper};
151 $config{$config{rcs}."_wrappermode"}=$wrapper->{wrappermode}
152 if exists $wrapper->{wrappermode};
155 die "don't know what to do with wrapper ".$wrapper->{wrapper}."\n";
159 IkiWiki::Setup::dump($setup);
164 if (! defined $setup) {
168 require IkiWiki::Setup;
170 %config = IkiWiki::defaultconfig();
171 IkiWiki::Setup::load($setup);
172 IkiWiki::checkconfig();
174 eval q{use IkiWiki::UserInfo};
177 foreach my $field (qw{allowed_attachments locked_pages}) {
178 my $orig=$config{$field};
179 foreach my $admin (@{$config{adminuser}}) {
180 my $a=IkiWiki::userinfo_get($admin, $field);
181 if (defined $a && length $a &&
182 $a ne $orig && # might already have been moved
183 defined $config{$field} &&
184 length $config{$field}) {
185 $config{$field}=IkiWiki::pagespec_merge($config{$field}, $a);
190 my %banned=map { $_ => 1 } @{$config{banned_users}}, IkiWiki::get_banned_users();
191 $config{banned_users}=[sort keys %banned];
193 IkiWiki::Setup::dump($setup);
197 print STDERR "Usage: ikiwiki-transition type ...\n";
198 print STDERR "Currently supported transition subcommands:\n";
199 print STDERR "\tprefix_directives file ...\n";
200 print STDERR "\tindexdb srcdir\n";
201 print STDERR "\thashpassword srcdir\n";
202 print STDERR "\taggregateinternal setupfile\n";
203 print STDERR "\tsetupformat setupfile\n";
204 print STDERR "\tmoveprefs setupfile\n";
208 usage() unless @ARGV;
211 if ($mode eq 'prefix_directives') {
212 prefix_directives(@ARGV);
214 elsif ($mode eq 'hashpassword') {
217 elsif ($mode eq 'indexdb') {
220 elsif ($mode eq 'aggregateinternal') {
221 aggregateinternal(@ARGV);
223 elsif ($mode eq 'setupformat') {
226 elsif ($mode eq 'moveprefs') {
235 # A slightly modified version of the old loadindex function.
237 %oldrenderedfiles=%pagectime=();
238 if (! $config{rebuild}) {
239 %pagesources=%pagemtime=%oldlinks=%links=%depends=
240 %destsources=%renderedfiles=%pagecase=%pagestate=();
242 open (my $in, "<", "$config{wikistatedir}/index") || return;
248 foreach my $i (split(/ /, $_)) {
249 my ($item, $val)=split(/=/, $i, 2);
250 push @{$items{$item}}, decode_entities($val);
253 next unless exists $items{src}; # skip bad lines for now
255 my $page=pagename($items{src}[0]);
256 if (! $config{rebuild}) {
257 $pagesources{$page}=$items{src}[0];
258 $pagemtime{$page}=$items{mtime}[0];
259 $oldlinks{$page}=[@{$items{link}}];
260 $links{$page}=[@{$items{link}}];
261 $depends{$page}=$items{depends}[0] if exists $items{depends};
262 $destsources{$_}=$page foreach @{$items{dest}};
263 $renderedfiles{$page}=[@{$items{dest}}];
264 $pagecase{lc $page}=$page;
265 foreach my $k (grep /_/, keys %items) {
266 my ($id, $key)=split(/_/, $k, 2);
267 $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
270 $oldrenderedfiles{$page}=[@{$items{dest}}];
271 $pagectime{$page}=$items{ctime}[0];
274 # saveindex relies on %hooks being populated, else it won't save
275 # the page state owned by a given hook. But no plugins are loaded
276 # by this program, so populate %hooks with all hook ids that
277 # currently have page state.
278 foreach my $page (keys %pagemtime) {
279 foreach my $id (keys %{$pagestate{$page}}) {
280 $hooks{_dummy}{$id}=1;
287 # Used to be in IkiWiki/UserInfo, but only used here now.
288 sub get_banned_users () {
290 my $userinfo=userinfo_retrieve();
291 foreach my $user (keys %{$userinfo}) {
292 push @ret, $user if $userinfo->{$user}->{banned};