Merge "docs/hooks.txt: fix incorrect description of UploadForm:* hooks"
[lhc/web/wiklou.git] / includes / OutputPage.php
index 564641a..0b2ba40 100644 (file)
@@ -642,9 +642,7 @@ class OutputPage extends ContextSource {
                        // Register a callback for $this->contentOverrides on the first call
                        $this->addContentOverrideCallback( function ( LinkTarget $target ) {
                                $key = $target->getNamespace() . ':' . $target->getDBkey();
-                               return isset( $this->contentOverrides[$key] )
-                                       ? $this->contentOverrides[$key]
-                                       : null;
+                               return $this->contentOverrides[$key] ?? null;
                        } );
                }
 
@@ -757,11 +755,7 @@ class OutputPage extends ContextSource {
         * @return mixed Property value or null if not found
         */
        public function getProperty( $name ) {
-               if ( isset( $this->mProperties[$name] ) ) {
-                       return $this->mProperties[$name];
-               } else {
-                       return null;
-               }
+               return $this->mProperties[$name] ?? null;
        }
 
        /**
@@ -1370,7 +1364,8 @@ class OutputPage extends ContextSource {
                );
 
                # Add the results to the link cache
-               $lb->addResultToCache( LinkCache::singleton(), $res );
+               $linkCache = MediaWikiServices::getInstance()->getLinkCache();
+               $lb->addResultToCache( $linkCache, $res );
 
                return $res;
        }
@@ -1516,9 +1511,7 @@ class OutputPage extends ContextSource {
                if ( $type == ResourceLoaderModule::TYPE_COMBINED ) {
                        return min( array_values( $this->mAllowedModules ) );
                } else {
-                       return isset( $this->mAllowedModules[$type] )
-                               ? $this->mAllowedModules[$type]
-                               : ResourceLoaderModule::ORIGIN_ALL;
+                       return $this->mAllowedModules[$type] ?? ResourceLoaderModule::ORIGIN_ALL;
                }
        }
 
@@ -2649,13 +2642,13 @@ class OutputPage extends ContextSource {
 
                        foreach ( $errors as $error ) {
                                $text .= '<li>';
-                               $text .= call_user_func_array( [ $this, 'msg' ], $error )->plain();
+                               $text .= $this->msg( ...$error )->plain();
                                $text .= "</li>\n";
                        }
                        $text .= '</ul>';
                } else {
                        $text .= "<div class=\"permissions-errors\">\n" .
-                                       call_user_func_array( [ $this, 'msg' ], reset( $errors ) )->plain() .
+                                       $this->msg( ...reset( $errors ) )->plain() .
                                        "\n</div>";
                }
 
@@ -3115,13 +3108,13 @@ class OutputPage extends ContextSource {
 
                // Pre-process information
                $separatorTransTable = $lang->separatorTransformTable();
-               $separatorTransTable = $separatorTransTable ? $separatorTransTable : [];
+               $separatorTransTable = $separatorTransTable ?: [];
                $compactSeparatorTransTable = [
                        implode( "\t", array_keys( $separatorTransTable ) ),
                        implode( "\t", $separatorTransTable ),
                ];
                $digitTransTable = $lang->digitTransformTable();
-               $digitTransTable = $digitTransTable ? $digitTransTable : [];
+               $digitTransTable = $digitTransTable ?: [];
                $compactDigitTransTable = [
                        implode( "\t", array_keys( $digitTransTable ) ),
                        implode( "\t", $digitTransTable ),
@@ -3904,7 +3897,7 @@ class OutputPage extends ContextSource {
         */
        public static function setupOOUI( $skinName = 'default', $dir = 'ltr' ) {
                $themes = ResourceLoaderOOUIModule::getSkinThemeMap();
-               $theme = isset( $themes[$skinName] ) ? $themes[$skinName] : $themes['default'];
+               $theme = $themes[$skinName] ?? $themes['default'];
                // For example, 'OOUI\WikimediaUITheme'.
                $themeClass = "OOUI\\{$theme}Theme";
                OOUI\Theme::setSingleton( new $themeClass() );
@@ -3968,12 +3961,8 @@ class OutputPage extends ContextSource {
                uksort( $logosPerDppx, function ( $a , $b ) {
                        $a = floatval( $a );
                        $b = floatval( $b );
-
-                       if ( $a == $b ) {
-                               return 0;
-                       }
                        // Sort from smallest to largest (e.g. 1x, 1.5x, 2x)
-                       return ( $a < $b ) ? -1 : 1;
+                       return $a <=> $b;
                } );
 
                foreach ( $logosPerDppx as $dppx => $src ) {
@@ -4026,8 +4015,8 @@ class OutputPage extends ContextSource {
                }
                if ( $this->CSPNonce === null ) {
                        // XXX It might be expensive to generate randomness
-                       // on every request, on windows.
-                       $rand = MWCryptRand::generate( 15 );
+                       // on every request, on Windows.
+                       $rand = random_bytes( 15 );
                        $this->CSPNonce = base64_encode( $rand );
                }
                return $this->CSPNonce;