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);
163 print STDERR "Usage: ikiwiki-transition type ...\n";
164 print STDERR "Currently supported transition subcommands:\n";
165 print STDERR "\tprefix_directives file\n";
166 print STDERR "\tindexdb srcdir\n";
167 print STDERR "\thashpassword srcdir\n";
168 print STDERR "\taggregateinternal setupfile\n";
169 print STDERR "\tsetupformat setupfile\n";
173 usage() unless @ARGV;
176 if ($mode eq 'prefix_directives') {
177 prefix_directives(@ARGV);
179 elsif ($mode eq 'hashpassword') {
182 elsif ($mode eq 'indexdb') {
185 elsif ($mode eq 'aggregateinternal') {
186 aggregateinternal(@ARGV);
188 elsif ($mode eq 'setupformat') {
197 # A slightly modified version of the old loadindex function.
199 %oldrenderedfiles=%pagectime=();
200 if (! $config{rebuild}) {
201 %pagesources=%pagemtime=%oldlinks=%links=%depends=
202 %destsources=%renderedfiles=%pagecase=%pagestate=();
204 open (my $in, "<", "$config{wikistatedir}/index") || return;
210 foreach my $i (split(/ /, $_)) {
211 my ($item, $val)=split(/=/, $i, 2);
212 push @{$items{$item}}, decode_entities($val);
215 next unless exists $items{src}; # skip bad lines for now
217 my $page=pagename($items{src}[0]);
218 if (! $config{rebuild}) {
219 $pagesources{$page}=$items{src}[0];
220 $pagemtime{$page}=$items{mtime}[0];
221 $oldlinks{$page}=[@{$items{link}}];
222 $links{$page}=[@{$items{link}}];
223 $depends{$page}=$items{depends}[0] if exists $items{depends};
224 $destsources{$_}=$page foreach @{$items{dest}};
225 $renderedfiles{$page}=[@{$items{dest}}];
226 $pagecase{lc $page}=$page;
227 foreach my $k (grep /_/, keys %items) {
228 my ($id, $key)=split(/_/, $k, 2);
229 $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
232 $oldrenderedfiles{$page}=[@{$items{dest}}];
233 $pagectime{$page}=$items{ctime}[0];
236 # saveindex relies on %hooks being populated, else it won't save
237 # the page state owned by a given hook. But no plugins are loaded
238 # by this program, so populate %hooks with all hook ids that
239 # currently have page state.
240 foreach my $page (keys %pagemtime) {
241 foreach my $id (keys %{$pagestate{$page}}) {
242 $hooks{_dummy}{$id}=1;