* @param $element string The element's name, e.g., 'a'
* @param $attribs array Associative array of attributes, e.g., array(
* 'href' => 'http://www.mediawiki.org/' ). Values will be HTML-escaped.
+ * A value of false means to omit the attribute.
* @param $contents string The raw HTML contents of the element: *not*
* escaped!
* @return string Raw HTML
*
* @param $attribs array Associative array of attributes, e.g., array(
* 'href' => 'http://www.mediawiki.org/' ). Values will be HTML-escaped.
+ * A value of false means to omit the attribute.
* @return string HTML fragment that goes between element name and '>'
* (starting with a space if at least one attribute is output)
*/
$ret = '';
foreach ( $attribs as $key => $value ) {
+ if ( $value === false ) {
+ continue;
+ }
+
# For boolean attributes, support array( 'foo' ) instead of
# requiring array( 'foo' => 'meaningless' ).
if ( is_int( $key )
* @return string Raw HTML
*/
public static function inlineScript( $contents ) {
- global $wgHtml5, $wgJsMimeType;
+ global $wgHtml5, $wgJsMimeType, $wgWellFormedXml;
$attrs = array();
if ( !$wgHtml5 ) {
$attrs['type'] = $wgJsMimeType;
+ }
+ if ( $wgWellFormedXml && preg_match( '/[<&]/', $contents ) ) {
$contents = "/*<![CDATA[*/$contents/*]]>*/";
}
return self::rawElement( 'script', $attrs, $contents );
* @return string Raw HTML
*/
public static function inlineStyle( $contents, $media = null ) {
- global $wgHtml5;
+ global $wgHtml5, $wgWellFormedXml;
$attrs = array();
if ( !$wgHtml5 ) {
- # Technically we should probably add CDATA stuff here like with
- # scripts, but in practice, stylesheets tend not to have
- # problematic characters anyway.
$attrs['type'] = 'text/css';
}
+ if ( $wgWellFormedXml && preg_match( '/[<&]/', $contents ) ) {
+ $contents = "/*<![CDATA[*/$contents/*]]>*/";
+ }
if ( $media !== null ) {
$attrs['media'] = $media;
}
* @param $name string name attribute
* @param $value mixed value attribute (null = omit)
* @param $type string type attribute
- * @param $attribs array Assocative array of miscellaneous extra attributes,
- * passed to Html::element()
+ * @param $attribs array Associative array of miscellaneous extra
+ * attributes, passed to Html::element()
* @return string Raw HTML
*/
public static function input( $name, $value = null, $type = 'text', $attribs = array() ) {
return self::element( 'input', $attribs );
}
+
+ /**
+ * Convenience function to produce an input element with type=hidden, like
+ * Xml::hidden.
+ *
+ * @param $name string name attribute
+ * @param $value string value attribute
+ * @param $attribs array Associative array of miscellaneous extra
+ * attributes, passed to Html::element()
+ * @return string Raw HTML
+ */
+ public static function hidden( $name, $value, $attribs = array() ) {
+ return self::input( $name, $value, 'hidden', $attribs );
+ }
}