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 $a ne $orig && # might already have been moved
205 defined $config{$field} &&
206 length $config{$field}) {
207 $config{$field}=IkiWiki::pagespec_merge($config{$field}, $a);
212 my %banned=map { $_ => 1 } @{$config{banned_users}}, IkiWiki::get_banned_users();
213 $config{banned_users}=[sort keys %banned];
215 IkiWiki::Setup::dump($setup);
219 print STDERR "Usage: ikiwiki-transition type ...\n";
220 print STDERR "Currently supported transition subcommands:\n";
221 print STDERR "\tprefix_directives setupfile ...\n";
222 print STDERR "\taggregateinternal setupfile\n";
223 print STDERR "\tsetupformat setupfile\n";
224 print STDERR "\tmoveprefs setupfile\n";
225 print STDERR "\thashpassword srcdir\n";
226 print STDERR "\tindexdb srcdir\n";
230 usage() unless @ARGV;
233 if ($mode eq 'prefix_directives') {
234 prefix_directives(@ARGV);
236 elsif ($mode eq 'hashpassword') {
239 elsif ($mode eq 'indexdb') {
242 elsif ($mode eq 'aggregateinternal') {
243 aggregateinternal(@ARGV);
245 elsif ($mode eq 'setupformat') {
248 elsif ($mode eq 'moveprefs') {
257 # A slightly modified version of the old loadindex function.
259 %oldrenderedfiles=%pagectime=();
260 if (! $config{rebuild}) {
261 %pagesources=%pagemtime=%oldlinks=%links=%depends=
262 %destsources=%renderedfiles=%pagecase=%pagestate=();
264 open (my $in, "<", "$config{wikistatedir}/index") || return;
270 foreach my $i (split(/ /, $_)) {
271 my ($item, $val)=split(/=/, $i, 2);
272 push @{$items{$item}}, decode_entities($val);
275 next unless exists $items{src}; # skip bad lines for now
277 my $page=pagename($items{src}[0]);
278 if (! $config{rebuild}) {
279 $pagesources{$page}=$items{src}[0];
280 $pagemtime{$page}=$items{mtime}[0];
281 $oldlinks{$page}=[@{$items{link}}];
282 $links{$page}=[@{$items{link}}];
283 $depends{$page}=$items{depends}[0] if exists $items{depends};
284 $destsources{$_}=$page foreach @{$items{dest}};
285 $renderedfiles{$page}=[@{$items{dest}}];
286 $pagecase{lc $page}=$page;
287 foreach my $k (grep /_/, keys %items) {
288 my ($id, $key)=split(/_/, $k, 2);
289 $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
292 $oldrenderedfiles{$page}=[@{$items{dest}}];
293 $pagectime{$page}=$items{ctime}[0];
296 # saveindex relies on %hooks being populated, else it won't save
297 # the page state owned by a given hook. But no plugins are loaded
298 # by this program, so populate %hooks with all hook ids that
299 # currently have page state.
300 foreach my $page (keys %pagemtime) {
301 foreach my $id (keys %{$pagestate{$page}}) {
302 $hooks{_dummy}{$id}=1;
309 # Used to be in IkiWiki/UserInfo, but only used here now.
310 sub get_banned_users () {
312 my $userinfo=userinfo_retrieve();
313 foreach my $user (keys %{$userinfo}) {
314 push @ret, $user if $userinfo->{$user}->{banned};