forked from okfn/moinmoin2mediawiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmm2mw.pl
executable file
·1471 lines (1353 loc) · 61.3 KB
/
mm2mw.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# MoinMoin to MediaWiki converter
#
# =========================================================================================
# (c) Copyright 2007, 2008 by Rotan Hanrahan (rotan A T ieee D O T org)
#
# W3C® SOFTWARE NOTICE AND LICENSE
# http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
#
# This work (and included software, documentation such as READMEs, or other related items)
# is being provided by the copyright holders under the following license. By obtaining,
# using and/or copying this work, you (the licensee) agree that you have read, understood,
# and will comply with the following terms and conditions.
#
# Permission to copy, modify, and distribute this software and its documentation, with or
# without modification, for any purpose and without fee or royalty is hereby granted,
# provided that you include the following on ALL copies of the software and documentation
# or portions thereof, including modifications:
#
# 1. The full text of this NOTICE in a location viewable to users of the
# redistributed or derivative work.
# 2. Any pre-existing intellectual property disclaimers, notices, or terms
# and conditions. If none exist, the W3C Software Short Notice should be
# included (hypertext is preferred, text is permitted) within the body of
# any redistributed or derivative code.
# 3. Notice of any changes or modifications to the files, including the date
# changes were made. (We recommend you provide URIs to the location from
# which the code is derived.)
#
# THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
# REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES
# OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR
# DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
#
# COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL
# DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
#
# The name and trademarks of copyright holders may NOT be used in advertising or publicity
# pertaining to the software without specific, written prior permission. Title to copyright in
# this software and any associated documentation will at all times remain with copyright holders.
#
# ========================================================================================
#
# Input: 1) Path to the data direcory from the MoinMoin (v1.3+) system.
# 2) To perform the upload to MediaWiki, you need the Wiki Sysop password.
# 3) Optional: A skip.txt file in the current directory. One line per wiki page name: prevents their conversion.
# Output: 1) A directory containing MediaWiki equivalents for all edited pages, including attachments.
# 2) The MediaWiki XML files for importing individual pages, and XML file(s) for the entire wiki.
# Note: The upload can be performed completely from within this tool.
# Command format:
# OSPrompt) perl mmTOmw.pl [path to moin-moin directory containing data directory]
# e.g. perl mmTOmw.pl ./myMoinMoinWiki
# Original motivation: port the W3C DDWG wiki from MoinMoin to MediaWiki in a repeatable manner.
# Features:
# V1.0
# - Interactive "commands with menu and help" textual interface
# - Generates MediaWiki importable XML files from moin-moin directory hierarchy
# - Provides one or more XML files for the entire wiki to be ported
# - XML files are split to a configurable size to avoid upload size limits
# - Also provides individual XML files for separate upload of specific pages
# - Note: You must upload the XML files via the MediaWiki Sysop account
# - Preserves entire edit history, including timestamps, authors and comments
# - Preserves most of the original moin-moin URLs
# - Exclusion list (external file) to prevent porting of certain wiki pages
# - Only the pages mentioned in the edit history are ported
# - Direct upload of attachements/images from within this program
# - Built-in help
# - Supports many moin-moin markup features:
# - Tables: width, style, alignment, spanning, borders, padding, cell justification
# - Lists: bullets, numbers, nested, partial support for lettered lists
# - Bold, Italic, Underline, Strike, Superscript, Subscript, Large/Small font
# - Structure: headings, paragraphs, line breaks
# - Definition styles
# - Code styles, "Pre" styles, "Nowiki" regions
# - Wiki links: Inline, CamelCase, Anchor text, Free links, Page inclusion
# - Attachments: images (become [[Image]]), generic files (become [[Media]])
# - Inline images
# - Smilies: <!> {*} {o} {OK} {X}
# - Wiki page redirects
# - Wiki page name compatibility (e.g. spaces and underscores are handled correctly)
# - Common link rewrites (RecentChanges, FindPage, SyntaxReference, SiteNavigation)
# Known limitations
# V1.0
# - Numbered lists must start at 1 (MW limitation)
# - Lists with uppercase letter 'bullets' are not supported (by MW) so are converted to lowercase
# - Cannot continue list numbering after text (e.g. a defn list) that directly follows an item in the middle of a list.
# - Cannot port [[TableOfContents]] (But MediaWiki makes its own anyway)
# - Cannot import indented lists of definitions (which are rare)
# - Apart from REDIRECT, moin-moin page commands are ignored
# - Cannot port moin-moin slideshow pages
# - Skips all moin-moin pages whose name starts with an escaped character
# - Only works with directory hierarchies from moin-moin version 1.3 or greater
# Special considerations
# - By default, MediaWiki will not support certain file types as attachments (e.g. PDF)
# - Before uploading, you can try using the sandbox to test the generated markup
# - Strongly recommend that the php.ini on the wiki server is edited to have 4Mb upload limit instead of 2Mb
# Assumptions:
# The target MediaWiki instance is empty.
# You have the MediaWiki sysop account details
# The moin-moin directory hierarchy
# data/ (The path to the 'data' directory is input to this program)
# +---cache/ . . .
# |
# +---dict/ . . .
# |
# +---pages/
# | +---ExampleWikiPage/
# | | +---attachments/
# | | | |
# | | | myFile.ext
# | | | SecondFile.ext
# | | |
# | | +---cache/ . . .
# | | |
# | | +---revisions/
# | | | |
# | | | 00000001 (moin-moin markup of revision 1)
# | | | 00000002
# | | | 00000003
# | | |
# | | current
# | |
# | +---SecondExample/ . . .
# |
# +---plugin/ . . .
# |
# +---plugins/ . . .
# |
# +---user/ . . .
# |
# edit-log
# error.log
# event-log
# intermap.txt
# The generated MediaWiki directory (containing resources for upload to server)
# myOutputDirectory-mw/
# +---pages
# | +---ExampleWikiPage/
# | | +---attachments/
# | | | |
# | | | myFile.ext (Use built-in "upload" command to upload all attachments)
# | | | SecondFile.ext
# | | |
# | | 00000001 (Generated MediaWiki markup of revision 1)
# | | 00000002
# | | 00000003
# | | ExampleWikiPage.xml (Use this to upload an individual page via Special:Upload)
# | |
# | +---SecondExample/. . .
# |
# allpages1.xml (Use these to upload the entire wiki via Special:Upload)
# allpages2.xml
# allpages3.xml (etc.)
# instructions.txt (In case you need help)
use strict;
use Cwd;
use File::Path;
use File::Copy;
use LWP::UserAgent;
use HTTP::Request::Common;
use Data::Dumper;
use XML::LibXML;
#########################################################################################################################
# Config data (the defaults come from experiments on the DDWG wiki)
my $datapath = './mywiki/data'; # The data directory at the root of the tarball
my $targetpath = './mywiki-mw'; # Destination folder for generated MediaWiki pages
my $testpage; # If defined, this will be the only page processed
my $moinmoinurlbase = 'http://www.w3.org/YYYY/GroupName/wiki/';
my $serverindexurl = 'http://mywiki.ex'; # skip index.php and so on. It is added automatically if needed.
my $interwiki = 'SomeWiki';
my $splitsize = 1000000; # 1Mb approx split size. Anwhere up to 1Mb is reasonable.
my $MaxXmlSize = '25000000'; # Limit, as per form on the Special:Import page NOTE: Make this as big as possible on the MW server. (edit php.ini)
my @extensions = ('png', 'jpg', 'gif', 'pdf'); # Extensions that can be uploaded to MediaWiki (This feature not used, yet.)
my $prompt = 'mmTOmw> ';
my $analysed = undef;
my $converted = undef;
my $uploaded = undef;
my $loggedIn = 0;
my $maxAttempts = 1; # number of times to try uploading an attachment
my $TRACE_ATTACHMENTS = undef;
# Diagnostic settings
my $diagnosticShowComparisonLink = 0;
if ($#ARGV >= 0) {
$datapath = $ARGV[0] . '/data';
$targetpath = $ARGV[0] . '-mw';
if (! -d $datapath) {
die "Directory $datapath not found.\n";
}
}
else {
print "Searching for a sub-directory with a Moin-Moin data directory...\n";
opendir(SUBDIRS, cwd()) || die "Cannot open current directory";
my @allSubDirs = grep { /^[^\.\(].*/ } readdir(SUBDIRS);
closedir(SUBDIRS);
foreach (@allSubDirs) {
if (-d) {
if (-e "$_/data") {
$datapath = cwd() . "/$_/data";
$targetpath = cwd() . "/$_" . '-mw';
print "Found what looks like a Moin-Moin data sub-directory.\n";
last;
}
}
}
}
if ($#ARGV >= 1) {$targetpath = $ARGV[1];}
if ($#ARGV >= 2) {$testpage = $ARGV[2];} # for diagnostic use only
$datapath =~ s/\/$//; $targetpath =~ s/\/$//;
# Collected data
my (@allWikiDirs, @portingDirectories, @deletingDirectories,
%wikiRevisions, %wikiRevisionComments, %wikiRevisionAuthors, %wikiRevisionTimestamps, @allRevisions, $revisionsTotal,
%users, @allAttachments, %wikiAttachments, %wikiAttachmentsInDirectory, %wikiAttachmentReferences, $attachmentsTotal,
%mmLoggedNames, %wikiPageName, %lastRevision, @skip);
# Temporary variables
my ($wikiDirName, $wikiDirPath, $targetDirectory, $copyDirectory, $copyPath,
$revisionPath, $revisionNumber, $revisionComment, $revisionsPath, $revisionTimestamp,
$attachment, $attachmentPath, $attachmentsPath, @logItems, $comment, $mmPageDirectory, $p, $wn);
# UA for HTTP uploads
my $ua = LWP::UserAgent->new(
agent => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)' ,
'cookie_jar' => {file => "wpcookies.txt", autosave => 1}
);
# List of pages that are to be skipped (in addition to the ones that were not created by wiki authors)
if (-e 'skip.txt') {
open(SKIP,'<skip.txt');
chomp(@skip = <SKIP>);
close(SKIP);
}
#########################################################################################################################
$| = 1;
print "mmTOmw : Copyright (c) Rotan Hanrahan 2007,2008.\n";
print "This is free software under the W3C License. See source for details.\n";
print "http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231\n";
showsettings();
print " Type '?' for help\n$prompt";
while (defined(my $command = <STDIN>)) {
$command =~ s/(^\s*|\s*$)//gs;
if ($command =~ /^(quit|exit|bye|end|stop|halt|finish|q|q!|terminate|eoj)$/i) {
print "Finished\n";
exit 0;
}
elsif ($command eq 'set') {
showsettings();
}
elsif ($command =~ /^(\?|help|assist|h)$/i) {
print " HELP\n";
print " src [<dir>] Shot/Set source moinmoin data directory\n";
print " dst [<dir>] Show/Set destination directory for conversion\n";
print " url [<url>] Show/Set MW home (eg http://.../wiki/index.php)\n";
print " mmurl [<url>] Show/Set MM home (eg http://.../source/wiki)\n";
print " split <bytes> Set approx split size for MediaWiki XML files\n";
print " analyse Analyse moinmoin logs and directories\n";
print " convert Analyse and then convert pages to MediaWiki format\n";
print " login Log in to current MediaWiki server (as Wiki Sysop)\n";
print " upload Upload pages and attachments to MediaWiki server\n";
print " set Display settings and results of analysis\n";
print " list all|pages|deletes|attachments Post analysis summaries\n";
print " quit|exit|stop...\n";
print "\n";
print " Typical use case:\n";
print " 1. Set moinmoin source directory, destination directory & MediaWiki home URL.\n";
print " 2. 'Convert' the MM pages to MW pages, and cache results in dest directory.\n";
print " 3. 'Upload' the converted data directly to the live MediaWiki server.\n";
}
elsif ($command =~ /^(src|source)(\s+(\S*))?/i) {
if (defined $3) { $datapath = $3; }
print " src = $datapath\n";
}
elsif ($command =~ /^(dst|dest|destination)(\s+(\S*))?/i) {
if (defined $converted) {
print " You cannot change the destination after conversion.\n";
}
else {
if (defined $3) { $targetpath = $3; }
print " dst = $targetpath\n";
}
}
elsif ($command =~ /^(url|mwurl)(\s+(\S+))?/i) {
if (defined $3) { $serverindexurl = $3; $loggedIn = 0; }
print " url = $serverindexurl\n";
}
elsif ($command =~ /^(mmurl|mm)(\s+(\S+))?/i) {
if (defined $3) { $moinmoinurlbase = $3; }
$moinmoinurlbase =~ s/\/$//;
print " mmURL = $moinmoinurlbase\n";
}
elsif ($command =~ /^(interwiki)(\s+(\S+))?/i) {
if (defined $3) { $interwiki = $3; }
$interwiki =~ s/\/$//;
print " interwiki = $interwiki\n";
}
elsif ($command =~ /^split(\s+(\d+))?$/i) {
if (defined $2) { $splitsize = $2; }
print " Split XML files at approx $splitsize bytes\n";
}
elsif ($command =~ /^(analyse|analyze)$/i) {
if (defined $analysed) {
print " To re-do the analysis, restart this program.\n";
}
else {
analyse();
showsettings();
}
}
elsif ($command =~ /^list(\s.*)?/i) {
if (!defined $analysed) {
print " The list command is only available after analysis.\n";
}
else {
if ($command eq 'list') {
print " list all : Lists all pages, deletes, attachments and users\n";
print " list pages : Lists pages to be ported to MediaWiki\n";
print " list deletes : Lists deleted pages that will not be ported\n";
print " list attach : Lists all attachments\n";
print " list users : Lists all the moinmoin users\n";
}
if ($command eq 'list all' || $command =~ /^list\s+pages?/i) {
foreach (@portingDirectories) {
print " page $_\n";
}
}
if ($command eq 'list all' || $command =~ /^list\s+deletes?/i) {
foreach (@deletingDirectories) {
print " delete $_\n";
}
}
if ($command eq 'list all' || $command =~ /^list\s+attach/i) {
foreach (sort keys %wikiAttachmentsInDirectory) {
print ' attach ' . join(', ',@{$wikiAttachmentsInDirectory{$_}}) . "\n to $_\n";
}
}
if ($command eq 'list all' || $command =~ /^list\s+users?/i) {
foreach (sort values %users) {
print " user $_\n";
}
}
}
}
elsif ($command =~ /^convert(\s+(\S+))?/) {
if (defined $converted) {
print " To repeat the conversion, restart this program.\n";
}
else {
my $timestamp = time();
analyse();
convert($1 . $testpage);
print ' Convertion took ' . (time() - $timestamp) . " seconds.\n";
}
}
elsif ($command eq 'login') {
LogIn($serverindexurl);
}
elsif ($command eq 'upload') {
my $timestamp = time();
if (!defined $analysed) {
print " Performing analysis to discover attachments...\n";
analyse();
}
if ($ENV{TRACE_ATTACHMENTS}) {
open $TRACE_ATTACHMENTS, '>&', $ENV{TRACE_ATTACHMENTS} || die;
}
Upload($serverindexurl);
if ($TRACE_ATTACHMENTS) {
close $TRACE_ATTACHMENTS || die;
}
print ' Upload took ' . (time() - $timestamp) . " seconds.\n";
}
elsif ($command ne '') {
print " Type '?' for help\n";
}
print $prompt;
}
###########################################################################################################
sub showsettings {
print " src = $datapath\n";
print " dst = $targetpath\n";
print " URL = $serverindexurl\n";
print " mmURL = $moinmoinurlbase\n";
print " interwiki = $interwiki\n";
print " Split = $splitsize\n";
if (defined $analysed) {
print " Analysis:\n";
print " " . scalar @portingDirectories . " wiki pages to be ported.\n";
print " " . scalar @deletingDirectories . " wiki pages are deleted and not to be ported.\n";
print " $revisionsTotal revisions in total to be ported.\n";
print " $attachmentsTotal attachments to be ported.\n";
print ' ' . (keys %users) . " users recorded in the moinmoin logs.\n";
}
}
sub convert {
if (defined $converted) { return; }
my $testpage = shift;
# Create destination folders
if (!-e "$targetpath") { mkdir("$targetpath") || die "Could not create $targetpath"; }
if (!-e "$targetpath/pages") { mkdir("$targetpath/pages") || die "Could not create $targetpath/pages"; }
# For each source moinmoin revision, generate a corresponding target MediaWiki document
my $pageid = 0;
my $allsize = 0; # Accumulated XML output to "allpagesNNN.xml". Reset to zero after each split.
my $allindex = 1; # Index of the split XML files. Increments after each split.
my @exportedpages;
open(EXPORTALL,">$targetpath/allpages$allindex.xml") || die "Could not open export file $targetpath/allpages$allindex.xml ($!)";
ExportPreamble(\*EXPORTALL);
foreach $wikiDirName (@portingDirectories) {
$pageid++;
if ($testpage) { next if ($wikiDirName ne $testpage); }
$wikiDirPath = "$datapath/pages/$wikiDirName";
my $estimatedConvertedSize = sizeOfDirectory("$wikiDirPath/revisions") * 1.25; # Assuming 25% overhead in MediaWiki versions
#print " Estimated size: $wikiDirName = $estimatedConvertedSize bytes\n";
$targetDirectory = "$targetpath/pages/$wikiDirName";
if (!-e $targetDirectory) { mkdir($targetDirectory) || die "Could not create $targetDirectory"; }
(my $title = $wikiDirName) =~ s/\s/_/g; # Not needed for MoinMoin names, but here just in case.
open(EXPORTPAGE,">$targetDirectory/$title.xml") || die "Could not open export file $title.xml ($!)";
if ($allsize + $estimatedConvertedSize > $splitsize) { # Split the output so that the imports are not much more than $splitsize each
ExportEnd(\*EXPORTALL);
if ($allsize > $MaxXmlSize) {
print " WARNING: XML file 'allpages$allindex' exceeds MediaWiki limit.\n";
}
$allsize = 0;
$allindex++;
open(EXPORTALL,">$targetpath/allpages$allindex.xml") || die "Could not open export file $targetpath/allpages$allindex.xml ($!)";
ExportPreamble(\*EXPORTALL);
}
ExportPreamble(\*EXPORTPAGE);
ExportPageBegin(\*EXPORTPAGE,$wikiDirName,$pageid);
ExportPageBegin(\*EXPORTALL,$wikiDirName,$pageid);
foreach $revisionNumber (@{$wikiRevisions{$wikiDirName}}) {
$revisionPath = "$wikiDirPath/revisions/$revisionNumber";
$revisionTimestamp = $wikiRevisionTimestamps{$wikiDirName . '#' . $revisionNumber};
$revisionComment = $wikiRevisionComments{$wikiDirName . '#' . $revisionNumber};
my $authorID = $wikiRevisionAuthors{$wikiDirName . '#' . $revisionNumber};
my $mwmarkup = ConvertMM2MW($revisionPath,"$targetDirectory/$revisionNumber",$wikiDirName,$revisionNumber,$revisionComment,$revisionTimestamp);
ExportPageRevision(\*EXPORTPAGE,$mwmarkup,$revisionNumber,$revisionTimestamp,$revisionComment,$users{$authorID},$authorID);
ExportPageRevision(\*EXPORTALL,$mwmarkup,$revisionNumber,$revisionTimestamp,$revisionComment,$users{$authorID},$authorID);
$allsize += length($mwmarkup);
}
ExportPageEnd(\*EXPORTPAGE);
ExportEnd(\*EXPORTPAGE);
ExportPageEnd(\*EXPORTALL);
push(@exportedpages,$title);
if ($testpage) { print "All revisions of $testpage have been created.\n"; last; }
foreach $attachment (@{$wikiAttachmentsInDirectory{$wikiDirName}}) {
$attachmentPath = "$datapath/pages/$wikiDirName/attachments/$attachment";
$copyDirectory = "$targetpath/pages/$wikiDirName/attachments";
$copyPath = "$copyDirectory/$attachment";
if (!-e $copyDirectory) { mkdir($copyDirectory) || die "Could not create $copyDirectory"; }
copy($attachmentPath,$copyPath) || die "Could not copy attachment $wikiDirName/$attachment - $!";
}
print "Generated $wikiDirName\n";
}
ExportEnd(\*EXPORTALL);
open(INSTRUCTIONS,">$targetpath/instructions.txt") || die "Could not open instructions";
print INSTRUCTIONS "# To upload the XML files to MediaWiki, log in as Sysop and go to 'Special:Import' page.\n";
print INSTRUCTIONS "\n\nPages for importing to the target MediaWiki server are:\n";
foreach (@exportedpages) {
print INSTRUCTIONS " $_\n";
}
close(INSTRUCTIONS);
print "Conversion complete.\n";
}
sub analyse {
if (defined $analysed) { return; }
open(EDITLOG, "<${datapath}/edit-log") || die "Cannot open edit-log";
while (my $logline = <EDITLOG>) {
@logItems = split(/\t{1}/,$logline);
if ($logItems[3] ne 'BadContent') {
$revisionTimestamp = $logItems[0];
$revisionNumber = $logItems[1];
# 99999999 corresponds to attachments (see http://moinmo.in/MoinDev/Storage)
if($revisionNumber == '99999999') {
next;
}
$wikiDirName = $logItems[3];
my $revisionAuthorID = $logItems[6];
chomp($comment = $logItems[8]);
$mmLoggedNames{$wikiDirName} = 1;
$wikiRevisionTimestamps{$wikiDirName . '#' . $revisionNumber} = $revisionTimestamp;
$wikiRevisionAuthors{$wikiDirName . '#' . $revisionNumber} = $revisionAuthorID;
if ($comment ne '') {
$wikiRevisionComments{$wikiDirName . '#' . $revisionNumber} = $comment;
}
$lastRevision{$wikiDirName} = $revisionNumber;
}
}
close(EDITLOG);
# %mmLoggedNames is a map from directories mentioned in the edit-log file to TRUE
# %wikiRevisionComments is a map from "directory#revision" to comments (for individual revisions)
# %lastRevision is a map from directories mentioned to the last revision recorded in the log
# (Note: if the last revision file is not found, the wiki page has been deleted, possibly spam.)
opendir(WIKIDIRS, "${datapath}/pages") || die "Cannot open data/pages";
@allWikiDirs = grep { /^[^\.\(].*/ && "$(datapath}/pages/$_" } readdir(WIKIDIRS); # list of all moinmoin wiki page directories
closedir(WIKIDIRS);
foreach $mmPageDirectory (@allWikiDirs) {
if ($mmLoggedNames{$mmPageDirectory}) {
if (-e "$datapath/pages/$mmPageDirectory/revisions/$lastRevision{$mmPageDirectory}") {
push(@portingDirectories,$mmPageDirectory);
}
else {
push(@deletingDirectories,$mmPageDirectory);
}
}
}
# @portingDirectories now lists all the new wiki directories that exist and are to be ported to MediaWiki format
# @deletingDirectories now lists all the wiki directories that will not be ported as the last revision was a deletion
# These directory names will be used as hash keys for all pages from now.
foreach $p (@portingDirectories) {
($wn = $p) =~ s/_/ /g; # "_" is replaced by space
$wn =~ s/\(2f\)/\//gi; # (2f) is replaced by "/"
$wikiPageName{$p} = $wn;
}
# %wikiPageName now maps directory names to wiki names
foreach $p (@portingDirectories) {
$revisionsPath = "${datapath}/pages/$p/revisions";
if (-e $revisionsPath) {
opendir(REVISIONSDIR, $revisionsPath) || die "Cannot open $revisionsPath";
@allRevisions = sort grep { /^[^\.].*/ } readdir(REVISIONSDIR);
closedir(REVISIONSDIR);
if (@allRevisions) {
$wikiRevisions{$p} = [ @allRevisions ];
}
$revisionsTotal += scalar @allRevisions;
}
}
# %wikiRevisions now maps directory names to lists of revisions
foreach $p (@portingDirectories) {
$attachmentsPath = "${datapath}/pages/$p/attachments";
if (-e $attachmentsPath) {
opendir(ATTACHMENTSDIR, $attachmentsPath) || die "Cannot open $attachmentsPath";
@allAttachments = sort grep { /^[^\.].*/ } readdir(ATTACHMENTSDIR);
closedir(ATTACHMENTSDIR);
foreach $attachment (@allAttachments) {
my $pagename = ConvertToMWName_($p);
$pagename =~ s/\//\$\$/g; # "/" -> "$$"
$wikiAttachments{$pagename . '$' . $attachment} = "pages/$p/attachments/$attachment";
}
$wikiAttachmentsInDirectory{$p} = [ @allAttachments ];
$attachmentsTotal += $#allAttachments + 1;
}
}
# %wikiAttachmentsInDirectory now maps directory names to lists of attachments
# %wikiAttachments now maps MW upload names to the local paths of the upload files
opendir(USERSDIR,"${datapath}/user") || die "Could not open ";
foreach (grep { /^[\d\.]{3,}(?<!\.trail)$/ } readdir(USERSDIR)) {
my $userid = $_;
open(USER,"<${datapath}/user/$userid") || die "Could not open user file $userid";
my $userdata = do { local( $/ ); <USER> };
close(USER);
$userdata =~ m/\bname=(\w*)/s;
$users{$userid} = $1;
}
closedir(USERDIR);
# %users now maps moinmoin user IDs to user names
$analysed = 1;
}
sub ExportBegin { # Params: TitleWithSpaces,Directory,PageID
my $spacedtitle = shift;
my $directory = shift;
my $pageid = shift;
(my $title = $spacedtitle) =~ s/\s/_/g; # Not needed for MoinMoin names, but here just in case.
open(EXPORT,">$directory/$title.xml") || die "Could not open export file $title.xml ($!)";
ExportPreamble(\*EXPORT);
ExportPageBegin(\*EXPORT,$spacedtitle,$pageid);
}
sub ExportPreamble { # Param: \*FileHandle
my $filehandle = shift;
print $filehandle
"<mediawiki\n" .
" xmlns=\"http://www.mediawiki.org/xml/export-0.3/\"\n" .
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" .
" xsi:schemaLocation=\"http://www.mediawiki.org/xml/export-0.3/ http://www.mediawiki.org/xml/export-0.3.xsd\"\n" .
" version=\"0.3\"\n" .
" xml:lang=\"en\">\n";
}
sub ExportPageBegin { # Params: \*FileHandle,TitleWithSpaces,PageID
my $filehandle = shift;
my $spacedtitle = shift;
my $pageid = shift;
print $filehandle
" <page>\n" .
" <title>" . XMLEscaped(ConvertToMWName($spacedtitle)) . "</title>\n" .
" <id>$pageid</id>\n";
}
sub ExportPageRevision { # Params: \*FileHandle,MWMarkup,RevisionID,TimeStamp,Comment,User,UserID Note: TS=YYYY-MM-DDThh:mm:ssZ
my $filehandle = shift;
my $mwmarkup = shift; # MediaWiki markup (not XML escaped)
my $revisionid = 0 + shift; # Numeric ID with no leading zeros
my ($ss,$mm,$hh,$md,$MM,$YY,undef,undef,undef) = gmtime(substr(shift,0,10));
my $timestamp = sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ',$YY+1900,$MM+1,$md,$hh,$mm,$ss);
my $comment = shift; # No line breaks
my $username = shift; # Name of MediaWiki user
my $userid = shift; # Numeric ID of MediaWiki user
print $filehandle
" <revision>\n" .
" <id>$revisionid</id>\n" .
" <timestamp>$timestamp</timestamp>\n" .
" <contributor>\n" .
" <username>$username</username>\n" .
" <id>$userid</id>\n" .
" </contributor>\n" .
" <comment>".XMLEscaped($comment)."</comment>\n" .
" <text xml:space=\"preserve\">";
print $filehandle XMLEscaped($mwmarkup);
print $filehandle
"</text>\n" .
" </revision>\n";
}
sub ExportPageEnd { # Param: \*FileHandle
my $filehandle = shift;
print $filehandle " </page>\n";
}
sub ExportEnd { # Param: \*FileHandle
my $filehandle = shift;
print $filehandle
"</mediawiki>\n";
close($filehandle);
}
sub sizeOfDirectory {
my $directoryPath = shift;
my $totalBytes = 0;
opendir(SIZEDIR,$directoryPath) || die "Could not open ";
foreach (grep { /^[^\.].*/ } readdir(SIZEDIR)) {
$totalBytes += -s "$directoryPath/$_";
}
closedir(SIZEDIR);
return $totalBytes;
}
# Escape reserved XML characters by replacing with markup entities
sub XMLEscaped {
my $text = shift;
$text =~ s/&/&/go;
$text =~ s/</</go;
$text =~ s/>/>/go;
$text =~ s/'/'/go; #'
$text =~ s/"/"/go; #"
return $text;
}
# See here for moinmoin syntax: http://www.w3.org/2005/MWI/DDWG/wiki/SyntaxReference
# And here: http://www.w3.org/2005/MWI/DDWG/wiki/HelpOnEditing
sub ConvertMM2MW { # Params: infile,outfile,mmname,revision,comment,timestamp
my $infile = shift;
my $outfile = shift;
my $mmname = shift;
my $revision = shift;
my $comment = shift;
my $edittimestamp = shift;
my $mwname = ConvertToMWName($mmname);
my $editdate = gmtime(substr($edittimestamp,0,10));
my $doc = ConvertToMW($infile,$mwname);
open(OUTFILE, ">$outfile") || die "Could not open $outfile";
print OUTFILE "<!-- MoinMoin name: $mmname -->\n";
print OUTFILE "<!-- Comment: $comment -->\n";
print OUTFILE "<!-- WikiMedia name: $mwname -->\n";
print OUTFILE "<!-- Page revision: $revision -->\n";
print OUTFILE "<!-- Original date: $editdate ($edittimestamp) -->\n";
print OUTFILE "\n";
print OUTFILE $doc;
close OUTFILE;
close INFILE;
return $doc;
}
# This converts a MoinMoin page name to a MediaWiki name, with spaces instead of underscores
sub ConvertToMWName { # Param: moinmoinpagename
(my $a = shift) =~ s/\((.*?)\)/DeHex($1)/ige;
$a =~ s/Category(.*)/Category:$1/;
$a =~ s/_/ /g;
return $a;
}
# This converts a MoinMoin page name to a MediaWiki name, with underscores for spaces
sub ConvertToMWName_ { # Param: moinmoinpagename
(my $a = shift) =~ s/\((.*?)\)/DeHex($1)/ige;
$a =~ s/\s/_/g;
return $a;
}
# This converts embedded hex "...(HH...HH)..." into real characters
sub DeHex { # Param: string of hex bytes
my $x = uc shift;
my @y;
return pack('(H2)*',(@y = (split(' ',(($x =~ s/(..)/$1 /g),$x)),@y)));
}
# This converts a MoinMoin table row into a MediaWiki table row
# See: http://www.w3.org/2005/MWI/DDWG/wiki/SyntaxReference
# See: http://www.mediawiki.org/wiki/Help:Tables
sub ProcessTableRow {
chomp(my $mmtr = shift);
my $x;
my $style;
my $celltext;
my $startspanpos;
# Convert long colspans into ||<-N> format
while (($startspanpos = index($mmtr,'||||')) >= 0) {
my $spans = substr($mmtr,$startspanpos); $spans =~ m/^(\|*)/; $spans = $1;
my $endspanpos = rindex($mmtr,'|',$startspanpos);
substr($mmtr,$startspanpos,length($spans)) = '||<-' . (length($spans) / 2) . '>';
}
my @cells = split(/\|\|/,$mmtr);
@cells = @cells[1..@cells-2];
my $mwcells = '';
foreach $x (@cells) {
if ( $x =~ m/^\s*((<.[^>]+>|<\(>|<:>|<\)>)+)(.+)/ ) {
$style = $1;
$celltext = $3;
# combinations
$style =~ s/<(\(|:|\)|\^|v)([^>]+)>/<$1><$2>/g; # e.g. <:90%> --> <:><90%>
# background colour
$style =~ s/<(#[^:]*?):>/bgcolor="$1" /g;
$style =~ s/<bgcolor=([^>]+)>/bgcolor=$1 /g;
# alignment
$style =~ s/<\(>/align="left" /g;
$style =~ s/<style="align\s*:\s*(left|right|center);">/align="$1" /g;
# $style =~ s/<style="align\s*:\s*left;">/align="left" /g;
$style =~ s/<\:>/align="center" /g;
# $style =~ s/<style="align\s*:\s*center;">/align="center" /g;
$style =~ s/<\)>/align="right" /g;
# $style =~ s/<style="align\s*:\s*right;">/align="right" /g;
$style =~ s/<\^>/valign="top" /g;
# $style =~ s/<style="vertical-align\s*:\s*top;">/valign="top" /g;
$style =~ s/<v>/valign="bottom" /g;
$style =~ s/<style="vertical-align\s*:\s*(top|bottom);">/valign="$1" /g;
# rowspan
$style =~ s/<\|(\d+)>/rowspan="$1" /g;
$style =~ s/<(rowspan=[^>]+)>/$1 /g;
# colspan
$style =~ s/<-(\d+)>/colspan="$1" /g;
$style =~ s/<(colspan=[^>]+)>/$1 /g;
# width
$style =~ s/<(\d+)\%>/width="$1%" /g;
# everything else
$style =~ s/tablewidth=".+"/ /g;
$style =~ s/<(rowbgcolor)[^>]+>/ /g;
$style =~ s/<(\w+=[^>])>/$1 /g;
$mwcells .= "|$style|$celltext\n";
}
else {
$mwcells .= "| $x\n";
}
}
return $mwcells;
}
sub ConvertToMW { # Params: MMFilePath, MMName
my $mmfile = shift;
open(INFILE, "<$mmfile") || die "Could not open $mmfile";
my $mwname = shift;
(my $mwname_ = $mwname) =~ s/\s/_/g; # MW name with "_" instead of " "
my $prev = '';
my $listprefix = '';
my $replacementprefix;
my $tabledepth = 0;
my $line;
my @lines;
my $replacement;
my $incode = 0;
my $toc = 0;
my $previouslistindent = '';
my @indents;
my @bullets;
while ($_ = ($line = <INFILE>)){
next if /^----$/; # remove unneeded header lines
if (/\}\}\}/) {
$incode = 0; # Current line contains }}} marking end of code
}
if ($incode) {
push(@lines,$line); # In the middle of 'code', so don't convert the wiki markup
next;
}
if (/\{\{\{(?!.*\}\}\})/) {
$incode = 1; # Current line contains {{{ with no following }}}, so all subsequent lines will be code. (But wiki-convert this line!)
}
# Line-by-line conversions. Most of these will not span across multiple lines.
# MoinMoin command conversions
$line =~ s/^\#REDIRECT \[\[(.*?)\]\]/[[ConvertToMWName($1)]]/e; # Redirect
# Comment out any remaining moinmoin commands (lines starting with #)
$line =~ s/^(\#.*)$/<!-- $1 -->/;
# Normalisation of indented lists
# A. xxxxxxx indent = ' ' bullet = A level = 0
# 1. xxxxxx indent = ' ' bullet = 1 level = 1
# 1. xxxxxx indent = ' ' bullet = 1 level = 1
# A. xxxxxxxx indent = ' ' bullet = A level = 0
# a. xxxxxxx indent = ' ' bullet = a level = 1
# * xxxxxxxx indent = ' ' bullet = * level = 2
# * xxxxxxxx indent = ' ' bullet = * level = 2
# Becomes:
# * '''A)''' xxxxxxx
# *# xxxxxx
# *# xxxxxx
# * '''B)''' xxxxxxxx
# ** '''a)''' xxxxxxx
# *** xxxxxxxx
# *** xxxxxxxx
# Common errors #
$line =~ s/^(\s*)\.\s/$1* /; # Replace false bullet
$line =~ s/\x0b/^k/g; # Replace ^k
$line =~ s/\x0f/^o/g; # Replace ^o
$line =~ s/\x00/^@/g; # Replace ^@
$line =~ s/\x08/^h/g; # Replace ^h
$line =~ s/\x03/^c/g; # Replace ^c
$line =~ s/\x0c/^l/g; # Replace ^l
$line =~ s/\x1b/^[/g; # Replace ^l
$line =~ s/\x0d//g; # Replace ^m
$line =~ s/^(\s*\*)(\S)/$1 $2/; # Insert missing space after bullet in moin-moin list (common error)
if ($line =~ /^([A-Za-z]\.|\*)\s+.+$/) {
$line = " $line"; # indent lines that look like list elements that have forgotted their leading space
}
if ($line =~ /^\s(\s*)((\d+|[\*aAi])\.|\*)\s+(.*)$/) {
my $currentindent = $1;
my $text = $4;
# my $bullet = substr($2,0,1);
my $bullet = $2;
$bullet =~ s/\.//;
my $b;
if ($bullet eq 'i') { $bullet = '1'; } # Don't support Roman bullets (not yet, anyway)
my $indentlevel = scalar(@indents);
if ($indentlevel == 0) { # This is the beginning of a new outermost list
$indents[0] = $currentindent; # record the initial indentation
$bullets[0] = $bullet; # and the initial bullet
}
else { # At least one line of the list has already been processed
# Is this indent bigger, smaller or the same as the previous indent?
my $previousindent = $indents[$indentlevel-1];
if (length($currentindent) < length($previousindent)) { # list is receding
while ($indentlevel > 0 && length($currentindent) <= length($previousindent)) { # recede
$indentlevel--;
$previousindent = $indentlevel?$indents[$indentlevel-1]:''; # examine the "previous previous" indents
}
# At this point the current indent matches the indent at $indentlevel-1
$indentlevel--; # Now $indentlevel is the correct list level for the current line
if ($indentlevel <= 0) { $indentlevel = 0; } # Unless the list appears to have started at a level greater than 1 !
$#indents = $indentlevel; # As we have receded to an outer level, the recorded inner level indents should be removed
#$#indents = $indentlevel?$indentlevel-1:0; $indentlevel--;
$b = $bullets[$indentlevel]; # When you recede to an outer level, you *must* continue that level's bullet type
if ($b =~ /[A-Ya-y]/) {
$bullets[$indentlevel] = chr ( ord ($b) + 1); # When continuing a level, increment lettered bullets
}
}
else { # list is not receding
if (length($currentindent) > length($previousindent)) { # this line is indented further than the previous line
$indents[$indentlevel] = $currentindent; # record the new indentation
$bullets[$indentlevel] = $bullet; # and the new bullet
}
else { # level has remained the same
$indentlevel--; # have not actually indented further, so undo the level increment
$b = $bullets[$indentlevel]; # and examine the bullet from this same level ...
if ($b =~ /[A-Ya-y]/) {
$bullets[$indentlevel] = chr ( ord ($b) + 1); # ... to see if it is a letter bullet that requires incrementing.
}
}
}
}
my $bulletleader = '';
for my $i (0..$indentlevel) { # MediaWiki list item starts with sequence of bullets from level 0 upwards
$b = $bullets[$i];
if ($b eq '*' || $b =~ /[A-Za-z]/) {
$bulletleader .= '*'; # Dot or lettered bullet
}
else {
$bulletleader .= '#'; # Digit
}
}
if ($b =~ /[A-Za-z]/) {
$bulletleader .= " '''$b)'''"; # MediaWiki syntax doesn't have lettered bullets, so insert the letter as a bold extra
}
$line ="$bulletleader $text\n";
}
elsif ($line !~ /^\s*$/) { # We have stopped processing a list; this line is from something else.
$#indents = -1;
}
else { # This is a blank line. If it occurs in the middle of a list, we can have trouble.
$line = "<!--BLANK-->\n"; # Use "blank line" marker. Will be removed after all lines are processed.
}
$_ = $line; # Simplify subsequent regex substitutions
# List conversion (DEPRECATED. Replaced by code above.)
#s/^ \*(\s*.*?)/\*$1/; # 1 ' * xxx' -> '* xxx'
#s/^ \*(\s*.*?)/\*\*$1/; # 2 ' * xxx' -> '** xxx'
#s/^ \*(\s*.*?)/\*\*\*$1/; # 3 ' * xxx' -> '*** xxx'
#s/^ \*(\s*.*?)/\*\*\*\*$1/; # 4 etc.
#s/^ \*(\s*.*?)/\*\*\*\*\*$1/; # 5
#s/^(\s+1\.)#(\d+)/$1 <!-- ! Should start numbering at $2 -->/; # Remove number starts. MW syntax only permits starting at 1
#s/^(\s+)(\d+)\.\s*$/:$2./; # Common idiom. A number on its own on a line. Almost like a numbered list, but not.
#s/^ \d+\.\s+(.*)$/# $1/; # 1 ' 1. xxx' -> '# xxxx' Note: numbering is forced to start at 1
#s/^ \d+\.\s+(.*)$/## $1/; # 2 ' 1. xxx' -> '## xxxx'
#s/^ \d+\.\s+(.*)$/### $1/; # 3 ' 1. xxx' -> '### xxxx'
#s/^ \d+\.\s+(.*)$/#### $1/; # 4 etc.
#s/^ \d+\.\s+(.*)$/##### $1/; # 5
#s/^ (a|A)\.\s+(.*)$/# $2/; # 1 ' a. xxx' -> '# xxxx'
#s/^ (a|A)\.\s+(.*)$/## $2/; # 2 ' a. xxx' -> '## xxxx'
#s/^ (a|A)\.\s+(.*)$/### $2/; # 3 ' a. xxx' -> '### xxxx'
#s/^ (a|A)\.\s+(.*)$/#### $2/; # 4 ' etc.
#s/^ (a|A)\.\s+(.*)$/##### $2/; # 5
# Markup conversion (when on a single line)
s/\^(.*?)\^/\<sup\>$1\<\/sup\>/g; # ^ * ^ -> <sup> * </sup>
s/\,\,(.*?)\,\,/\<sub\>$1\<\/sub\>/g; # ,, * ,, -> <sub> * </sub>
s/__(.*?)__/\<u\>$1\<\/u\>/g; # __ * __ -> <u> * </u>
s/--\((.*?)\)--/\<s\>$1\<\/s\>/g; # --( * )-- -> <s> * </s>
# Mediawiki seems to understand ''', '' and '''''
# s/'''(.*?)'''/\<b\>$1\<\/b\>/g; # ''' * ''' -> <b> * </b>
# s/''(.*?)''/\<i\>$1\<\/i\>/g; # '' * '' -> <i> * </i>
s/~\+(.*?)\+~/\<span style="font-size: larger"\>$1\<\/span\>/g; # ~+xxx+~ -> <span style="font-size: larger">xxx</span>
s/~-(.*?)-~/\<span style="font-size: smaller"\>$1\<\/span\>/g; # ~-xxx-~ -> <span style="font-size: smaller">xxx</span>
s/^ (.*?):: (.*)$/; $1 : $2/; # x:: y -> ; x : y
s/\[\[BR\]\]/\<br\>/g; # [[BR]] -> <br>
# Categories
s/\[http:Category(\w+)\]/[[Category:$1]]/g;
s/\["[^["]*\bCategory(\w+)"\]/[[Category:$1]]/g; #"
s/\[\[?CategoryCategory\]?\]//g;
s/\bCategoryCategory\b//g;
s/\[\[?Category(([A-Z][a-z0-9]+)+)\]?\]/[[Category:$1]]/g;
s/\bCategory(([A-Z][a-z0-9]+)+)\b/[[Category:$1]]/g;
if($mwname =~ /^Category/) {
s/----\s*//s;
s/'''List of pages in this category:'''\s*//s;
s/To add a page to this category, add a link to this page on the last line of the page. You can add multiple categories to a page\.\s*//s;
s/Describe the pages in this category\.\.\.\s*//s;
s/\[\[FullSearch(\([^)]*\))?\]\]\s*//s;
}
# Link conversion
## comment these out as MoinMoin link syntax has changed since 1.5
## see http://moinmo.in/HelpOnLinking
# s/\[\#([^\s|]+)[\s|]+([^\]]+)\]/\[\[\#$1|$2\]\]/g; # [#Foo bar] -> [[#Foo|bar]]
# s/(?<!\[)\[\#([^\s:]+)\]/\[\[\#$1\]\]/g; # [# * ] -> [[ * ]]
# s/\[\"(.*?)\"\]/\[\[$1\]\]/g; # [" * "] -> [[ * ]] (This may be covered by Free Link below)
s/\[:([^:\]]+):([^\]]+)\]/[[$1|$2]]/g; # [:HTML/AddedElementEmbed:embed] -> [[HTML/AddedElementEmbed|embed]]
s/\[\:(.*?)\]/\[\[$1\]\]/g; # [: * ] -> [[ * ]]
# Images
s/\binline:(\S+\.(png|jpg|gif))/[[Image:$1]]/g; # inline:mypic.png -> [[Image:mypic.png]]
# One-line wrappers
s/\{\{\{(.*?)\}\}\}/<code\>\<nowiki\>$1\<\/nowiki\>\<\/code\>/g; # {{{ * }}} -> <code><nowiki> * </nowiki></code>
# Multi-line wrappers