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);
225 if (! defined $dir) {
228 $config{wikistatedir}=$dir."/.ikiwiki";
229 IkiWiki::loadindex();
230 foreach my $page (keys %links) {
232 $l{$_}=1 foreach @{$links{$page}};
233 $links{$page}=[keys %l]
235 IkiWiki::saveindex();
239 print STDERR "Usage: ikiwiki-transition type ...\n";
240 print STDERR "Currently supported transition subcommands:\n";
241 print STDERR "\tprefix_directives setupfile ...\n";
242 print STDERR "\taggregateinternal setupfile\n";
243 print STDERR "\tsetupformat setupfile\n";
244 print STDERR "\tmoveprefs setupfile\n";
245 print STDERR "\thashpassword srcdir\n";
246 print STDERR "\tindexdb srcdir\n";
247 print STDERR "\tdeduplinks srcdir\n";
251 usage() unless @ARGV;
254 if ($mode eq 'prefix_directives') {
255 prefix_directives(@ARGV);
257 elsif ($mode eq 'hashpassword') {
260 elsif ($mode eq 'indexdb') {
263 elsif ($mode eq 'aggregateinternal') {
264 aggregateinternal(@ARGV);
266 elsif ($mode eq 'setupformat') {
269 elsif ($mode eq 'moveprefs') {
272 elsif ($mode eq 'deduplinks') {
281 # A slightly modified version of the old loadindex function.
283 %oldrenderedfiles=%pagectime=();
284 if (! $config{rebuild}) {
285 %pagesources=%pagemtime=%oldlinks=%links=%depends=
286 %destsources=%renderedfiles=%pagecase=%pagestate=();
288 open (my $in, "<", "$config{wikistatedir}/index") || return;
294 foreach my $i (split(/ /, $_)) {
295 my ($item, $val)=split(/=/, $i, 2);
296 push @{$items{$item}}, decode_entities($val);
299 next unless exists $items{src}; # skip bad lines for now
301 my $page=pagename($items{src}[0]);
302 if (! $config{rebuild}) {
303 $pagesources{$page}=$items{src}[0];
304 $pagemtime{$page}=$items{mtime}[0];
305 $oldlinks{$page}=[@{$items{link}}];
306 $links{$page}=[@{$items{link}}];
307 $depends{$page}=$items{depends}[0] if exists $items{depends};
308 $destsources{$_}=$page foreach @{$items{dest}};
309 $renderedfiles{$page}=[@{$items{dest}}];
310 $pagecase{lc $page}=$page;
311 foreach my $k (grep /_/, keys %items) {
312 my ($id, $key)=split(/_/, $k, 2);
313 $pagestate{$page}{decode_entities($id)}{decode_entities($key)}=$items{$k}[0];
316 $oldrenderedfiles{$page}=[@{$items{dest}}];
317 $pagectime{$page}=$items{ctime}[0];
320 # saveindex relies on %hooks being populated, else it won't save
321 # the page state owned by a given hook. But no plugins are loaded
322 # by this program, so populate %hooks with all hook ids that
323 # currently have page state.
324 foreach my $page (keys %pagemtime) {
325 foreach my $id (keys %{$pagestate{$page}}) {
326 $hooks{_dummy}{$id}=1;
333 # Used to be in IkiWiki/UserInfo, but only used here now.
334 sub get_banned_users () {
336 my $userinfo=userinfo_retrieve();
337 foreach my $user (keys %{$userinfo}) {
338 push @ret, $user if $userinfo->{$user}->{banned};