diff --git a/MultimediaViewer.php b/MultimediaViewer.php index 7c0f1262d..52fba3b62 100644 --- a/MultimediaViewer.php +++ b/MultimediaViewer.php @@ -63,12 +63,20 @@ if ( !isset( $wgMediaViewerUseThumbnailGuessing ) ) { $wgMediaViewerUseThumbnailGuessing = false; } -if ( !isset( $wgEnableMediaViewerForLoggedInUsersOnly ) ) { +if ( !isset( $wgMediaViewerEnableByDefault ) ) { /** - * @var bool: If set, and $wgMediaViewerIsInBeta is unset, Media Viewer will be turned on for - * all logged-in users. False if unset. + * If trueish, and $wgMediaViewerIsInBeta is unset, Media Viewer will be turned on by default. + * @var bool */ - $wgEnableMediaViewerForLoggedInUsersOnly = false; + $wgMediaViewerEnableByDefault = true; +} + +if ( !isset( $wgMediaViewerEnableByDefaultForAnonymous ) ) { + /** + * If set, overrides $wgMediaViewerEnableByDefault for anonymous users. + * @var bool + */ + $wgMediaViewerEnableByDefaultForAnonymous = $wgMediaViewerEnableByDefault; } $wgMessagesDirs['MultimediaViewer'] = __DIR__ . '/i18n'; @@ -948,7 +956,12 @@ foreach ( array( $wgAutoloadClasses['MultimediaViewerHooks'] = __DIR__ . '/MultimediaViewerHooks.php'; -$wgDefaultUserOptions['multimediaviewer-enable'] = true; +$wgExtensionFunctions[] = function () { + global $wgMediaViewerEnableByDefault, $wgDefaultUserOptions; + if ( $wgMediaViewerEnableByDefault ) { + $wgDefaultUserOptions['multimediaviewer-enable'] = true; + } +}; $wgHooks['GetPreferences'][] = 'MultimediaViewerHooks::getPreferences'; $wgHooks['GetBetaFeaturePreferences'][] = 'MultimediaViewerHooks::getBetaPreferences'; diff --git a/MultimediaViewerHooks.php b/MultimediaViewerHooks.php index 27d7b49df..6ac204aaa 100644 --- a/MultimediaViewerHooks.php +++ b/MultimediaViewerHooks.php @@ -37,22 +37,17 @@ class MultimediaViewerHooks { * @return bool */ protected static function shouldHandleClicks( $user ) { - global $wgMediaViewerIsInBeta, $wgEnableMediaViewerForLoggedInUsersOnly; + global $wgMediaViewerIsInBeta, $wgMediaViewerEnableByDefaultForAnonymous; if ( $wgMediaViewerIsInBeta && class_exists( 'BetaFeatures' ) ) { return BetaFeatures::isFeatureEnabled( $user, 'multimedia-viewer' ); } - if ( $user->getOption( 'multimediaviewer-enable' ) ) { - if ( $wgEnableMediaViewerForLoggedInUsersOnly ) { - return $user->isLoggedIn(); - } else { - // Default to enabling for everyone. - return true; - } + if ( !$user->isLoggedIn() && isset( $wgMediaViewerEnableByDefaultForAnonymous ) ) { + return (bool)$wgMediaViewerEnableByDefaultForAnonymous; + } else { + return (bool)$user->getOption( 'multimediaviewer-enable' ); } - - return false; } /**