From a58285fd06c8113c45377c655dd43cef6337e815 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 11 Jan 2007 19:06:07 +0000 Subject: Aktualisierung auf MediaWiki 1.9.0 --- includes/Xml.php | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'includes/Xml.php') diff --git a/includes/Xml.php b/includes/Xml.php index 34574458..67dda7fe 100644 --- a/includes/Xml.php +++ b/includes/Xml.php @@ -128,10 +128,13 @@ class Xml { * @return string HTML */ public static function check( $name, $checked=false, $attribs=array() ) { - return self::element( 'input', array( - 'name' => $name, - 'type' => 'checkbox', - 'value' => 1 ) + self::attrib( 'checked', $checked ) + $attribs ); + return self::element( 'input', array_merge( + array( + 'name' => $name, + 'type' => 'checkbox', + 'value' => 1 ), + self::attrib( 'checked', $checked ), + $attribs ) ); } /** @@ -254,6 +257,33 @@ class Xml { return strtr( $string, $pairs ); } + /** + * Encode a variable of unknown type to JavaScript. + * Doesn't support hashtables just yet. + */ + public static function encodeJsVar( $value ) { + if ( is_bool( $value ) ) { + $s = $value ? 'true' : 'false'; + } elseif ( is_null( $value ) ) { + $s = 'null'; + } elseif ( is_int( $value ) ) { + $s = $value; + } elseif ( is_array( $value ) ) { + $s = '['; + foreach ( $value as $name => $elt ) { + if ( $s != '[' ) { + $s .= ', '; + } + $s .= self::encodeJsVar( $elt ); + } + $s .= ']'; + } else { + $s = '"' . self::escapeJsString( $value ) . '"'; + } + return $s; + } + + /** * Check if a string is well-formed XML. * Must include the surrounding tag. @@ -270,8 +300,8 @@ class Xml { xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, false ); if( !xml_parse( $parser, $text, true ) ) { - $err = xml_error_string( xml_get_error_code( $parser ) ); - $position = xml_get_current_byte_index( $parser ); + //$err = xml_error_string( xml_get_error_code( $parser ) ); + //$position = xml_get_current_byte_index( $parser ); //$fragment = $this->extractFragment( $html, $position ); //$this->mXmlError = "$err at byte $position:\n$fragment"; xml_parser_free( $parser ); @@ -297,5 +327,19 @@ class Xml { ''; return Xml::isWellFormed( $html ); } + + /** + * Replace " > and < with their respective HTML entities ( ", + * >, <) + * + * @param $in String: text that might contain HTML tags. + * @return string Escaped string + */ + public static function escapeTagsOnly( $in ) { + return str_replace( + array( '"', '>', '<' ), + array( '"', '>', '<' ), + $in ); + } } ?> -- cgit v1.2.3-54-g00ecf