Merge "Move cookie-blocking methods to BlockManager"
[lhc/web/wiklou.git] / includes / preferences / DefaultPreferencesFactory.php
index a5c8064..beed60b 100644 (file)
@@ -39,8 +39,8 @@ use MediaWiki\Linker\LinkRenderer;
 use MediaWiki\MediaWikiServices;
 use MessageLocalizer;
 use MWException;
-use MWNamespace;
 use MWTimestamp;
+use NamespaceInfo;
 use OutputPage;
 use Parser;
 use ParserOptions;
@@ -74,6 +74,9 @@ class DefaultPreferencesFactory implements PreferencesFactory {
        /** @var LinkRenderer */
        protected $linkRenderer;
 
+       /** @var NamespaceInfo */
+       protected $nsInfo;
+
        /**
         * TODO Make this a const when we drop HHVM support (T192166)
         *
@@ -108,16 +111,20 @@ class DefaultPreferencesFactory implements PreferencesFactory {
        ];
 
        /**
-        * @param array|Config $options Config accepted for backwards compatibility
+        * Do not call this directly.  Get it from MediaWikiServices.
+        *
+        * @param ServiceOptions|Config $options Config accepted for backwards compatibility
         * @param Language $contLang
         * @param AuthManager $authManager
         * @param LinkRenderer $linkRenderer
+        * @param NamespaceInfo|null $nsInfo
         */
        public function __construct(
                $options,
                Language $contLang,
                AuthManager $authManager,
-               LinkRenderer $linkRenderer
+               LinkRenderer $linkRenderer,
+               NamespaceInfo $nsInfo = null
        ) {
                if ( $options instanceof Config ) {
                        wfDeprecated( __METHOD__ . ' with Config parameter', '1.34' );
@@ -126,10 +133,15 @@ class DefaultPreferencesFactory implements PreferencesFactory {
 
                $options->assertRequiredOptions( self::$constructorOptions );
 
+               if ( !$nsInfo ) {
+                       wfDeprecated( __METHOD__ . ' with no NamespaceInfo argument', '1.34' );
+                       $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
+               }
                $this->options = $options;
                $this->contLang = $contLang;
                $this->authManager = $authManager;
                $this->linkRenderer = $linkRenderer;
+               $this->nsInfo = $nsInfo;
                $this->logger = new NullLogger();
        }
 
@@ -484,18 +496,6 @@ class DefaultPreferencesFactory implements PreferencesFactory {
                        }
                }
 
-               // Stuff from Language::getExtraUserToggles()
-               // FIXME is this dead code? $extraUserToggles doesn't seem to be defined for any language
-               $toggles = $this->contLang->getExtraUserToggles();
-
-               foreach ( $toggles as $toggle ) {
-                       $defaultPreferences[$toggle] = [
-                               'type' => 'toggle',
-                               'section' => 'personal/i18n',
-                               'label-message' => "tog-$toggle",
-                       ];
-               }
-
                // show a preview of the old signature first
                $oldsigWikiText = MediaWikiServices::getInstance()->getParser()->preSaveTransform(
                        '~~~',
@@ -1262,7 +1262,7 @@ class DefaultPreferencesFactory implements PreferencesFactory {
         * @param array &$defaultPreferences
         */
        protected function searchPreferences( &$defaultPreferences ) {
-               foreach ( MWNamespace::getValidNamespaces() as $n ) {
+               foreach ( $this->nsInfo->getValidNamespaces() as $n ) {
                        $defaultPreferences['searchNs' . $n] = [
                                'type' => 'api',
                        ];
@@ -1282,6 +1282,23 @@ class DefaultPreferencesFactory implements PreferencesFactory {
 
                # Only show skins that aren't disabled in $wgSkipSkins
                $validSkinNames = Skin::getAllowedSkins();
+               $allInstalledSkins = Skin::getSkinNames();
+
+               // Display the installed skin the user has specifically requested via useskin=….
+               $useSkin = $context->getRequest()->getRawVal( 'useskin' );
+               if ( isset( $allInstalledSkins[$useSkin] )
+                       && $context->msg( "skinname-$useSkin" )->exists()
+               ) {
+                       $validSkinNames[$useSkin] = $useSkin;
+               }
+
+               // Display the skin if the user has set it as a preference already before it was hidden.
+               $currentUserSkin = $user->getOption( 'skin' );
+               if ( isset( $allInstalledSkins[$currentUserSkin] )
+                       && $context->msg( "skinname-$useSkin" )->exists()
+               ) {
+                       $validSkinNames[$currentUserSkin] = $currentUserSkin;
+               }
 
                foreach ( $validSkinNames as $skinkey => &$skinname ) {
                        $msg = $context->msg( "skinname-{$skinkey}" );
@@ -1493,6 +1510,14 @@ class DefaultPreferencesFactory implements PreferencesFactory {
                 */
                $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
 
+               // This allows users to opt-in to hidden skins. While this should be discouraged and is not
+               // discoverable, this allows users to still use hidden skins while preventing new users from
+               // adopting unsupported skins. If no useskin=… parameter was provided, it will not show up
+               // in the resulting URL.
+               $htmlForm->setAction( $context->getTitle()->getLocalURL( [
+                       'useskin' => $context->getRequest()->getRawVal( 'useskin' )
+               ] ) );
+
                $htmlForm->setModifiedUser( $user );
                $htmlForm->setId( 'mw-prefs-form' );
                $htmlForm->setAutocomplete( 'off' );