Index: trunk/wiki2xml/php/README |
— | — | @@ -0,0 +1,79 @@ |
| 2 | +=pod |
| 3 | + |
| 4 | +You can read this document better with: |
| 5 | + |
| 6 | + perldoc README |
| 7 | + |
| 8 | +Otherwise, please just ignore the funny characters. |
| 9 | + |
| 10 | +=head1 NAME |
| 11 | + |
| 12 | +WIKI2XML - Wikitext to XML converter |
| 13 | + |
| 14 | +=head1 INSTALLATION |
| 15 | + |
| 16 | +=head2 Download/Checkout |
| 17 | + |
| 18 | +Check out the current release from SVN: |
| 19 | + |
| 20 | + svn co http://svn.wikimedia.org/svnroot/mediawiki/trunk/wiki2xml |
| 21 | + |
| 22 | +=head2 Copy files |
| 23 | + |
| 24 | +Copy the subdirectory C<< ./php/ >> to your server's C<< wiki/ >> |
| 25 | +directory as a subdirectory named C<< w2x >>: |
| 26 | + |
| 27 | + htdocs |
| 28 | + \- wiki |
| 29 | + \- w2x <-- here |
| 30 | + \- w2x.php |
| 31 | + \- wiki2xml.php etc |
| 32 | + |
| 33 | +=head2 Configuration |
| 34 | + |
| 35 | +The configuration is stored in C<< default.php >> and C<< local.php >>. |
| 36 | + |
| 37 | +There is a C<< sample_local.php >> file, copy it to C<< local.php >> |
| 38 | +and then edit it to match your configuration. |
| 39 | + |
| 40 | +On a Unix/Linux server the following can be used as a starting point: |
| 41 | + |
| 42 | + $xmlg["temp_dir"] = "/tmp"; # Directory for temporary files |
| 43 | + |
| 44 | + #$xmlg["zip_odt_path"] = ""; # Path to the zip/unzip programs; can be omitted |
| 45 | + # if in default execuatable path |
| 46 | + $xmlg["zip_odt"] = 'zip -r9 $1 $2'; # Command to zip directory $1 to file $2 |
| 47 | + $xmlg["unzip_odt"] = 'unzip -x $1 -d $2'; # Command to unzip file $1 to directory $2 |
| 48 | + |
| 49 | +=head1 USAGE |
| 50 | + |
| 51 | +Open the following in your browser: |
| 52 | + |
| 53 | + http://example.com/wiki/w2x/w2x.php |
| 54 | + |
| 55 | +It should present you with a form with a textarea and several buttons. |
| 56 | + |
| 57 | +=head1 TROUBLESHOOTING |
| 58 | + |
| 59 | +If you get errors like the following: |
| 60 | + |
| 61 | + Warning: fopen(/tmp/ODD6Rq1qt-DIR/content.xml): failed to open stream: |
| 62 | + No such file or directory in /.../wiki/wiki2xml/w2x.php on line 112 |
| 63 | + |
| 64 | +then make sure that the tmp directory you selected is really writable by |
| 65 | +your webserver. |
| 66 | + |
| 67 | +=head2 OpenOffice Output |
| 68 | + |
| 69 | +For OpenOffice output, the converter will extract a file called C<< template.odt >> |
| 70 | +into the temp directory. It will then replace/modify the files in it, zip it |
| 71 | +up again and then offer the browser the resulting file as a download. |
| 72 | + |
| 73 | +=head1 AUTHOR |
| 74 | + |
| 75 | +Copyright 2005-2006 by Magnus Manske <magnus.manske@web.de> |
| 76 | + |
| 77 | +Released under the GPL. |
| 78 | + |
| 79 | +=cut |
| 80 | + |
Index: trunk/wiki2xml/php/w2x.php |
— | — | @@ -23,8 +23,8 @@ |
24 | 24 | |
25 | 25 | $content_provider = new ContentProviderHTTP ; |
26 | 26 | $converter = new MediaWikiConverter ; |
27 | | - |
28 | | - $xmlg["book_title"] = $_POST['document_title'] ; |
| 27 | + |
| 28 | + $xmlg["book_title"] = $_POST['document_title'] || 'document'; |
29 | 29 | $xmlg["site_base_url"] = $_POST['site'] ; |
30 | 30 | $xmlg["resolvetemplates"] = $_POST['use_templates'] ; |
31 | 31 | $xmlg['templates'] = explode ( "\n" , $_POST['templates'] ) ; |
— | — | @@ -110,6 +110,7 @@ |
111 | 111 | |
112 | 112 | # Create ODT structure |
113 | 113 | $handle = fopen ( $dir . "/content.xml" , "w" ) ; |
| 114 | +/* Old code |
114 | 115 | fwrite ( $handle , $out ) ; |
115 | 116 | fclose ( $handle ) ; |
116 | 117 | |
— | — | @@ -138,7 +139,41 @@ |
139 | 140 | @rmdir ( $dir ) ; |
140 | 141 | @unlink ( $dir_file ) ; |
141 | 142 | @unlink ( $out_file ) ; |
142 | | - chdir ( $cwd ) ; |
| 143 | + chdir ( $cwd ) ;*/ |
| 144 | + |
| 145 | + if ($handle) { |
| 146 | + fwrite ( $handle , $out ) ; |
| 147 | + # Generate temporary ODT file |
| 148 | + $out_file = tempnam($dir, "ODT"); |
| 149 | + $cmd = $xmlg['zip_odt'] ; |
| 150 | + $cmd = str_replace ( '$1' , escapeshellarg ( $out_file ) , $cmd ) ; |
| 151 | + $cmd = str_replace ( '$2' , escapeshellarg ( $dir . "/" ) , $cmd ) ; |
| 152 | + @unlink ( $out_file ) ; |
| 153 | + exec ( $cmd ) ; |
| 154 | + |
| 155 | + if ( $format == "odt" ) { # Return ODT file |
| 156 | + $filename = $xmlg["book_title"] ; |
| 157 | + if (!preg_match('/\.[a-zA-Z]{3}$/',$filename)) { $filename .= '.odt'; } |
| 158 | + if (!preg_match('/\.[a-zA-Z]{3}$/',$out_file)) { $out_file .= '.zip'; } |
| 159 | + header('Content-type: application/vnd.oasis.opendocument.text; charset=utf-8'); |
| 160 | + header('Content-Disposition: inline; filename="'.$filename.'"'); |
| 161 | + # XXX TODO: error handling here |
| 162 | + $handle = fopen($out_file, 'rb'); |
| 163 | + fpassthru ( $handle ) ; |
| 164 | + fclose ( $handle ) ; |
| 165 | + } else { # Return XML |
| 166 | + header('Content-type: text/xml; charset=utf-8'); |
| 167 | + print str_replace ( ">" , ">\n" , $out ) ; |
| 168 | + } |
| 169 | + |
| 170 | + # Cleanup |
| 171 | + SureRemoveDir ( $dir ) ; |
| 172 | + @rmdir ( $dir ) ; |
| 173 | + @unlink ( $dir_file ) ; |
| 174 | + @unlink ( $out_file ) ; |
| 175 | + chdir ( $cwd ) ; |
| 176 | + } # error occured |
| 177 | + |
143 | 178 | } else if ( $format == "docbook_xml" ) { |
144 | 179 | $out = $converter->articles2docbook_xml ( $xml , $xmlg ) ; |
145 | 180 | header('Content-type: text/xml; charset=utf-8'); |