* @return string Raw HTML
*/
public static function rawElement( $element, $attribs = array(), $contents = '' ) {
+ global $wgWellFormedXml;
+ $start = self::openElement( $element, $attribs );
+ if ( in_array( $element, self::$voidElements ) ) {
+ if ( $wgWellFormedXml ) {
+ # Silly XML.
+ return substr( $start, 0, -1 ) . ' />';
+ }
+ return $start;
+ } else {
+ return "$start$contents</$element>";
+ }
+ }
+
+ /**
+ * Identical to rawElement(), but HTML-escapes $contents (like
+ * Xml::element()).
+ */
+ public static function element( $element, $attribs = array(), $contents = '' ) {
+ return self::rawElement( $element, $attribs, strtr( $contents, array(
+ # There's no point in escaping quotes, >, etc. in the contents of
+ # elements.
+ '&' => '&',
+ '<' => '<'
+ ) ) );
+ }
+
+ /**
+ * Identical to rawElement(), but has no third parameter and omits the end
+ * tag (and the self-closing / in XML mode for empty elements).
+ */
+ public static function openElement( $element, $attribs = array() ) {
global $wgHtml5, $wgWellFormedXml;
$attribs = (array)$attribs;
# This is not required in HTML5, but let's do it anyway, for
}
}
- $start = "<$element" . self::expandAttributes(
- self::dropDefaults( $element, $attribs ) );
- if ( in_array( $element, self::$voidElements ) ) {
- if ( $wgWellFormedXml ) {
- return "$start />";
- }
- return "$start>";
- } else {
- return "$start>$contents</$element>";
- }
- }
-
- /**
- * Identical to rawElement(), but HTML-escapes $contents (like
- * Xml::element()).
- */
- public static function element( $element, $attribs = array(), $contents = '' ) {
- return self::rawElement( $element, $attribs, strtr( $contents, array(
- # There's no point in escaping quotes, >, etc. in the contents of
- # elements.
- '&' => '&',
- '<' => '<'
- ) ) );
+ return "<$element" . self::expandAttributes(
+ self::dropDefaults( $element, $attribs ) ) . '>';
}
/**
global $wgHtml5;
$attribs['name'] = $name;
if ( !$wgHtml5 ) {
- if ( !array_key_exists('cols', $attribs) )
+ if ( !isset( $attribs['cols'] ) )
$attribs['cols'] = "";
- if ( !array_key_exists('rows', $attribs) )
+ if ( !isset( $attribs['rows'] ) )
$attribs['rows'] = "";
}
return self::element( 'textarea', $attribs, $value );