* (bug 20464) Force manual recaching to false in LocalisationCache::disableBackend...
[lhc/web/wiklou.git] / includes / Html.php
index 075cb3b..8d97bc4 100644 (file)
@@ -100,6 +100,7 @@ class Html {
         * @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
@@ -187,6 +188,7 @@ class 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)
         */
@@ -195,6 +197,10 @@ class Html {
 
                $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 )
@@ -256,11 +262,13 @@ class Html {
         * @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 );
@@ -294,15 +302,15 @@ class Html {
         * @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;
                }
@@ -339,8 +347,8 @@ class Html {
         * @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() ) {
@@ -354,4 +362,18 @@ class Html {
 
                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 );
+       }
 }