$txt = wfShellExec( $cmd, $retval );
wfProfileOut( 'djvutxt' );
if( $retval == 0) {
+ # Get rid of invalid UTF-8, strip control characters
+ if( is_callable( 'iconv' ) ) {
+ wfSuppressWarnings();
+ $txt = iconv( "UTF-8","UTF-8//IGNORE", $txt );
+ wfRestoreWarnings();
+ } else {
+ $txt = UtfNormal::cleanUp( $txt );
+ }
+ $txt = preg_replace( "/[\013\035\037]/", "", $txt );
$txt = htmlspecialchars($txt);
- $txt = preg_replace( "/\(page\s\d*\s\d*\s\d*\s\d*\s*\"(.*?)\"\s*\)/s", "<PAGE value=\"$1\" />", $txt );
- $txt = preg_replace( "/\(\)/", "<PAGE value=\"\" />", $txt );
+ $txt = preg_replace( "/\((page\s[\d-]*\s[\d-]*\s[\d-]*\s[\d-]*\s*\"([^<]*?)\"\s*|)\)/s", "<PAGE value=\"$2\" />", $txt );
$txt = "<DjVuTxt>\n<HEAD></HEAD>\n<BODY>\n" . $txt . "</BODY>\n</DjVuTxt>\n";
$xml = preg_replace( "/<DjVuXML>/", "<mw-djvu><DjVuXML>", $xml );
$xml = $xml . $txt. '</mw-djvu>' ;