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();
117 print "... now add aggregateinternal => 1 to your .setup file\n";
122 if (! defined $setup) {
126 require IkiWiki::Setup;
128 %config = IkiWiki::defaultconfig();
129 IkiWiki::Setup::load($setup);
130 IkiWiki::checkconfig();
132 # unpack old-format wrappers setting into new fields
135 foreach my $wrapper (@{$config{wrappers}}) {
136 if ($wrapper->{cgi}) {
138 die "don't know what to do with second cgi wrapper ".$wrapper->{wrapper}."\n";
141 print "setting cgi_wrapper to ".$wrapper->{wrapper}."\n";
142 $config{cgi_wrapper}=$wrapper->{wrapper};
143 $config{cgi_wrappermode}=$wrapper->{wrappermode}
144 if exists $wrapper->{wrappermode};
146 elsif ($config{rcs}) {
148 die "don't know what to do with second rcs wrapper ".$wrapper->{wrapper}."\n";
151 print "setting $config{rcs}_wrapper to ".$wrapper->{wrapper}."\n";
152 $config{$config{rcs}."_wrapper"}=$wrapper->{wrapper};
153 $config{$config{rcs}."_wrappermode"}=$wrapper->{wrappermode}
154 if exists $wrapper->{wrappermode};
157 die "don't know what to do with wrapper ".$wrapper->{wrapper}."\n";
161 IkiWiki::Setup::dump($setup);
165 print STDERR "Usage: ikiwiki-transition type ...\n";
166 print STDERR "Currently supported transition subcommands:\n";
167 print STDERR "\tprefix_directives file\n";
168 print STDERR "\tindexdb srcdir\n";
169 print STDERR "\thashpassword srcdir\n";
170 print STDERR "\taggregateinternal setupfile\n";
171 print STDERR "\tsetupformat setupfile\n";
175 usage() unless @ARGV;
178 if ($mode eq 'prefix_directives') {
179 prefix_directives(@ARGV);
181 elsif ($mode eq 'hashpassword') {
184 elsif ($mode eq 'indexdb') {
187 elsif ($mode eq 'aggregateinternal') {
188 aggregateinternal(@ARGV);
190 elsif ($mode eq 'setupformat') {
199 # A slightly modified version of the old loadindex function.
201 %oldrenderedfiles=%pagectime=();
202 if (! $config{rebuild}) {
203 %pagesources=%pagemtime=%oldlinks=%links=%depends=
204 %destsources=%renderedfiles=%pagecase=%pagestate=();
206 open (my $in, "<", "$config{wikistatedir}/index") || return;
212 foreach my $i (split(/ /, $_)) {
213 my ($item, $val)=split(/=/, $i, 2);
214 push @{$items{$item}}, decode_entities($val);
217 next unless exists $items{src}; # skip bad lines for now
219 my $page=pagename($items{src}[0]);
220 if (! $config{rebuild}) {
221 $pagesources{$page}=$items{src}[0];
222 $pagemtime{$page}=$items{mtime}[0];
223 $oldlinks{$page}=[@{$items{link}}];
224 $links{$page}=[@{$items{link}}];
225 $depends{$page}=$items{depends}[0] if exists $items{depends};
226 $destsources{$_}=$page foreach @{$items{dest}};
227 $renderedfiles{$page}=[@{$items{dest}}];
228 $pagecase{lc $page}=$page;
229 foreach my $k (grep /_/, keys %items) {
230 my ($id, $key)=split(/_/, $k, 2);
231 $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
234 $oldrenderedfiles{$page}=[@{$items{dest}}];
235 $pagectime{$page}=$items{ctime}[0];
238 # saveindex relies on %hooks being populated, else it won't save
239 # the page state owned by a given hook. But no plugins are loaded
240 # by this program, so populate %hooks with all hook ids that
241 # currently have page state.
242 foreach my $page (keys %pagemtime) {
243 foreach my $id (keys %{$pagestate{$page}}) {
244 $hooks{_dummy}{$id}=1;