This patch expands the "Upload" page with another form which allows Microsoft Word documents to be uploaded. The document is parsed and a "preview" page appears with the contents of the documents converted to UseModWiki markup. Internally, the document is first converted to HTML by wvHtml (part of the wv package), and the resulting page is then converted to wiki text by HTML::WikiConverter?.
This particular patch is a bit trickier to install and use than the rest of my patches, mostly due to the external requirements.
If the script doesn't work, please check your installation of wv and HTML::WikiConverter?, as well as your config file first. The web server's error log is also likely to hold some useful info.
--- wiki.pl 2003-09-11 14:21:02.000000000 +0200 +++ MicrosoftWordUpload.pl 2005-10-20 12:15:57.000000000 +0200 @@ -53,7 +53,9 @@ @IsbnNames @IsbnPre @IsbnPost $EmailFile $FavIcon $RssDays $UserHeader $UserBody $StartUID $ParseParas $AuthorFooter $UseUpload $AllUpload $UploadDir $UploadUrl $LimitFileUrl $MaintTrimRc $SearchButton - $EditNameLink $UseMetaWiki @ImageSites $BracketImg ); + $EditNameLink $UseMetaWiki @ImageSites $BracketImg + $MicrosoftWordUpload + ); # Note: $NotifyDefault is kept because it was a config variable in 0.90 # Other global variables: use vars qw(%Page %Section %Text %InterSite %SaveUrl %SaveNumUrl @@ -75,7 +77,7 @@ $HomePage = "HomePage"; # Home page (change space to _) $RCName = "RecentChanges"; # Name of changes page (change space to _) $LogoUrl = "/wiki.gif"; # URL for site logo ("" for no logo) -$ENV{PATH} = "/usr/bin/"; # Path used to find "diff" +$ENV{PATH} = "/usr/bin/:/bin/"; # Path used to find "diff" and "sed" $ScriptTZ = ""; # Local time zone ("" means do not print) $RcDefault = 30; # Default number of RecentChanges days @RcDays = qw(1 3 7 30 90); # Days for links on RecentChanges @@ -132,6 +134,7 @@ $TableSyntax = 1; # 1 = wiki syntax tables, 0 = no table syntax $NewFS = 0; # 1 = new multibyte $FS, 0 = old $FS $UseUpload = 0; # 1 = allow uploads, 0 = no uploads +$MicrosoftWordUpload = 1; # Word->wiki conversion (see docs @ www.usemod.org) # Minor options: $LogoLeft = 0; # 1 = logo on left, 0 = logo on right @@ -3153,6 +3156,10 @@ &SaveUpload(); return; } + if ($UseUpload && $MicrosoftWordUpload && (&GetParam("uploadword", 0))) { + &SaveMicrosoftWordUpload(); + return; + } $search = &GetParam("search", ""); if (($search ne "") || (&GetParam("dosearch", "") ne "")) { &DoSearch($search); @@ -4911,9 +4918,18 @@ print '<FORM METHOD="post" ACTION="' . $ScriptName . '" ENCTYPE="multipart/form-data">'; print '<input type="hidden" name="upload" value="1" />'; - print 'File to Upload: <INPUT TYPE="file" NAME="file"><br><BR>'; - print '<INPUT TYPE="submit" NAME="Submit" VALUE="Upload">'; + print T('File to Upload:'), ' <INPUT TYPE="file" NAME="file"><br><BR>'; + print '<INPUT TYPE="submit" NAME="Submit" VALUE="', T('Upload'), '">'; print '</FORM>'; + if ($MicrosoftWordUpload) { + print '<hr><FORM METHOD="post" ACTION="' . $ScriptName + . '" ENCTYPE="multipart/form-data">'; + print '<input type="hidden" name="uploadword" value="1" />'; + print T('Microsoft Word File to Upload:'), ' <INPUT TYPE="file" NAME="file"><BR>'; + print T('New Page Title:'), ' <INPUT TYPE="text" NAME="newpagetitle"><BR><BR>'; + print '<INPUT TYPE="submit" NAME="Submit" VALUE="', T('Upload'), '">'; + print '</FORM>'; + } print &GetCommonFooter(); } @@ -4942,6 +4958,34 @@ print &GetCommonFooter(); } +sub SaveMicrosoftWordUpload() { + my ($uploadFilehandle, $wikiConverter, $html, $wikiText); + if (!$AllUpload) { + return if (!&UserIsEditorOrError()); + } + &RequestLock(); + unlink("$TempDir/MicrosoftWordUpload.doc"); + unlink("$TempDir/MicrosoftWordUpload.html"); + $uploadFilehandle = $q->upload('file'); + open UPLOADFILE, ">$TempDir/MicrosoftWordUpload.doc"; + while (<$uploadFilehandle>) { print UPLOADFILE; } + close UPLOADFILE; + `wvHtml $TempDir/MicrosoftWordUpload.doc --targetdir=$TempDir --charset=iso-8859-2 MicrosoftWordUpload.html`; + + use HTML::WikiConverter; + $wikiConverter = new HTML::WikiConverter( dialect => 'UseMod' ); + open HTML, "$TempDir/MicrosoftWordUpload.html" or die "Couldn't open $TempDir/MicrosoftWordUpload.html: $!"; + while (sysread(HTML, $html, 16384, length($html)) > 0) {} + close HTML; + &ReleaseLock(); + + $wikiText = $wikiConverter->html2wiki($html); + use Encode; + $wikiText = encode("iso-8859-1", $wikiText); + + &DoEdit(&GetParam('newpagetitle', 'WordPage'), 0, 0, $wikiText, 1); +} + sub ConvertFsFile { my ($oldFS, $newFS, $fname) = @_; my ($oldData, $newData, $status);