Index: trunk/phase3/includes/Preferences.php |
— | — | @@ -14,7 +14,72 @@ |
15 | 15 | global $wgLang, $wgRCMaxAge; |
16 | 16 | |
17 | 17 | $defaultPreferences = array(); |
| 18 | + |
| 19 | + self::profilePreferences( $user, $defaultPreferences ); |
| 20 | + self::emailPreferences( $user, $defaultPreferences ); |
| 21 | + self::skinPreferences( $user, $defaultPreferences ); |
| 22 | + self::mathPreferences( $user, $defaultPreferences ); |
| 23 | + self::filesPreferences( $user, $defaultPreferences ); |
| 24 | + self::datetimePreferences( $user, $defaultPreferences ); |
| 25 | + self::renderingPreferences( $user, $defaultPreferences ); |
| 26 | + self::editingPreferences( $user, $defaultPreferences ); |
| 27 | + self::rcPreferences( $user, $defaultPreferences ); |
| 28 | + self::watchlistPreferences( $user, $defaultPreferences ); |
| 29 | + self::searchPreferences( $user, $defaultPreferences ); |
| 30 | + self::miscPreferences( $user, $defaultPreferences ); |
| 31 | + |
| 32 | + wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) ); |
| 33 | + |
| 34 | + ## Prod in defaults from the user |
| 35 | + global $wgDefaultUserOptions; |
| 36 | + foreach( $defaultPreferences as $name => &$info ) { |
| 37 | + $prefFromUser = self::getOptionFromUser( $name, $info, $user ); |
| 38 | + $field = HTMLForm::loadInputFromParameters( $info ); // For validation |
| 39 | + $globalDefault = isset($wgDefaultUserOptions[$name]) |
| 40 | + ? $wgDefaultUserOptions[$name] |
| 41 | + : null; |
| 42 | + |
| 43 | + // If it validates, set it as the default |
| 44 | + if ( isset($info['default']) ) { |
| 45 | + // Already set, no problem |
| 46 | + continue; |
| 47 | + } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing |
| 48 | + $field->validate( $prefFromUser, $user->mOptions ) ) { |
| 49 | + $info['default'] = $prefFromUser; |
| 50 | + } elseif( $field->validate( $globalDefault, $user->mOptions ) ) { |
| 51 | + $info['default'] = $globalDefault; |
| 52 | + } |
| 53 | + } |
18 | 54 | |
| 55 | + self::$defaultPreferences = $defaultPreferences; |
| 56 | + |
| 57 | + return $defaultPreferences; |
| 58 | + } |
| 59 | + |
| 60 | + // Pull option from a user account. Handles stuff like array-type preferences. |
| 61 | + static function getOptionFromUser( $name, $info, $user ) { |
| 62 | + $val = $user->getOption( $name ); |
| 63 | + |
| 64 | + // Handling for array-type preferences |
| 65 | + if ( ( isset($info['type']) && $info['type'] == 'multiselect' ) || |
| 66 | + ( isset($info['class']) && $info['class'] == 'HTMLMultiSelectField' ) ) { |
| 67 | + |
| 68 | + $options = HTMLFormField::flattenOptions($info['options']); |
| 69 | + $prefix = isset($info['prefix']) ? $info['prefix'] : $name; |
| 70 | + $val = array(); |
| 71 | + |
| 72 | + foreach( $options as $label => $value ) { |
| 73 | + if ($user->getOption( "$prefix$value" ) ) { |
| 74 | + $val[] = $value; |
| 75 | + } |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + return $val; |
| 80 | + } |
| 81 | + |
| 82 | + static function profilePreferences( $user, &$defaultPreferences ) { |
| 83 | + global $wgLang; |
19 | 84 | ## User info ##################################### |
20 | 85 | // Information panel |
21 | 86 | $defaultPreferences['username'] = |
— | — | @@ -216,8 +281,9 @@ |
217 | 282 | 'label-message' => 'tog-rememberpassword', |
218 | 283 | 'section' => 'personal', |
219 | 284 | ); |
220 | | - |
221 | | - |
| 285 | + } |
| 286 | + |
| 287 | + static function emailPreferences( $user, &$defaultPreferences ) { |
222 | 288 | ## Email ####################################### |
223 | 289 | ## Email stuff |
224 | 290 | global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication; |
— | — | @@ -235,6 +301,7 @@ |
236 | 302 | $disableEmailPrefs = false; |
237 | 303 | } else { |
238 | 304 | $disableEmailPrefs = true; |
| 305 | + global $wgUser; // wgUser is okay here, it's for display |
239 | 306 | $skin = $wgUser->getSkin(); |
240 | 307 | $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' . |
241 | 308 | $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ), |
— | — | @@ -297,7 +364,9 @@ |
298 | 365 | 'label-message' => 'tog-enotifrevealaddr' |
299 | 366 | ); |
300 | 367 | } |
301 | | - |
| 368 | + } |
| 369 | + |
| 370 | + static function skinPreferences( $user, &$defaultPreferences ) { |
302 | 371 | ## Skin ##################################### |
303 | 372 | global $wgAllowUserSkin; |
304 | 373 | |
— | — | @@ -323,7 +392,9 @@ |
324 | 393 | 'label-message' => 'qbsettings', |
325 | 394 | ); |
326 | 395 | } |
327 | | - |
| 396 | + } |
| 397 | + |
| 398 | + static function mathPreferences( $user, &$defaultPreferences ) { |
328 | 399 | ## Math ##################################### |
329 | 400 | global $wgUseTeX; |
330 | 401 | if ($wgUseTeX) { |
— | — | @@ -336,7 +407,9 @@ |
337 | 408 | 'section' => 'math', |
338 | 409 | ); |
339 | 410 | } |
340 | | - |
| 411 | + } |
| 412 | + |
| 413 | + static function filesPreferences( $user, &$defaultPreferences ) { |
341 | 414 | ## Files ##################################### |
342 | 415 | $defaultPreferences['imagesize'] = |
343 | 416 | array( |
— | — | @@ -352,6 +425,10 @@ |
353 | 426 | 'label-message' => 'thumbsize', |
354 | 427 | 'section' => 'files', |
355 | 428 | ); |
| 429 | + } |
| 430 | + |
| 431 | + static function datetimePreferences( $user, &$defaultPreferences ) { |
| 432 | + global $wgLang; |
356 | 433 | |
357 | 434 | ## Date and time ##################################### |
358 | 435 | $dateOptions = self::getDateOptions(); |
— | — | @@ -407,7 +484,9 @@ |
408 | 485 | 'default' => $tzSetting, |
409 | 486 | 'section' => 'datetime', |
410 | 487 | ); |
411 | | - |
| 488 | + } |
| 489 | + |
| 490 | + static function renderingPreferences( $user, &$defaultPreferences ) { |
412 | 491 | ## Page Rendering ############################## |
413 | 492 | $defaultPreferences['underline'] = |
414 | 493 | array( |
— | — | @@ -476,7 +555,9 @@ |
477 | 556 | 'section' => 'rendering', |
478 | 557 | 'label-message' => 'tog-numberheadings', |
479 | 558 | ); |
480 | | - |
| 559 | + } |
| 560 | + |
| 561 | + static function editingPreferences( $user, &$defaultPreferences ) { |
481 | 562 | ## Editing ##################################### |
482 | 563 | $defaultPreferences['cols'] = |
483 | 564 | array( |
— | — | @@ -566,7 +647,10 @@ |
567 | 648 | 'section' => 'editing', |
568 | 649 | 'label-message' => 'tog-uselivepreview', |
569 | 650 | ); |
570 | | - |
| 651 | + } |
| 652 | + |
| 653 | + static function rcPreferences( $user, &$defaultPreferences ) { |
| 654 | + global $wgRCMaxAge, $wgUseRCPatrol; |
571 | 655 | ## RecentChanges ##################################### |
572 | 656 | $defaultPreferences['rcdays'] = |
573 | 657 | array( |
— | — | @@ -620,7 +704,10 @@ |
621 | 705 | 'label-message' => 'tog-shownumberswatching', |
622 | 706 | ); |
623 | 707 | } |
624 | | - |
| 708 | + } |
| 709 | + |
| 710 | + static function watchlistPreferences( $user, &$defaultPreferences ) { |
| 711 | + global $wgUseRCPatrol; |
625 | 712 | ## Watchlist ##################################### |
626 | 713 | $defaultPreferences['wllimit'] = |
627 | 714 | array( |
— | — | @@ -702,6 +789,10 @@ |
703 | 790 | ); |
704 | 791 | } |
705 | 792 | } |
| 793 | + } |
| 794 | + |
| 795 | + static function searchPreferences( $user, &$defaultPreferences ) { |
| 796 | + global $wgContLang; |
706 | 797 | |
707 | 798 | ## Search ##################################### |
708 | 799 | $defaultPreferences['searchlimit'] = |
— | — | @@ -757,7 +848,9 @@ |
758 | 849 | 'section' => 'searchoptions', |
759 | 850 | ); |
760 | 851 | } |
761 | | - |
| 852 | + } |
| 853 | + |
| 854 | + static function miscPreferences( $user, &$defaultPreferences ) { |
762 | 855 | ## Misc ##################################### |
763 | 856 | $defaultPreferences['diffonly'] = |
764 | 857 | array( |
— | — | @@ -771,57 +864,8 @@ |
772 | 865 | 'section' => 'misc', |
773 | 866 | 'label-message' => 'tog-norollbackdiff', |
774 | 867 | ); |
775 | | - |
776 | | - wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) ); |
777 | | - |
778 | | - ## Prod in defaults from the user |
779 | | - global $wgDefaultUserOptions; |
780 | | - foreach( $defaultPreferences as $name => &$info ) { |
781 | | - $prefFromUser = self::getOptionFromUser( $name, $info, $user ); |
782 | | - $field = HTMLForm::loadInputFromParameters( $info ); // For validation |
783 | | - $globalDefault = isset($wgDefaultUserOptions[$name]) |
784 | | - ? $wgDefaultUserOptions[$name] |
785 | | - : null; |
786 | | - |
787 | | - // If it validates, set it as the default |
788 | | - if ( isset($info['default']) ) { |
789 | | - // Already set, no problem |
790 | | - continue; |
791 | | - } elseif ( !is_null( $prefFromUser ) && // Make sure we're not just pulling nothing |
792 | | - $field->validate( $prefFromUser, $user->mOptions ) ) { |
793 | | - $info['default'] = $prefFromUser; |
794 | | - } elseif( $field->validate( $globalDefault, $user->mOptions ) ) { |
795 | | - $info['default'] = $globalDefault; |
796 | | - } |
797 | | - } |
798 | | - |
799 | | - self::$defaultPreferences = $defaultPreferences; |
800 | | - |
801 | | - return $defaultPreferences; |
802 | 868 | } |
803 | 869 | |
804 | | - // Pull option from a user account. Handles stuff like array-type preferences. |
805 | | - static function getOptionFromUser( $name, $info, $user ) { |
806 | | - $val = $user->getOption( $name ); |
807 | | - |
808 | | - // Handling for array-type preferences |
809 | | - if ( ( isset($info['type']) && $info['type'] == 'multiselect' ) || |
810 | | - ( isset($info['class']) && $info['class'] == 'HTMLMultiSelectField' ) ) { |
811 | | - |
812 | | - $options = HTMLFormField::flattenOptions($info['options']); |
813 | | - $prefix = isset($info['prefix']) ? $info['prefix'] : $name; |
814 | | - $val = array(); |
815 | | - |
816 | | - foreach( $options as $label => $value ) { |
817 | | - if ($user->getOption( "$prefix$value" ) ) { |
818 | | - $val[] = $value; |
819 | | - } |
820 | | - } |
821 | | - } |
822 | | - |
823 | | - return $val; |
824 | | - } |
825 | | - |
826 | 870 | static function generateSkinOptions( $user ) { |
827 | 871 | global $wgDefaultSkin; |
828 | 872 | $ret = array(); |