$attribs = array_map( array( 'UtfNormal', 'cleanUp' ), $attribs );
}
if( $contents ) {
+ wfProfileIn( __METHOD__ . '-norm' );
$contents = UtfNormal::cleanUp( $contents );
+ wfProfileOut( __METHOD__ . '-norm' );
}
return self::element( $element, $attribs, $contents );
}
* @param $includehidden Bool: include hidden namespaces?
* @return String: Html string containing the namespace selector
*/
- public static function &namespaceSelector($selected = '', $allnamespaces = null, $includehidden=false) {
+ public static function namespaceSelector($selected = '', $allnamespaces = null, $includehidden=false) {
global $wgContLang;
if( $selected !== '' ) {
if( is_null( $selected ) ) {
* @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 ) );
}
/**
'type' => 'hidden',
'value' => $value ) + $attribs );
}
+
+ /**
+ * Convenience function to build an HTML drop-down list item.
+ * @param $text String: text for this item
+ * @param $value String: form submission value; if empty, use text
+ * @param $selected boolean: if true, will be the default selected item
+ * @param $attribs array: optional additional HTML attributes
+ * @return string HTML
+ */
+ public static function option( $text, $value=null, $selected=false,
+ $attribs=array() ) {
+ if( !is_null( $value ) ) {
+ $attribs['value'] = $value;
+ }
+ if( $selected ) {
+ $attribs['selected'] = 'selected';
+ }
+ return self::element( 'option', $attribs, $text );
+ }
/**
* Returns an escaped string suitable for inclusion in a string literal
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.
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 );
'</html>';
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 );
+ }
}
?>