summaryrefslogtreecommitdiff
path: root/includes/Xml.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2007-01-11 19:06:07 +0000
committerPierre Schmitz <pierre@archlinux.de>2007-01-11 19:06:07 +0000
commita58285fd06c8113c45377c655dd43cef6337e815 (patch)
treedfe31d3d12652352fe44890b4811eda0728faefb /includes/Xml.php
parent20194986f6638233732ba1fc3e838f117d3cc9ea (diff)
Aktualisierung auf MediaWiki 1.9.0
Diffstat (limited to 'includes/Xml.php')
-rw-r--r--includes/Xml.php56
1 files changed, 50 insertions, 6 deletions
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 ) );
}
/**
@@ -255,6 +258,33 @@ class Xml {
}
/**
+ * 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 {
'</html>';
return Xml::isWellFormed( $html );
}
+
+ /**
+ * Replace " > and < with their respective HTML entities ( &quot;,
+ * &gt;, &lt;)
+ *
+ * @param $in String: text that might contain HTML tags.
+ * @return string Escaped string
+ */
+ public static function escapeTagsOnly( $in ) {
+ return str_replace(
+ array( '"', '>', '<' ),
+ array( '&quot;', '&gt;', '&lt;' ),
+ $in );
+ }
}
?>