Merge "maintenance: Script to rename titles for Unicode uppercasing changes"
[lhc/web/wiklou.git] / includes / Html.php
index 61785d5..d0f9fc6 100644 (file)
@@ -518,7 +518,7 @@ class Html {
                                        $newValue = [];
                                        foreach ( $value as $k => $v ) {
                                                if ( is_string( $v ) ) {
-                                                       // String values should be normal `array( 'foo' )`
+                                                       // String values should be normal `[ 'foo' ]`
                                                        // Just append them
                                                        if ( !isset( $value[$v] ) ) {
                                                                // As a special case don't set 'foo' if a
@@ -574,10 +574,8 @@ class Html {
                $attrs = [];
                if ( $nonce !== null ) {
                        $attrs['nonce'] = $nonce;
-               } else {
-                       if ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
-                               wfWarn( "no nonce set on script. CSP will break it" );
-                       }
+               } elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
+                       wfWarn( "no nonce set on script. CSP will break it" );
                }
 
                if ( preg_match( '/<\/?script/i', $contents ) ) {
@@ -600,10 +598,8 @@ class Html {
                $attrs = [ 'src' => $url ];
                if ( $nonce !== null ) {
                        $attrs['nonce'] = $nonce;
-               } else {
-                       if ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
-                               wfWarn( "no nonce set on script. CSP will break it" );
-                       }
+               } elseif ( ContentSecurityPolicy::isNonceRequired( RequestContext::getMain()->getConfig() ) ) {
+                       wfWarn( "no nonce set on script. CSP will break it" );
                }
 
                return self::element( 'script', $attrs );
@@ -835,27 +831,25 @@ class Html {
         * @return array
         */
        public static function namespaceSelectorOptions( array $params = [] ) {
-               $options = [];
-
                if ( !isset( $params['exclude'] ) || !is_array( $params['exclude'] ) ) {
                        $params['exclude'] = [];
                }
 
-               if ( isset( $params['all'] ) ) {
-                       // add an option that would let the user select all namespaces.
-                       // Value is provided by user, the name shown is localized for the user.
-                       $options[$params['all']] = wfMessage( 'namespacesall' )->text();
-               }
                if ( $params['in-user-lang'] ?? false ) {
                        global $wgLang;
                        $lang = $wgLang;
                } else {
                        $lang = MediaWikiServices::getInstance()->getContentLanguage();
                }
-               // Add all namespaces as options
-               $options += $lang->getFormattedNamespaces();
 
                $optionsOut = [];
+               if ( isset( $params['all'] ) ) {
+                       // add an option that would let the user select all namespaces.
+                       // Value is provided by user, the name shown is localized for the user.
+                       $optionsOut[$params['all']] = wfMessage( 'namespacesall' )->text();
+               }
+               // Add all namespaces as options
+               $options = $lang->getFormattedNamespaces();
                // Filter out namespaces below 0 and massage labels
                foreach ( $options as $nsId => $nsName ) {
                        if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
@@ -1010,16 +1004,16 @@ class Html {
        }
 
        /**
-        * Get HTML for an info box with an icon.
+        * Get HTML for an information message box with an icon.
         *
-        * @param string $text Wikitext, get this with wfMessage()->plain()
+        * @internal For use by the WebInstaller class.
+        * @param string $rawHtml HTML
         * @param string $icon Path to icon file (used as 'src' attribute)
         * @param string $alt Alternate text for the icon
         * @param string $class Additional class name to add to the wrapper div
-        *
-        * @return string
+        * @return string HTML
         */
-       static function infoBox( $text, $icon, $alt, $class = '' ) {
+       public static function infoBox( $rawHtml, $icon, $alt, $class = '' ) {
                $s = self::openElement( 'div', [ 'class' => "mw-infobox $class" ] );
 
                $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-left' ] ) .
@@ -1032,7 +1026,7 @@ class Html {
                                self::closeElement( 'div' );
 
                $s .= self::openElement( 'div', [ 'class' => 'mw-infobox-right' ] ) .
-                               $text .
+                               $rawHtml .
                                self::closeElement( 'div' );
                $s .= self::element( 'div', [ 'style' => 'clear: left;' ], ' ' );