r70633 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70632‎ | r70633 | r70634 >
Date:16:13, 7 August 2010
Author:catrope
Status:deferred
Tags:
Comment:
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 (modified) (history)
  • /trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/PrefSwitch/SpecialPrefSwitch.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.i18n.php
@@ -18,6 +18,7 @@
1919 'prefswitch-survey-true' => 'Yes',
2020 'prefswitch-survey-false' => 'No',
2121 'prefswitch-survey-submit-off' => 'Turn new features off',
 22+ 'prefswitch-survey-submit-global-off' => 'Turn new features off on all wikis',
2223 'prefswitch-survey-cancel-off' => 'If you would like to continue using the new features, you can return to $1.',
2324 'prefswitch-survey-submit-feedback' => 'Send feedback',
2425 'prefswitch-survey-cancel-feedback' => 'If you do not want to provide feedback, you can return to $1.',
@@ -161,6 +162,7 @@
162163 'prefswitch-main-feedback' => 'Entry asking for feedback in a local page.',
163164 'prefswitch-main-anon' => 'Is used on Special:UsabilityInitiativePrefSwitch at Wikimedia.org.',
164165 '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:"}}',
 166+ 'prefswitch-survey-submit-global-off' => 'This message may still change',
165167 );
166168
167169 /** Afrikaans (Afrikaans)
Index: trunk/extensions/UsabilityInitiative/PrefSwitch/PrefSwitch.php
@@ -38,6 +38,9 @@
3939 ),
4040 );
4141
 42+// Allow global opt-outs. Depends on CentralAuth
 43+$wgPrefSwitchGlobalOptOut = false;
 44+
4245 // Survey questions to ask when users switch prefs
4346 // array(
4447 // survey-id => array(
@@ -62,6 +65,7 @@
6366 $wgPrefSwitchSurveys['feedback'] = array(
6467 'submit-msg' => 'prefswitch-survey-submit-feedback',
6568 'updatable' => true,
 69+ 'global' => false,
6670 'questions' => array(
6771 'like' => array(
6872 'question' => 'prefswitch-survey-question-like',
@@ -76,6 +80,8 @@
7781 $wgPrefSwitchSurveys['off'] = array(
7882 'submit-msg' => 'prefswitch-survey-submit-off',
7983 'updatable' => false,
 84+ 'global' => true,
 85+ 'submit-global-msg' => 'prefswitch-survey-submit-global-off',
8086 'questions' => array_merge(
8187 $wgPrefSwitchSurveys['feedback']['questions'],
8288 array(
Index: trunk/extensions/UsabilityInitiative/PrefSwitch/SpecialPrefSwitch.php
@@ -67,10 +67,30 @@
6868 $user->saveSettings();
6969 }
7070 /**
71 - * Switches a user's prefernces off
 71+ * Switches a user's preferences off
7272 * @param $user User object to set preferences for
 73+ * @param $global bool Whether to apply this change on all wikis in $wgPrefSwitchWikis
7374 */
74 - public static function switchOff( $user ) {
 75+ public static function switchOff( $user, $global = false ) {
 76+ self::switchOffUser( $user );
 77+ if ( $global ) {
 78+ $globalUser = new CentralAuthUser( $user->getName() );
 79+ if ( !$globalUser->exists() ) {
 80+ return;
 81+ }
 82+ $accounts = $globalUser->queryAttached();
 83+ foreach ( $accounts as $account ) {
 84+ $remoteUser = UserRightsProxy::newFromName(
 85+ $account['wiki'],
 86+ $globalUser->getName(),
 87+ true
 88+ );
 89+ self::switchOffUser( $remoteUser );
 90+ }
 91+ }
 92+ }
 93+
 94+ private static function switchOffUser( $user ) {
7595 global $wgPrefSwitchPrefs;
7696 foreach ( $wgPrefSwitchPrefs['off'] as $pref => $value ) {
7797 $user->setOption( $pref, $value );
@@ -85,7 +105,7 @@
86106 wfLoadExtensionMessages( 'PrefSwitch' );
87107 }
88108 public function execute( $par ) {
89 - global $wgRequest, $wgOut, $wgUser, $wgPrefSwitchSurveys, $wgPrefSwitchStyleVersion;
 109+ global $wgRequest, $wgOut, $wgUser, $wgPrefSwitchSurveys, $wgPrefSwitchStyleVersion, $wgPrefSwitchGlobalOptOut;
90110 // Get the origin from the request
91111 $par = $wgRequest->getVal( 'from', $par );
92112 $this->originTitle = Title::newFromText( $par );
@@ -126,7 +146,7 @@
127147 case 'off':
128148 // Switch off
129149 if ( self::checkToken() && self::isSwitchedOn( $wgUser ) && $wgRequest->wasPosted() ) {
130 - self::switchOff( $wgUser );
 150+ self::switchOff( $wgUser, $wgRequest->getCheck( 'global' ) && $wgPrefSwitchGlobalOptOut );
131151 PrefSwitchSurvey::save( 'off', $wgPrefSwitchSurveys['feedback'] );
132152 $wgOut->addWikiMsg( 'prefswitch-success-off' );
133153 } else if ( !self::isSwitchedOn( $wgUser ) ) {
@@ -199,7 +219,7 @@
200220 /* Private Functions */
201221
202222 private function render( $mode = null ) {
203 - global $wgUser, $wgOut, $wgPrefSwitchSurveys, $wgAllowUserCss, $wgAllowUserJs;
 223+ global $wgUser, $wgOut, $wgPrefSwitchSurveys, $wgPrefSwitchGlobalOptOut, $wgAllowUserCss, $wgAllowUserJs;
204224 // Make sure links will retain the origin
205225 $query = array( 'from' => $this->origin, 'fromquery' => $this->originQuery );
206226 if ( isset( $wgPrefSwitchSurveys[$mode] ) ) {
@@ -229,6 +249,15 @@
230250 wfMsg( $wgPrefSwitchSurveys[$mode]['submit-msg'] ),
231251 array( 'id' => "prefswitch-survey-submit-{$mode}", 'class' => 'prefswitch-survey-submit' )
232252 );
 253+ if ( $wgPrefSwitchSurveys[$mode]['global'] && $wgPrefSwitchGlobalOptOut ) {
 254+ $html .= Xml::submitButton(
 255+ wfMsg( $wgPrefSwitchSurveys[$mode]['submit-global-msg'] ),
 256+ array( 'id' => "prefswitch-survey-submit-global-{$mode}",
 257+ 'class' => 'prefswitch-survey-submit',
 258+ 'name' => 'global',
 259+ )
 260+ );
 261+ }
233262 $html .= Xml::closeElement( 'dt' );
234263 $html .= Xml::closeElement( 'form' );
235264 $wgOut->addHtml( $html );

Follow-up revisions

RevisionCommit summaryAuthorDate
r721271.16wmf4: Merge r70633, r72043, r72055, r72059 from trunkcatrope17:52, 1 September 2010

Status & tagging log