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);
80 $config{wikistatedir}=$dir."/.ikiwiki";
82 # Note: No lockwiki here because ikiwiki already locks it
83 # before calling this.
84 if (! IkiWiki::oldloadindex()) {
85 die "failed to load index\n";
87 if (! IkiWiki::saveindex()) {
88 die "failed to save indexdb\n"
90 if (! IkiWiki::loadindex()) {
91 die "transition failed, cannot load new indexdb\n";
93 if (! unlink("$config{wikistatedir}/index")) {
94 die "unlink failed: $!\n";
100 if (! defined $dir) {
103 $config{wikistatedir}=$dir."/.ikiwiki";
105 eval q{use IkiWiki::UserInfo};
106 eval q{use Authen::Passphrase::BlowfishCrypt};
108 error("ikiwiki-transition hashpassword: failed to load Authen::Passphrase, passwords not hashed");
112 IkiWiki::loadplugin("passwordauth");
113 my $userinfo = IkiWiki::userinfo_retrieve();
114 foreach my $user (keys %{$userinfo}) {
115 if (ref $userinfo->{$user} &&
116 exists $userinfo->{$user}->{password} &&
117 length $userinfo->{$user}->{password} &&
118 ! exists $userinfo->{$user}->{cryptpassword}) {
119 IkiWiki::Plugin::passwordauth::setpassword($user, $userinfo->{$user}->{password});
124 sub aggregateinternal {
126 if (! defined $setup) {
130 require IkiWiki::Setup;
131 require IkiWiki::Plugin::aggregate;
133 %config = IkiWiki::defaultconfig();
134 IkiWiki::Setup::load($setup);
135 IkiWiki::checkconfig();
137 IkiWiki::Plugin::aggregate::migrate_to_internal();
142 if (! defined $setup) {
146 require IkiWiki::Setup;
148 %config = IkiWiki::defaultconfig();
149 IkiWiki::Setup::load($setup);
150 IkiWiki::checkconfig();
152 # unpack old-format wrappers setting into new fields
155 foreach my $wrapper (@{$config{wrappers}}) {
156 if ($wrapper->{cgi}) {
158 die "don't know what to do with second cgi wrapper ".$wrapper->{wrapper}."\n";
161 print "setting cgi_wrapper to ".$wrapper->{wrapper}."\n";
162 $config{cgi_wrapper}=$wrapper->{wrapper};
163 $config{cgi_wrappermode}=$wrapper->{wrappermode}
164 if exists $wrapper->{wrappermode};
166 elsif ($config{rcs}) {
168 die "don't know what to do with second rcs wrapper ".$wrapper->{wrapper}."\n";
171 print "setting $config{rcs}_wrapper to ".$wrapper->{wrapper}."\n";
172 $config{$config{rcs}."_wrapper"}=$wrapper->{wrapper};
173 $config{$config{rcs}."_wrappermode"}=$wrapper->{wrappermode}
174 if exists $wrapper->{wrappermode};
177 die "don't know what to do with wrapper ".$wrapper->{wrapper}."\n";
181 IkiWiki::Setup::dump($setup);
186 if (! defined $setup) {
190 require IkiWiki::Setup;
192 %config = IkiWiki::defaultconfig();
193 IkiWiki::Setup::load($setup);
194 IkiWiki::checkconfig();
196 eval q{use IkiWiki::UserInfo};
199 foreach my $field (qw{allowed_attachments locked_pages}) {
200 my $orig=$config{$field};
201 foreach my $admin (@{$config{adminuser}}) {
202 my $a=IkiWiki::userinfo_get($admin, $field);
203 if (defined $a && length $a &&
204 # might already have been moved
205 (! defined $orig || $a ne $orig)) {
206 if (defined $config{$field} &&
207 length $config{$field}) {
208 $config{$field}=IkiWiki::pagespec_merge($config{$field}, $a);
217 my %banned=map { $_ => 1 } @{$config{banned_users}}, IkiWiki::get_banned_users();
218 $config{banned_users}=[sort keys %banned];
220 IkiWiki::Setup::dump($setup);
224 print STDERR "Usage: ikiwiki-transition type ...\n";
225 print STDERR "Currently supported transition subcommands:\n";
226 print STDERR "\tprefix_directives setupfile ...\n";
227 print STDERR "\taggregateinternal setupfile\n";
228 print STDERR "\tsetupformat setupfile\n";
229 print STDERR "\tmoveprefs setupfile\n";
230 print STDERR "\thashpassword srcdir\n";
231 print STDERR "\tindexdb srcdir\n";
235 usage() unless @ARGV;
238 if ($mode eq 'prefix_directives') {
239 prefix_directives(@ARGV);
241 elsif ($mode eq 'hashpassword') {
244 elsif ($mode eq 'indexdb') {
247 elsif ($mode eq 'aggregateinternal') {
248 aggregateinternal(@ARGV);
250 elsif ($mode eq 'setupformat') {
253 elsif ($mode eq 'moveprefs') {
262 # A slightly modified version of the old loadindex function.
264 %oldrenderedfiles=%pagectime=();
265 if (! $config{rebuild}) {
266 %pagesources=%pagemtime=%oldlinks=%links=%depends=
267 %destsources=%renderedfiles=%pagecase=%pagestate=();
269 open (my $in, "<", "$config{wikistatedir}/index") || return;
275 foreach my $i (split(/ /, $_)) {
276 my ($item, $val)=split(/=/, $i, 2);
277 push @{$items{$item}}, decode_entities($val);
280 next unless exists $items{src}; # skip bad lines for now
282 my $page=pagename($items{src}[0]);
283 if (! $config{rebuild}) {
284 $pagesources{$page}=$items{src}[0];
285 $pagemtime{$page}=$items{mtime}[0];
286 $oldlinks{$page}=[@{$items{link}}];
287 $links{$page}=[@{$items{link}}];
288 $depends{$page}=$items{depends}[0] if exists $items{depends};
289 $destsources{$_}=$page foreach @{$items{dest}};
290 $renderedfiles{$page}=[@{$items{dest}}];
291 $pagecase{lc $page}=$page;
292 foreach my $k (grep /_/, keys %items) {
293 my ($id, $key)=split(/_/, $k, 2);
294 $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
297 $oldrenderedfiles{$page}=[@{$items{dest}}];
298 $pagectime{$page}=$items{ctime}[0];
301 # saveindex relies on %hooks being populated, else it won't save
302 # the page state owned by a given hook. But no plugins are loaded
303 # by this program, so populate %hooks with all hook ids that
304 # currently have page state.
305 foreach my $page (keys %pagemtime) {
306 foreach my $id (keys %{$pagestate{$page}}) {
307 $hooks{_dummy}{$id}=1;
314 # Used to be in IkiWiki/UserInfo, but only used here now.
315 sub get_banned_users () {
317 my $userinfo=userinfo_retrieve();
318 foreach my $user (keys %{$userinfo}) {
319 push @ret, $user if $userinfo->{$user}->{banned};