http://www.mediawiki.org/wiki/Special:Code/MediaWiki/70633
Revision: 70633 Author: catrope Date: 2010-08-07 16:13:18 +0000 (Sat, 07 Aug 2010) Log Message: ----------- PrefSwitch: Make global opt-outs possible, using CentralAuth to determine which wikis a user has an account on. Needs to be enabled explicitly (to prevent errors when CentralAuth isn't installed). Best used in combination with DontSwitchMeOver and $wgPrefSwitchPrefs['off']['dontswitchmeover'] = 1; Modified Paths: -------------- trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.i18n.php trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.php trunk/extensions/UsabilityInitiative/PrefSwitch/SpecialPrefSwitch.php Modified: trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.i18n.php =================================================================== --- trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.i18n.php 2010-08-07 16:08:22 UTC (rev 70632) +++ trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.i18n.php 2010-08-07 16:13:18 UTC (rev 70633) @@ -18,6 +18,7 @@ 'prefswitch-survey-true' => 'Yes', 'prefswitch-survey-false' => 'No', 'prefswitch-survey-submit-off' => 'Turn new features off', + 'prefswitch-survey-submit-global-off' => 'Turn new features off on all wikis', 'prefswitch-survey-cancel-off' => 'If you would like to continue using the new features, you can return to $1.', 'prefswitch-survey-submit-feedback' => 'Send feedback', 'prefswitch-survey-cancel-feedback' => 'If you do not want to provide feedback, you can return to $1.', @@ -161,6 +162,7 @@ 'prefswitch-main-feedback' => 'Entry asking for feedback in a local page.', 'prefswitch-main-anon' => 'Is used on Special:UsabilityInitiativePrefSwitch at Wikimedia.org.', 'prefswitch-feedbackpage' => '{{doc-important|The name of the user experience feedback page on this wiki. Should only be translated for ja, es, de, fr, it, ru, pl, pt, nl for now. Do not translate "Project:"}}', + 'prefswitch-survey-submit-global-off' => 'This message may still change', ); /** Afrikaans (Afrikaans) Modified: trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.php =================================================================== --- trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.php 2010-08-07 16:08:22 UTC (rev 70632) +++ trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.php 2010-08-07 16:13:18 UTC (rev 70633) @@ -38,6 +38,9 @@ ), ); +// Allow global opt-outs. Depends on CentralAuth +$wgPrefSwitchGlobalOptOut = false; + // Survey questions to ask when users switch prefs // array( // survey-id => array( @@ -62,6 +65,7 @@ $wgPrefSwitchSurveys['feedback'] = array( 'submit-msg' => 'prefswitch-survey-submit-feedback', 'updatable' => true, + 'global' => false, 'questions' => array( 'like' => array( 'question' => 'prefswitch-survey-question-like', @@ -76,6 +80,8 @@ $wgPrefSwitchSurveys['off'] = array( 'submit-msg' => 'prefswitch-survey-submit-off', 'updatable' => false, + 'global' => true, + 'submit-global-msg' => 'prefswitch-survey-submit-global-off', 'questions' => array_merge( $wgPrefSwitchSurveys['feedback']['questions'], array( Modified: trunk/extensions/UsabilityInitiative/PrefSwitch/SpecialPrefSwitch.php =================================================================== --- trunk/extensions/UsabilityInitiative/PrefSwitch/SpecialPrefSwitch.php 2010-08-07 16:08:22 UTC (rev 70632) +++ trunk/extensions/UsabilityInitiative/PrefSwitch/SpecialPrefSwitch.php 2010-08-07 16:13:18 UTC (rev 70633) @@ -67,10 +67,30 @@ $user->saveSettings(); } /** - * Switches a user's prefernces off + * Switches a user's preferences off * @param $user User object to set preferences for + * @param $global bool Whether to apply this change on all wikis in $wgPrefSwitchWikis */ - public static function switchOff( $user ) { + public static function switchOff( $user, $global = false ) { + self::switchOffUser( $user ); + if ( $global ) { + $globalUser = new CentralAuthUser( $user->getName() ); + if ( !$globalUser->exists() ) { + return; + } + $accounts = $globalUser->queryAttached(); + foreach ( $accounts as $account ) { + $remoteUser = UserRightsProxy::newFromName( + $account['wiki'], + $globalUser->getName(), + true + ); + self::switchOffUser( $remoteUser ); + } + } + } + + private static function switchOffUser( $user ) { global $wgPrefSwitchPrefs; foreach ( $wgPrefSwitchPrefs['off'] as $pref => $value ) { $user->setOption( $pref, $value ); @@ -85,7 +105,7 @@ wfLoadExtensionMessages( 'PrefSwitch' ); } public function execute( $par ) { - global $wgRequest, $wgOut, $wgUser, $wgPrefSwitchSurveys, $wgPrefSwitchStyleVersion; + global $wgRequest, $wgOut, $wgUser, $wgPrefSwitchSurveys, $wgPrefSwitchStyleVersion, $wgPrefSwitchGlobalOptOut; // Get the origin from the request $par = $wgRequest->getVal( 'from', $par ); $this->originTitle = Title::newFromText( $par ); @@ -126,7 +146,7 @@ case 'off': // Switch off if ( self::checkToken() && self::isSwitchedOn( $wgUser ) && $wgRequest->wasPosted() ) { - self::switchOff( $wgUser ); + self::switchOff( $wgUser, $wgRequest->getCheck( 'global' ) && $wgPrefSwitchGlobalOptOut ); PrefSwitchSurvey::save( 'off', $wgPrefSwitchSurveys['feedback'] ); $wgOut->addWikiMsg( 'prefswitch-success-off' ); } else if ( !self::isSwitchedOn( $wgUser ) ) { @@ -199,7 +219,7 @@ /* Private Functions */ private function render( $mode = null ) { - global $wgUser, $wgOut, $wgPrefSwitchSurveys, $wgAllowUserCss, $wgAllowUserJs; + global $wgUser, $wgOut, $wgPrefSwitchSurveys, $wgPrefSwitchGlobalOptOut, $wgAllowUserCss, $wgAllowUserJs; // Make sure links will retain the origin $query = array( 'from' => $this->origin, 'fromquery' => $this->originQuery ); if ( isset( $wgPrefSwitchSurveys[$mode] ) ) { @@ -229,6 +249,15 @@ wfMsg( $wgPrefSwitchSurveys[$mode]['submit-msg'] ), array( 'id' => "prefswitch-survey-submit-{$mode}", 'class' => 'prefswitch-survey-submit' ) ); + if ( $wgPrefSwitchSurveys[$mode]['global'] && $wgPrefSwitchGlobalOptOut ) { + $html .= Xml::submitButton( + wfMsg( $wgPrefSwitchSurveys[$mode]['submit-global-msg'] ), + array( 'id' => "prefswitch-survey-submit-global-{$mode}", + 'class' => 'prefswitch-survey-submit', + 'name' => 'global', + ) + ); + } $html .= Xml::closeElement( 'dt' ); $html .= Xml::closeElement( 'form' ); $wgOut->addHtml( $html ); _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs