From a1521389271e6b1547222af2b166a27f38331986 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Fri, 3 Sep 2004 06:49:17 +0000 Subject: [PATCH] Normalize output for Special:Export. --- includes/SpecialExport.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/includes/SpecialExport.php b/includes/SpecialExport.php index c2ccbe8337..6bc83d8657 100644 --- a/includes/SpecialExport.php +++ b/includes/SpecialExport.php @@ -82,7 +82,7 @@ function page2xml( $page, $curonly, $full = false ) { 'cur_user_text as user_text', 'cur_restrictions as restrictions','cur_comment as comment', 'cur_text as text' ), $title->curCond(), $fname ); if( $s !== false ) { - $tl = htmlspecialchars( $title->getPrefixedText() ); + $tl = xmlsafe( $title->getPrefixedText() ); $xml = " \n"; $xml .= " $tl\n"; if( $full ) { @@ -117,21 +117,21 @@ function revision2xml( $s, $full, $cur ) { $xml .= " $s->id\n"; $xml .= " $ts\n"; if($s->user) { - $u = "" . htmlspecialchars( $s->user_text ) . ""; + $u = "" . xmlsafe( $s->user_text ) . ""; if($full) $u .= "$s->user"; } else { - $u = "" . htmlspecialchars( $s->user_text ) . ""; + $u = "" . xmlsafe( $s->user_text ) . ""; } $xml .= " $u\n"; if( !empty( $s->minor ) ) { $xml .= " \n"; } if($s->comment != "") { - $c = htmlspecialchars( $s->comment ); + $c = xmlsafe( $s->comment ); $xml .= " $c\n"; } - $t = htmlspecialchars( Article::getRevisionText( $s, "" ) ); + $t = xmlsafe( Article::getRevisionText( $s, "" ) ); $xml .= " $t\n"; $xml .= " \n"; return $xml; @@ -142,4 +142,15 @@ function wfTimestamp2ISO8601( $ts ) { return preg_replace( '/^(....)(..)(..)(..)(..)(..)$/', '$1-$2-$3T$4:$5:$6Z', $ts ); } -?> +function xmlsafe( $string ) { + # May contain old data which has not been properly normalized. + global $wgUseLatin1; + if( $wgUseLatin1 ) { + $string = preg_replace( '/[\x00-\x08\x0b-\x1f]/', '', $string ); + } else { + $string = UtfNormal::cleanUp( $string ); + } + return htmlspecialchars( $string ); +} + +?> \ No newline at end of file -- 2.20.1