Fixing dump tests for non-wikitext in NS_MAIN.
[lhc/web/wiklou.git] / includes / Html.php
index 83af24a..a07dd4c 100644 (file)
@@ -191,12 +191,8 @@ class Html {
                        return '';
                }
 
-               # Remove HTML5-only attributes if we aren't doing HTML5, and disable
-               # form validation regardless (see bug 23769 and the more detailed
-               # comment in expandAttributes())
+               # Remove invalid input types
                if ( $element == 'input' ) {
-                       # Whitelist of types that don't cause validation.  All except
-                       # 'search' are valid in XHTML1.
                        $validTypes = array(
                                'hidden',
                                'text',
@@ -208,9 +204,9 @@ class Html {
                                'image',
                                'reset',
                                'button',
-                               'search',
                        );
 
+                       # Allow more input types in HTML5 mode
                        if( $wgHtml5 ) {
                                $validTypes = array_merge( $validTypes, array(
                                        'datetime',
@@ -232,11 +228,6 @@ class Html {
                        && !in_array( $attribs['type'], $validTypes ) ) {
                                unset( $attribs['type'] );
                        }
-
-                       if ( isset( $attribs['type'] ) && $attribs['type'] == 'search'
-                       && !$wgHtml5 ) {
-                               unset( $attribs['type'] );
-                       }
                }
 
                if ( !$wgHtml5 && $element == 'textarea' && isset( $attribs['maxlength'] ) ) {
@@ -762,7 +753,7 @@ class Html {
         * - name: [optional], default: 'namespace'
         * @return string HTML code to select a namespace.
         */
-       public static function namespaceSelector( Array $params = array(), Array $selectAttribs = array() ) {
+       public static function namespaceSelector( array $params = array(), array $selectAttribs = array() ) {
                global $wgContLang;
 
                ksort( $selectAttribs );
@@ -805,10 +796,12 @@ class Html {
                        if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
                                continue;
                        }
-                       if ( $nsId === 0 ) {
+                       if ( $nsId === NS_MAIN ) {
                                // For other namespaces use use the namespace prefix as label, but for
                                // main we don't use "" but the user message descripting it (e.g. "(Main)" or "(Article)")
                                $nsName = wfMessage( 'blanknamespace' )->text();
+                       } elseif ( is_int( $nsId ) ) {
+                               $nsName = $wgContLang->convertNamespace( $nsId );
                        }
                        $optionsHtml[] = Html::element(
                                'option', array(
@@ -819,6 +812,14 @@ class Html {
                        );
                }
 
+               if ( !array_key_exists( 'id', $selectAttribs ) ) {
+                       $selectAttribs['id'] = 'namespace';
+               }
+
+               if ( !array_key_exists( 'name', $selectAttribs ) ) {
+                       $selectAttribs['name'] = 'namespace';
+               }
+
                $ret = '';
                if ( isset( $params['label'] ) ) {
                        $ret .= Html::element(
@@ -941,4 +942,22 @@ class Html {
 
                return $s;
        }
+
+       /**
+        * Generate a srcset attribute value from an array mapping pixel densities
+        * to URLs. Note that srcset supports width and height values as well, which
+        * are not used here.
+        *
+        * @param array $urls
+        * @return string
+        */
+       static function srcSet( $urls ) {
+               $candidates = array();
+               foreach( $urls as $density => $url ) {
+                       // Image candidate syntax per current whatwg live spec, 2012-09-23:
+                       // http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content-1.html#attr-img-srcset
+                       $candidates[] = "{$url} {$density}x";
+               }
+               return implode( ", ", $candidates );
+       }
 }