X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FPreferences.php;h=fde135b8918ee173fd155adfe0b250eb918103ea;hb=6b7317c91fb949e3f0af0039e0f99f15d9c60c91;hp=bbf0e4bfb7ba4be403f1b6656c1b97544aaf67a0;hpb=a307c1353a85524a2d7c3e7890be69af37a48f10;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Preferences.php b/includes/Preferences.php index bbf0e4bfb7..fde135b891 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -29,27 +29,35 @@ class Preferences { static $defaultPreferences = null; static $saveFilters = array( 'timecorrection' => array( 'Preferences', 'filterTimezoneInput' ), + 'rows' => array( 'Preferences', 'filterIntval' ), + 'rclimit' => array( 'Preferences', 'filterIntval' ), + 'wllimit' => array( 'Preferences', 'filterIntval' ), + 'searchlimit' => array( 'Preferences', 'filterIntval' ), ); - static function getPreferences( $user ) { - if ( self::$defaultPreferences ) + /** + * @throws MWException + * @param $user User + * @param $context IContextSource + * @return array|null + */ + static function getPreferences( $user, IContextSource $context ) { + if ( self::$defaultPreferences ) { return self::$defaultPreferences; - - global $wgRCMaxAge; + } $defaultPreferences = array(); - self::profilePreferences( $user, $defaultPreferences ); - self::skinPreferences( $user, $defaultPreferences ); - self::filesPreferences( $user, $defaultPreferences ); - self::mathPreferences( $user, $defaultPreferences ); - self::datetimePreferences( $user, $defaultPreferences ); - self::renderingPreferences( $user, $defaultPreferences ); - self::editingPreferences( $user, $defaultPreferences ); - self::rcPreferences( $user, $defaultPreferences ); - self::watchlistPreferences( $user, $defaultPreferences ); - self::searchPreferences( $user, $defaultPreferences ); - self::miscPreferences( $user, $defaultPreferences ); + self::profilePreferences( $user, $context, $defaultPreferences ); + self::skinPreferences( $user, $context, $defaultPreferences ); + self::filesPreferences( $user, $context, $defaultPreferences ); + self::datetimePreferences( $user, $context, $defaultPreferences ); + self::renderingPreferences( $user, $context, $defaultPreferences ); + self::editingPreferences( $user, $context, $defaultPreferences ); + self::rcPreferences( $user, $context, $defaultPreferences ); + self::watchlistPreferences( $user, $context, $defaultPreferences ); + self::searchPreferences( $user, $context, $defaultPreferences ); + self::miscPreferences( $user, $context, $defaultPreferences ); wfRunHooks( 'GetPreferences', array( $user, &$defaultPreferences ) ); @@ -62,10 +70,9 @@ class Preferences { } ## Prod in defaults from the user - global $wgDefaultUserOptions; foreach ( $defaultPreferences as $name => &$info ) { $prefFromUser = self::getOptionFromUser( $name, $info, $user ); - $field = HTMLForm::loadInputFromParameters( $info ); // For validation + $field = HTMLForm::loadInputFromParameters( $name, $info ); // For validation $defaultOptions = User::getDefaultOptions(); $globalDefault = isset( $defaultOptions[$name] ) ? $defaultOptions[$name] @@ -90,7 +97,14 @@ class Preferences { return $defaultPreferences; } - // Pull option from a user account. Handles stuff like array-type preferences. + /** + * Pull option from a user account. Handles stuff like array-type preferences. + * + * @param $name + * @param $info + * @param $user User + * @return array|String + */ static function getOptionFromUser( $name, $info, $user ) { $val = $user->getOption( $name ); @@ -101,7 +115,7 @@ class Preferences { $prefix = isset( $info['prefix'] ) ? $info['prefix'] : $name; $val = array(); - foreach ( $options as $label => $value ) { + foreach ( $options as $value ) { if ( $user->getOption( "$prefix$value" ) ) { $val[] = $value; } @@ -111,8 +125,18 @@ class Preferences { return $val; } - static function profilePreferences( $user, &$defaultPreferences ) { - global $wgLang, $wgUser; + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences + * @return void + */ + static function profilePreferences( $user, IContextSource $context, &$defaultPreferences ) { + global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode, + $wgDisableTitleConversion, $wgDisableLangConversion, $wgMaxSigChars, + $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication, + $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress; + ## User info ##################################### // Information panel $defaultPreferences['username'] = array( @@ -140,23 +164,22 @@ class Preferences { $groupName = User::getGroupName( $ueg ); $userGroups[] = User::makeGroupLinkHTML( $ueg, $groupName ); - $memberName = User::getGroupMember( $ueg ); + $memberName = User::getGroupMember( $ueg, $user->getName() ); $userMembers[] = User::makeGroupLinkHTML( $ueg, $memberName ); } asort( $userGroups ); asort( $userMembers ); + $lang = $context->getLanguage(); + $defaultPreferences['usergroups'] = array( 'type' => 'info', - 'label' => wfMsgExt( - 'prefs-memberingroups', 'parseinline', - $wgLang->formatNum( count( $userGroups ) ) - ), - 'default' => wfMsgExt( - 'prefs-memberingroups-type', array(), - $wgLang->commaList( $userGroups ), - $wgLang->commaList( $userMembers ) - ), + 'label' => $context->msg( 'prefs-memberingroups' )->numParams( + count( $userGroups ) )->parse(), + 'default' => $context->msg( 'prefs-memberingroups-type', + $lang->commaList( $userGroups ), + $lang->commaList( $userMembers ) + )->plain(), 'raw' => true, 'section' => 'personal/info', ); @@ -164,26 +187,27 @@ class Preferences { $defaultPreferences['editcount'] = array( 'type' => 'info', 'label-message' => 'prefs-edits', - 'default' => $wgLang->formatNum( $user->getEditCount() ), + 'default' => $lang->formatNum( $user->getEditCount() ), 'section' => 'personal/info', ); if ( $user->getRegistration() ) { + $displayUser = $context->getUser(); + $userRegistration = $user->getRegistration(); $defaultPreferences['registrationdate'] = array( 'type' => 'info', 'label-message' => 'prefs-registration', - 'default' => wfMsgExt( - 'prefs-registration-date-time', 'parsemag', - $wgLang->timeanddate( $user->getRegistration(), true ), - $wgLang->date( $user->getRegistration(), true ), - $wgLang->time( $user->getRegistration(), true ) - ), + 'default' => $context->msg( + 'prefs-registration-date-time', + $lang->userTimeAndDate( $userRegistration, $displayUser ), + $lang->userDate( $userRegistration, $displayUser ), + $lang->userTime( $userRegistration, $displayUser ) + )->parse(), 'section' => 'personal/info', ); } // Actually changeable stuff - global $wgAuth; $defaultPreferences['realname'] = array( 'type' => $wgAuth->allowPropChange( 'realname' ) ? 'text' : 'info', 'default' => $user->getRealName(), @@ -196,17 +220,17 @@ class Preferences { 'type' => 'select', 'section' => 'personal/info', 'options' => array( - wfMsg( 'gender-male' ) => 'male', - wfMsg( 'gender-female' ) => 'female', - wfMsg( 'gender-unknown' ) => 'unknown', + $context->msg( 'gender-male' )->text() => 'male', + $context->msg( 'gender-female' )->text() => 'female', + $context->msg( 'gender-unknown' )->text() => 'unknown', ), 'label-message' => 'yourgender', 'help-message' => 'prefs-help-gender', ); if ( $wgAuth->allowPasswordChange() ) { - $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'Resetpass' ), - wfMsgHtml( 'prefs-resetpass' ), array(), + $link = Linker::link( SpecialPage::getTitleFor( 'ChangePassword' ), + $context->msg( 'prefs-resetpass' )->escaped(), array(), array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) ); $defaultPreferences['password'] = array( @@ -217,24 +241,19 @@ class Preferences { 'section' => 'personal/info', ); } - global $wgCookieExpiration; if ( $wgCookieExpiration > 0 ) { $defaultPreferences['rememberpassword'] = array( 'type' => 'toggle', - 'label' => wfMsgExt( - 'tog-rememberpassword', - array( 'parsemag' ), - $wgLang->formatNum( ceil( $wgCookieExpiration / ( 3600 * 24 ) ) ) - ), + 'label' => $context->msg( 'tog-rememberpassword' )->numParams( + ceil( $wgCookieExpiration / ( 3600 * 24 ) ) )->text(), 'section' => 'personal/info', ); } // Language - global $wgContLanguageCode; - $languages = array_reverse( Language::getLanguageNames( false ) ); - if ( !array_key_exists( $wgContLanguageCode, $languages ) ) { - $languages[$wgContLanguageCode] = $wgContLanguageCode; + $languages = Language::getLanguageNames( false ); + if ( !array_key_exists( $wgLanguageCode, $languages ) ) { + $languages[$wgLanguageCode] = $wgLanguageCode; } ksort( $languages ); @@ -250,20 +269,14 @@ class Preferences { 'label-message' => 'yourlanguage', ); - global $wgContLang, $wgDisableLangConversion; - global $wgDisableTitleConversion; /* see if there are multiple language variants to choose from*/ $variantArray = array(); if ( !$wgDisableLangConversion ) { $variants = $wgContLang->getVariants(); - $languages = Language::getLanguageNames( true ); foreach ( $variants as $v ) { $v = str_replace( '_', '-', strtolower( $v ) ); - if ( array_key_exists( $v, $languages ) ) { - // If it doesn't have a name, we'll pretend it doesn't exist - $variantArray[$v] = $languages[$v]; - } + $variantArray[$v] = $wgContLang->getVariantname( $v, false ); } $options = array(); @@ -278,24 +291,23 @@ class Preferences { 'type' => 'select', 'options' => $options, 'section' => 'personal/i18n', + 'help-message' => 'prefs-help-variant', ); } } if ( count( $variantArray ) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion ) { $defaultPreferences['noconvertlink'] = - array( + array( 'type' => 'toggle', 'section' => 'personal/i18n', 'label-message' => 'tog-noconvertlink', ); } - global $wgMaxSigChars, $wgOut, $wgParser; - // show a preview of the old signature first - $oldsigWikiText = $wgParser->preSaveTransform( "~~~", new Title , $user, new ParserOptions ); - $oldsigHTML = $wgOut->parseInline( $oldsigWikiText ); + $oldsigWikiText = $wgParser->preSaveTransform( "~~~", $context->getTitle(), $user, ParserOptions::newFromContext( $context ) ); + $oldsigHTML = $context->getOutput()->parseInline( $oldsigWikiText, true, true ); $defaultPreferences['oldsig'] = array( 'type' => 'info', 'raw' => true, @@ -320,23 +332,35 @@ class Preferences { ## Email stuff - global $wgEnableEmail; if ( $wgEnableEmail ) { - global $wgEmailConfirmToEdit; + $helpMessages[] = $wgEmailConfirmToEdit + ? 'prefs-help-email-required' + : 'prefs-help-email' ; + + if( $wgEnableUserEmail ) { + // additional messages when users can send email to each other + $helpMessages[] = 'prefs-help-email-others'; + } + + $link = Linker::link( + SpecialPage::getTitleFor( 'ChangeEmail' ), + $context->msg( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' )->escaped(), + array(), + array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) ); + + $emailAddress = $user->getEmail() ? htmlspecialchars( $user->getEmail() ) : ''; + if ( $wgAuth->allowPropChange( 'emailaddress' ) ) { + $emailAddress .= $emailAddress == '' ? $link : " ($link)"; + } $defaultPreferences['emailaddress'] = array( - 'type' => $wgAuth->allowPropChange( 'emailaddress' ) ? 'email' : 'info', - 'default' => $user->getEmail(), - 'section' => 'personal/email', + 'type' => 'info', + 'raw' => true, + 'default' => $emailAddress, 'label-message' => 'youremail', - 'help-message' => $wgEmailConfirmToEdit - ? 'prefs-help-email-required' - : 'prefs-help-email', - 'validation-callback' => array( 'Preferences', 'validateEmail' ), + 'section' => 'personal/email', ); - global $wgEnableUserEmail, $wgEmailAuthentication; - $disableEmailPrefs = false; if ( $wgEmailAuthentication ) { @@ -345,29 +369,25 @@ class Preferences { // date and time are separate parameters to facilitate localisation. // $time is kept for backward compat reasons. // 'emailauthenticated' is also used in SpecialConfirmemail.php - $time = $wgLang->timeAndDate( $user->getEmailAuthenticationTimestamp(), true ); - $d = $wgLang->date( $user->getEmailAuthenticationTimestamp(), true ); - $t = $wgLang->time( $user->getEmailAuthenticationTimestamp(), true ); - $emailauthenticated = wfMsgExt( - 'emailauthenticated', 'parseinline', - array( $time, $d, $t ) - ) . '
'; + $displayUser = $context->getUser(); + $emailTimestamp = $user->getEmailAuthenticationTimestamp(); + $time = $lang->userTimeAndDate( $emailTimestamp, $displayUser ); + $d = $lang->userDate( $emailTimestamp, $displayUser ); + $t = $lang->userTime( $emailTimestamp, $displayUser ); + $emailauthenticated = $context->msg( 'emailauthenticated', + $time, $d, $t )->parse() . '
'; $disableEmailPrefs = false; } else { $disableEmailPrefs = true; - $skin = $wgUser->getSkin(); - $emailauthenticated = wfMsgExt( 'emailnotauthenticated', 'parseinline' ) . '
' . - $skin->link( + $emailauthenticated = $context->msg( 'emailnotauthenticated' )->parse() . '
' . + Linker::linkKnown( SpecialPage::getTitleFor( 'Confirmemail' ), - wfMsg( 'emailconfirmlink' ), - array(), - array(), - array( 'known', 'noclasses' ) + $context->msg( 'emailconfirmlink' )->escaped() ) . '
'; } } else { $disableEmailPrefs = true; - $emailauthenticated = wfMsgHtml( 'noemailprefs' ); + $emailauthenticated = $context->msg( 'noemailprefs' )->escaped(); } $defaultPreferences['emailauthentication'] = array( @@ -396,7 +416,6 @@ class Preferences { ); } - global $wgEnotifWatchlist; if ( $wgEnotifWatchlist ) { $defaultPreferences['enotifwatchlistpages'] = array( 'type' => 'toggle', @@ -405,7 +424,6 @@ class Preferences { 'disabled' => $disableEmailPrefs, ); } - global $wgEnotifUserTalk; if ( $wgEnotifUserTalk ) { $defaultPreferences['enotifusertalkpages'] = array( 'type' => 'toggle', @@ -422,7 +440,6 @@ class Preferences { 'disabled' => $disableEmailPrefs, ); - global $wgEnotifRevealEditorAddress; if ( $wgEnotifRevealEditorAddress ) { $defaultPreferences['enotifrevealaddr'] = array( 'type' => 'toggle', @@ -435,13 +452,19 @@ class Preferences { } } - static function skinPreferences( $user, &$defaultPreferences ) { + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences + * @return void + */ + static function skinPreferences( $user, IContextSource $context, &$defaultPreferences ) { ## Skin ##################################### - global $wgLang, $wgAllowUserCss, $wgAllowUserJs; + global $wgAllowUserCss, $wgAllowUserJs; $defaultPreferences['skin'] = array( 'type' => 'radio', - 'options' => self::generateSkinOptions( $user ), + 'options' => self::generateSkinOptions( $user, $context ), 'label' => ' ', 'section' => 'rendering/skin', ); @@ -450,23 +473,22 @@ class Preferences { # This code is basically copied from generateSkinOptions(). It'd # be nice to somehow merge this back in there to avoid redundancy. if ( $wgAllowUserCss || $wgAllowUserJs ) { - $sk = $user->getSkin(); $linkTools = array(); if ( $wgAllowUserCss ) { $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.css' ); - $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) ); + $linkTools[] = Linker::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() ); } if ( $wgAllowUserJs ) { $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.js' ); - $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) ); + $linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() ); } $defaultPreferences['commoncssjs'] = array( 'type' => 'info', 'raw' => true, - 'default' => $wgLang->pipeList( $linkTools ), + 'default' => $context->getLanguage()->pipeList( $linkTools ), 'label-message' => 'prefs-common-css-js', 'section' => 'rendering/skin', ); @@ -474,9 +496,7 @@ class Preferences { $selectedSkin = $user->getOption( 'skin' ); if ( in_array( $selectedSkin, array( 'cologneblue', 'standard' ) ) ) { - global $wgLang; - - $settings = array_flip( $wgLang->getQuickbarSettings() ); + $settings = array_flip( $context->getLanguage()->getQuickbarSettings() ); $defaultPreferences['quickbar'] = array( 'type' => 'radio', @@ -487,40 +507,36 @@ class Preferences { } } - static function mathPreferences( $user, &$defaultPreferences ) { - ## Math ##################################### - global $wgUseTeX, $wgLang; - if ( $wgUseTeX ) { - $defaultPreferences['math'] = array( - 'type' => 'radio', - 'options' => array_flip( array_map( 'wfMsgHtml', $wgLang->getMathNames() ) ), - 'label' => ' ', - 'section' => 'rendering/math', - ); - } - } - - static function filesPreferences( $user, &$defaultPreferences ) { + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences Array + */ + static function filesPreferences( $user, IContextSource $context, &$defaultPreferences ) { ## Files ##################################### $defaultPreferences['imagesize'] = array( 'type' => 'select', - 'options' => self::getImageSizes(), + 'options' => self::getImageSizes( $context ), 'label-message' => 'imagemaxsize', 'section' => 'rendering/files', ); $defaultPreferences['thumbsize'] = array( 'type' => 'select', - 'options' => self::getThumbSizes(), + 'options' => self::getThumbSizes( $context ), 'label-message' => 'thumbsize', 'section' => 'rendering/files', ); } - static function datetimePreferences( $user, &$defaultPreferences ) { - global $wgLang; - + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences + * @return void + */ + static function datetimePreferences( $user, IContextSource $context, &$defaultPreferences ) { ## Date and time ##################################### - $dateOptions = self::getDateOptions(); + $dateOptions = self::getDateOptions( $context ); if ( $dateOptions ) { $defaultPreferences['date'] = array( 'type' => 'radio', @@ -531,10 +547,12 @@ class Preferences { } // Info + $now = wfTimestampNow(); + $lang = $context->getLanguage(); $nowlocal = Xml::element( 'span', array( 'id' => 'wpLocalTime' ), - $wgLang->time( $now = wfTimestampNow(), true ) ); - $nowserver = $wgLang->time( $now, false ) . - Xml::hidden( 'wpServerTime', substr( $now, 8, 2 ) * 60 + substr( $now, 10, 2 ) ); + $lang->time( $now, true ) ); + $nowserver = $lang->time( $now, false ) . + Html::hidden( 'wpServerTime', (int)substr( $now, 8, 2 ) * 60 + (int)substr( $now, 10, 2 ) ); $defaultPreferences['nowserver'] = array( 'type' => 'info', @@ -554,44 +572,60 @@ class Preferences { // Grab existing pref. $tzOffset = $user->getOption( 'timecorrection' ); - $tz = explode( '|', $tzOffset, 2 ); + $tz = explode( '|', $tzOffset, 3 ); + + $tzOptions = self::getTimezoneOptions( $context ); $tzSetting = $tzOffset; if ( count( $tz ) > 1 && $tz[0] == 'Offset' ) { $minDiff = $tz[1]; $tzSetting = sprintf( '%+03d:%02d', floor( $minDiff / 60 ), abs( $minDiff ) % 60 ); + } elseif ( count( $tz ) > 1 && $tz[0] == 'ZoneInfo' && + !in_array( $tzOffset, HTMLFormField::flattenOptions( $tzOptions ) ) ) + { + # Timezone offset can vary with DST + $userTZ = timezone_open( $tz[2] ); + if ( $userTZ !== false ) { + $minDiff = floor( timezone_offset_get( $userTZ, date_create( 'now' ) ) / 60 ); + $tzSetting = "ZoneInfo|$minDiff|{$tz[2]}"; + } } $defaultPreferences['timecorrection'] = array( 'class' => 'HTMLSelectOrOtherField', 'label-message' => 'timezonelegend', - 'options' => self::getTimezoneOptions(), + 'options' => $tzOptions, 'default' => $tzSetting, 'size' => 20, 'section' => 'datetime/timeoffset', ); } - static function renderingPreferences( $user, &$defaultPreferences ) { + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences Array + */ + static function renderingPreferences( $user, IContextSource $context, &$defaultPreferences ) { ## Page Rendering ############################## global $wgAllowUserCssPrefs; if ( $wgAllowUserCssPrefs ) { $defaultPreferences['underline'] = array( 'type' => 'select', 'options' => array( - wfMsg( 'underline-never' ) => 0, - wfMsg( 'underline-always' ) => 1, - wfMsg( 'underline-default' ) => 2, + $context->msg( 'underline-never' )->text() => 0, + $context->msg( 'underline-always' )->text() => 1, + $context->msg( 'underline-default' )->text() => 2, ), 'label-message' => 'tog-underline', 'section' => 'rendering/advancedrendering', ); } - $stubThresholdValues = array( 0, 50, 100, 500, 1000, 2000, 5000, 10000 ); - $stubThresholdOptions = array(); + $stubThresholdValues = array( 50, 100, 500, 1000, 2000, 5000, 10000 ); + $stubThresholdOptions = array( $context->msg( 'stub-threshold-disabled' )->text() => 0 ); foreach ( $stubThresholdValues as $value ) { - $stubThresholdOptions[wfMsg( 'size-bytes', $value )] = $value; + $stubThresholdOptions[$context->msg( 'size-bytes', $value )->text()] = $value; } $defaultPreferences['stubthreshold'] = array( @@ -599,14 +633,14 @@ class Preferences { 'section' => 'rendering/advancedrendering', 'options' => $stubThresholdOptions, 'size' => 20, - 'label' => wfMsg( 'stub-threshold' ), // Raw HTML message. Yay? + 'label' => $context->msg( 'stub-threshold' )->text(), // Raw HTML message. Yay? ); if ( $wgAllowUserCssPrefs ) { $defaultPreferences['highlightbroken'] = array( 'type' => 'toggle', 'section' => 'rendering/advancedrendering', - 'label' => wfMsg( 'tog-highlightbroken' ), // Raw HTML + 'label' => $context->msg( 'tog-highlightbroken' )->text(), // Raw HTML ); $defaultPreferences['showtoc'] = array( 'type' => 'toggle', @@ -645,17 +679,16 @@ class Preferences { ); } - static function editingPreferences( $user, &$defaultPreferences ) { + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences Array + */ + static function editingPreferences( $user, IContextSource $context, &$defaultPreferences ) { global $wgUseExternalEditor, $wgAllowUserCssPrefs; ## Editing ##################################### - $defaultPreferences['cols'] = array( - 'type' => 'int', - 'label-message' => 'columns', - 'section' => 'editing/textboxsize', - 'min' => 4, - 'max' => 1000, - ); + $defaultPreferences['rows'] = array( 'type' => 'int', 'label-message' => 'rows', @@ -670,10 +703,10 @@ class Preferences { 'section' => 'editing/advancedediting', 'label-message' => 'editfont-style', 'options' => array( - wfMsg( 'editfont-default' ) => 'default', - wfMsg( 'editfont-monospace' ) => 'monospace', - wfMsg( 'editfont-sansserif' ) => 'sans-serif', - wfMsg( 'editfont-serif' ) => 'serif', + $context->msg( 'editfont-default' )->text() => 'default', + $context->msg( 'editfont-monospace' )->text() => 'monospace', + $context->msg( 'editfont-sansserif' )->text() => 'sans-serif', + $context->msg( 'editfont-serif' )->text() => 'serif', ) ); } @@ -711,6 +744,14 @@ class Preferences { 'label-message' => 'tog-showtoolbar', ); + if ( $user->isAllowed( 'minoredit' ) ) { + $defaultPreferences['minordefault'] = array( + 'type' => 'toggle', + 'section' => 'editing/advancedediting', + 'label-message' => 'tog-minordefault', + ); + } + if ( $wgUseExternalEditor ) { $defaultPreferences['externaleditor'] = array( 'type' => 'toggle', @@ -730,7 +771,7 @@ class Preferences { 'label-message' => 'tog-forceeditsummary', ); - + $defaultPreferences['uselivepreview'] = array( 'type' => 'toggle', 'section' => 'editing/advancedediting', @@ -738,8 +779,13 @@ class Preferences { ); } - static function rcPreferences( $user, &$defaultPreferences ) { - global $wgRCMaxAge, $wgUseRCPatrol, $wgLang; + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences Array + */ + static function rcPreferences( $user, IContextSource $context, &$defaultPreferences ) { + global $wgRCMaxAge, $wgRCShowWatchingUsers; ## RecentChanges ##################################### $defaultPreferences['rcdays'] = array( @@ -748,11 +794,8 @@ class Preferences { 'section' => 'rc/displayrc', 'min' => 1, 'max' => ceil( $wgRCMaxAge / ( 3600 * 24 ) ), - 'help' => wfMsgExt( - 'recentchangesdays-max', - array( 'parsemag' ), - $wgLang->formatNum( ceil( $wgRCMaxAge / ( 3600 * 24 ) ) ) - ) + 'help' => $context->msg( 'recentchangesdays-max' )->numParams( + ceil( $wgRCMaxAge / ( 3600 * 24 ) ) )->text() ); $defaultPreferences['rclimit'] = array( 'type' => 'int', @@ -771,7 +814,7 @@ class Preferences { 'section' => 'rc/advancedrc', ); - if ( $wgUseRCPatrol ) { + if ( $user->useRCPatrol() ) { $defaultPreferences['hidepatrolled'] = array( 'type' => 'toggle', 'section' => 'rc/advancedrc', @@ -784,7 +827,6 @@ class Preferences { ); } - global $wgRCShowWatchingUsers; if ( $wgRCShowWatchingUsers ) { $defaultPreferences['shownumberswatching'] = array( 'type' => 'toggle', @@ -794,16 +836,24 @@ class Preferences { } } - static function watchlistPreferences( $user, &$defaultPreferences ) { - global $wgUseRCPatrol, $wgEnableAPI; + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences + */ + static function watchlistPreferences( $user, IContextSource $context, &$defaultPreferences ) { + global $wgUseRCPatrol, $wgEnableAPI, $wgRCMaxAge; + $watchlistdaysMax = ceil( $wgRCMaxAge / ( 3600 * 24 ) ); + ## Watchlist ##################################### $defaultPreferences['watchlistdays'] = array( 'type' => 'float', 'min' => 0, - 'max' => 7, + 'max' => $watchlistdaysMax, 'section' => 'watchlist/displaywatchlist', - 'help' => wfMsgHtml( 'prefs-watchlist-days-max' ), + 'help' => $context->msg( 'prefs-watchlist-days-max' )->numParams( + $watchlistdaysMax )->text(), 'label-message' => 'prefs-watchlist-days', ); $defaultPreferences['wllimit'] = array( @@ -811,7 +861,7 @@ class Preferences { 'min' => 0, 'max' => 1000, 'label-message' => 'prefs-watchlist-edits', - 'help' => wfMsgHtml( 'prefs-watchlist-edits-max' ), + 'help' => $context->msg( 'prefs-watchlist-edits-max' )->escaped(), 'section' => 'watchlist/displaywatchlist', ); $defaultPreferences['extendwatchlist'] = array( @@ -861,7 +911,7 @@ class Preferences { 'type' => 'text', 'section' => 'watchlist/advancedwatchlist', 'label-message' => 'prefs-watchlist-token', - 'help' => wfMsgHtml( 'prefs-help-watchlist-token', $hash ) + 'help' => $context->msg( 'prefs-help-watchlist-token', $hash )->escaped() ); } @@ -887,8 +937,13 @@ class Preferences { } } - static function searchPreferences( $user, &$defaultPreferences ) { - global $wgContLang; + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences Array + */ + static function searchPreferences( $user, IContextSource $context, &$defaultPreferences ) { + global $wgContLang, $wgEnableMWSuggest, $wgVectorUseSimpleSearch; ## Search ##################################### $defaultPreferences['searchlimit'] = array( @@ -897,20 +952,7 @@ class Preferences { 'section' => 'searchoptions/displaysearchoptions', 'min' => 0, ); - $defaultPreferences['contextlines'] = array( - 'type' => 'int', - 'label-message' => 'contextlines', - 'section' => 'searchoptions/displaysearchoptions', - 'min' => 0, - ); - $defaultPreferences['contextchars'] = array( - 'type' => 'int', - 'label-message' => 'contextchars', - 'section' => 'searchoptions/displaysearchoptions', - 'min' => 0, - ); - global $wgEnableMWSuggest; if ( $wgEnableMWSuggest ) { $defaultPreferences['disablesuggest'] = array( 'type' => 'toggle', @@ -918,8 +960,7 @@ class Preferences { 'section' => 'searchoptions/displaysearchoptions', ); } - - global $wgVectorUseSimpleSearch; + if ( $wgVectorUseSimpleSearch ) { $defaultPreferences['vector-simplesearch'] = array( 'type' => 'toggle', @@ -934,9 +975,6 @@ class Preferences { 'section' => 'searchoptions/advancedsearchoptions', ); - // Searchable namespaces back-compat with old format - $searchableNamespaces = SearchEngine::searchableNamespaces(); - $nsOptions = array(); foreach ( $wgContLang->getNamespaces() as $ns => $name ) { @@ -947,7 +985,7 @@ class Preferences { $displayNs = str_replace( '_', ' ', $name ); if ( !$displayNs ) { - $displayNs = wfMsg( 'blanknamespace' ); + $displayNs = $context->msg( 'blanknamespace' )->text(); } $displayNs = htmlspecialchars( $displayNs ); @@ -963,7 +1001,14 @@ class Preferences { ); } - static function miscPreferences( $user, &$defaultPreferences ) { + /** + * @param $user User + * @param $context IContextSource + * @param $defaultPreferences Array + */ + static function miscPreferences( $user, IContextSource $context, &$defaultPreferences ) { + global $wgContLang; + ## Misc ##################################### $defaultPreferences['diffonly'] = array( 'type' => 'toggle', @@ -977,8 +1022,6 @@ class Preferences { ); // Stuff from Language::getExtraUserToggles() - global $wgContLang; - $toggles = $wgContLang->getExtraUserToggles(); foreach ( $toggles as $toggle ) { @@ -991,15 +1034,16 @@ class Preferences { } /** - * @param $user The User object + * @param $user User The User object + * @param $context IContextSource * @return Array: text/links to display as key; $skinkey as value */ - static function generateSkinOptions( $user ) { - global $wgDefaultSkin, $wgLang, $wgAllowUserCss, $wgAllowUserJs; + static function generateSkinOptions( $user, IContextSource $context ) { + global $wgDefaultSkin, $wgAllowUserCss, $wgAllowUserJs; $ret = array(); $mptitle = Title::newMainPage(); - $previewtext = wfMsgHtml( 'skin-preview' ); + $previewtext = $context->msg( 'skin-preview' )->text(); # Only show members of Skin::getSkinNames() rather than # $skinNames (skins is all skin names from Language.php) @@ -1008,21 +1052,19 @@ class Preferences { # Sort by UI skin name. First though need to update validSkinNames as sometimes # the skinkey & UI skinname differ (e.g. "standard" skinkey is "Classic" in the UI). foreach ( $validSkinNames as $skinkey => &$skinname ) { - $msgName = "skinname-{$skinkey}"; - $localisedSkinName = wfMsg( $msgName ); - if ( !wfEmptyMsg( $msgName, $localisedSkinName ) ) { - $skinname = htmlspecialchars( $localisedSkinName ); + $msg = $context->msg( "skinname-{$skinkey}" ); + if ( $msg->exists() ) { + $skinname = htmlspecialchars( $msg->text() ); } } asort( $validSkinNames ); - $sk = $user->getSkin(); foreach ( $validSkinNames as $skinkey => $sn ) { $linkTools = array(); # Mark the default skin if ( $skinkey == $wgDefaultSkin ) { - $linkTools[] = wfMsgHtml( 'default' ); + $linkTools[] = $context->msg( 'default' )->escaped(); } # Create preview link @@ -1032,24 +1074,28 @@ class Preferences { # Create links to user CSS/JS pages if ( $wgAllowUserCss ) { $cssPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.css' ); - $linkTools[] = $sk->link( $cssPage, wfMsgHtml( 'prefs-custom-css' ) ); + $linkTools[] = Linker::link( $cssPage, $context->msg( 'prefs-custom-css' )->escaped() ); } if ( $wgAllowUserJs ) { $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.js' ); - $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) ); + $linkTools[] = Linker::link( $jsPage, $context->msg( 'prefs-custom-js' )->escaped() ); } - $display = $sn . ' ' . wfMsg( 'parentheses', $wgLang->pipeList( $linkTools ) ); + $display = $sn . ' ' . $context->msg( 'parentheses', $context->getLanguage()->pipeList( $linkTools ) )->text(); $ret[$display] = $skinkey; } return $ret; } - static function getDateOptions() { - global $wgLang; - $dateopts = $wgLang->getDatePreferences(); + /** + * @param $context IContextSource + * @return array + */ + static function getDateOptions( IContextSource $context ) { + $lang = $context->getLanguage(); + $dateopts = $lang->getDatePreferences(); $ret = array(); @@ -1065,13 +1111,12 @@ class Preferences { $wgDefaultUserOptions['date'] = 'default'; } - $idCnt = 0; $epoch = wfTimestampNow(); foreach ( $dateopts as $key ) { if ( $key == 'default' ) { - $formatted = wfMsgHtml( 'datedefault' ); + $formatted = $context->msg( 'datedefault' )->escaped(); } else { - $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) ); + $formatted = htmlspecialchars( $lang->timeanddate( $epoch, false, $key ) ); } $ret[$formatted] = $key; } @@ -1079,94 +1124,123 @@ class Preferences { return $ret; } - static function getImageSizes() { + /** + * @param $context IContextSource + * @return array + */ + static function getImageSizes( IContextSource $context ) { global $wgImageLimits; $ret = array(); + $pixels = $context->msg( 'unit-pixel' )->text(); foreach ( $wgImageLimits as $index => $limits ) { - $display = "{$limits[0]}×{$limits[1]}" . wfMsg( 'unit-pixel' ); + $display = "{$limits[0]}×{$limits[1]}" . $pixels; $ret[$display] = $index; } return $ret; } - static function getThumbSizes() { + /** + * @param $context IContextSource + * @return array + */ + static function getThumbSizes( IContextSource $context ) { global $wgThumbLimits; $ret = array(); + $pixels = $context->msg( 'unit-pixel' )->text(); foreach ( $wgThumbLimits as $index => $size ) { - $display = $size . wfMsg( 'unit-pixel' ); + $display = $size . $pixels; $ret[$display] = $index; } return $ret; } - static function validateSignature( $signature, $alldata ) { - global $wgParser, $wgMaxSigChars, $wgLang; + /** + * @param $signature string + * @param $alldata array + * @param $form HTMLForm + * @return bool|string + */ + static function validateSignature( $signature, $alldata, $form ) { + global $wgParser, $wgMaxSigChars; if ( mb_strlen( $signature ) > $wgMaxSigChars ) { return Xml::element( 'span', array( 'class' => 'error' ), - wfMsgExt( 'badsiglength', 'parsemag', - $wgLang->formatNum( $wgMaxSigChars ) - ) - ); - } elseif ( !empty( $alldata['fancysig'] ) && + $form->msg( 'badsiglength' )->numParams( $wgMaxSigChars )->text() ); + } elseif ( isset( $alldata['fancysig'] ) && + $alldata['fancysig'] && false === $wgParser->validateSig( $signature ) ) { - return Xml::element( 'span', array( 'class' => 'error' ), wfMsg( 'badsig' ) ); + return Xml::element( 'span', array( 'class' => 'error' ), $form->msg( 'badsig' )->text() ); } else { return true; } } - static function cleanSignature( $signature, $alldata ) { - global $wgParser; - if ( $alldata['fancysig'] ) { + /** + * @param $signature string + * @param $alldata array + * @param $form HTMLForm + * @return string + */ + static function cleanSignature( $signature, $alldata, $form ) { + if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) { + global $wgParser; $signature = $wgParser->cleanSig( $signature ); } else { // When no fancy sig used, make sure ~{3,5} get removed. - $signature = $wgParser->cleanSigInSig( $signature ); + $signature = Parser::cleanSigInSig( $signature ); } return $signature; } - static function validateEmail( $email, $alldata ) { - if ( $email && !User::isValidEmailAddr( $email ) ) { - return wfMsgExt( 'invalidemailaddress', 'parseinline' ); - } - - global $wgEmailConfirmToEdit; - if ( $wgEmailConfirmToEdit && !$email ) { - return wfMsgExt( 'noemailtitle', 'parseinline' ); + /** + * @param $user User + * @param $context IContextSource + * @param $formClass string + * @param $remove Array: array of items to remove + * @return HtmlForm + */ + static function getFormObject( $user, IContextSource $context, $formClass = 'PreferencesForm', array $remove = array() ) { + $formDescriptor = Preferences::getPreferences( $user, $context ); + if ( count( $remove ) ) { + $removeKeys = array_flip( $remove ); + $formDescriptor = array_diff_key( $formDescriptor, $removeKeys ); } - return true; - } + $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' ); - static function getFormObject( $user, $formClass = 'PreferencesForm' ) { - $formDescriptor = Preferences::getPreferences( $user ); - $htmlForm = new $formClass( $formDescriptor, 'prefs' ); - - $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) ); + $htmlForm->setModifiedUser( $user ); + $htmlForm->setId( 'mw-prefs-form' ); + $htmlForm->setSubmitText( $context->msg( 'saveprefs' )->text() ); # Used message keys: 'accesskey-preferences-save', 'tooltip-preferences-save' $htmlForm->setSubmitTooltip( 'preferences-save' ); - $htmlForm->setTitle( SpecialPage::getTitleFor( 'Preferences' ) ); $htmlForm->setSubmitID( 'prefsubmit' ); $htmlForm->setSubmitCallback( array( 'Preferences', 'tryFormSubmit' ) ); return $htmlForm; } - static function getTimezoneOptions() { + /** + * @return array + */ + static function getTimezoneOptions( IContextSource $context ) { $opt = array(); - global $wgLocalTZoffset; - - $opt[wfMsg( 'timezoneuseserverdefault' )] = "System|$wgLocalTZoffset"; - $opt[wfMsg( 'timezoneuseoffset' )] = 'other'; - $opt[wfMsg( 'guesstimezone' )] = 'guess'; + global $wgLocalTZoffset, $wgLocaltimezone; + // Check that $wgLocalTZoffset is the same as $wgLocaltimezone + if ( $wgLocalTZoffset == date( 'Z' ) / 60 ) { + $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $wgLocaltimezone )->text(); + } else { + $tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 ); + $server_tz_msg = $context->msg( 'timezoneuseserverdefault', $tzstring )->text(); + } + $opt[$server_tz_msg] = "System|$wgLocalTZoffset"; + $opt[$context->msg( 'timezoneuseoffset' )->text()] = 'other'; + $opt[$context->msg( 'guesstimezone' )->text()] = 'guess'; if ( function_exists( 'timezone_identifiers_list' ) ) { # Read timezone list @@ -1174,16 +1248,16 @@ class Preferences { sort( $tzs ); $tzRegions = array(); - $tzRegions['Africa'] = wfMsg( 'timezoneregion-africa' ); - $tzRegions['America'] = wfMsg( 'timezoneregion-america' ); - $tzRegions['Antarctica'] = wfMsg( 'timezoneregion-antarctica' ); - $tzRegions['Arctic'] = wfMsg( 'timezoneregion-arctic' ); - $tzRegions['Asia'] = wfMsg( 'timezoneregion-asia' ); - $tzRegions['Atlantic'] = wfMsg( 'timezoneregion-atlantic' ); - $tzRegions['Australia'] = wfMsg( 'timezoneregion-australia' ); - $tzRegions['Europe'] = wfMsg( 'timezoneregion-europe' ); - $tzRegions['Indian'] = wfMsg( 'timezoneregion-indian' ); - $tzRegions['Pacific'] = wfMsg( 'timezoneregion-pacific' ); + $tzRegions['Africa'] = $context->msg( 'timezoneregion-africa' )->text(); + $tzRegions['America'] = $context->msg( 'timezoneregion-america' )->text(); + $tzRegions['Antarctica'] = $context->msg( 'timezoneregion-antarctica' )->text(); + $tzRegions['Arctic'] = $context->msg( 'timezoneregion-arctic' )->text(); + $tzRegions['Asia'] = $context->msg( 'timezoneregion-asia' )->text(); + $tzRegions['Atlantic'] = $context->msg( 'timezoneregion-atlantic' )->text(); + $tzRegions['Australia'] = $context->msg( 'timezoneregion-australia' )->text(); + $tzRegions['Europe'] = $context->msg( 'timezoneregion-europe' )->text(); + $tzRegions['Indian'] = $context->msg( 'timezoneregion-indian' )->text(); + $tzRegions['Pacific'] = $context->msg( 'timezoneregion-pacific' )->text(); asort( $tzRegions ); $prefill = array_fill_keys( array_values( $tzRegions ), array() ); @@ -1215,6 +1289,20 @@ class Preferences { return $opt; } + /** + * @param $value + * @param $alldata + * @return int + */ + static function filterIntval( $value, $alldata ){ + return intval( $value ); + } + + /** + * @param $tz + * @param $alldata + * @return string + */ static function filterTimezoneInput( $tz, $alldata ) { $data = explode( '|', $tz, 3 ); switch ( $data[0] ) { @@ -1223,7 +1311,6 @@ class Preferences { return $tz; default: $data = explode( ':', $tz, 2 ); - $minDiff = 0; if ( count( $data ) == 2 ) { $data[0] = intval( $data[0] ); $data[1] = intval( $data[1] ); @@ -1241,9 +1328,16 @@ class Preferences { } } - static function tryFormSubmit( $formData, $entryPoint = 'internal' ) { - global $wgUser, $wgEmailAuthentication, $wgEnableEmail; + /** + * @param $formData + * @param $form HTMLForm + * @param $entryPoint string + * @return bool|Status|string + */ + static function tryFormSubmit( $formData, $form, $entryPoint = 'internal' ) { + global $wgHiddenPrefs; + $user = $form->getModifiedUser(); $result = true; // Filter input @@ -1260,78 +1354,106 @@ class Preferences { 'emailaddress', ); - if ( $wgEnableEmail ) { - $newaddr = $formData['emailaddress']; - $oldaddr = $wgUser->getEmail(); - if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) { - # the user has supplied a new email address on the login page - # new behaviour: set this new emailaddr from login-page into user database record - $wgUser->setEmail( $newaddr ); - # but flag as "dirty" = unauthenticated - $wgUser->invalidateEmail(); - if ( $wgEmailAuthentication ) { - # Mail a temporary password to the dirty address. - # User can come back through the confirmation URL to re-enable email. - $result = $wgUser->sendConfirmationMail( $oldaddr != '' ); - if ( WikiError::isError( $result ) ) { - return wfMsg( 'mailerror', htmlspecialchars( $result->getMessage() ) ); - } elseif ( $entryPoint == 'ui' ) { - $result = 'eauth'; - } - } - } else { - $wgUser->setEmail( $newaddr ); - } - if ( $oldaddr != $newaddr ) { - wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldaddr, $newaddr ) ); - } - } - // Fortunately, the realname field is MUCH simpler - global $wgHiddenPrefs; if ( !in_array( 'realname', $wgHiddenPrefs ) ) { $realName = $formData['realname']; - $wgUser->setRealName( $realName ); + $user->setRealName( $realName ); } foreach ( $saveBlacklist as $b ) { unset( $formData[$b] ); } + # If users have saved a value for a preference which has subsequently been disabled + # via $wgHiddenPrefs, we don't want to destroy that setting in case the preference + # is subsequently re-enabled + # TODO: maintenance script to actually delete these + foreach( $wgHiddenPrefs as $pref ){ + # If the user has not set a non-default value here, the default will be returned + # and subsequently discarded + $formData[$pref] = $user->getOption( $pref, null, true ); + } + // Keeps old preferences from interfering due to back-compat // code, etc. - $wgUser->resetOptions(); + $user->resetOptions(); foreach ( $formData as $key => $value ) { - $wgUser->setOption( $key, $value ); + $user->setOption( $key, $value ); } - $wgUser->saveSettings(); + $user->saveSettings(); return $result; } - public static function tryUISubmit( $formData ) { - $res = self::tryFormSubmit( $formData, 'ui' ); + /** + * @param $formData + * @return Status + */ + public static function tryUISubmit( $formData, $form ) { + $res = self::tryFormSubmit( $formData, $form, 'ui' ); if ( $res ) { - $urlOptions = array( 'success' ); + $urlOptions = array( 'success' => 1 ); if ( $res === 'eauth' ) { - $urlOptions[] = 'eauth'; + $urlOptions['eauth'] = 1; } - $queryString = implode( '&', $urlOptions ); + $urlOptions += $form->getExtraSuccessRedirectParameters(); - $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( $queryString ); + $url = $form->getTitle()->getFullURL( $urlOptions ); - global $wgOut; - $wgOut->redirect( $url ); + $form->getContext()->getOutput()->redirect( $url ); } - return true; + return Status::newGood(); } + /** + * Try to set a user's email address. + * This does *not* try to validate the address. + * Caller is responsible for checking $wgAuth. + * @param $user User + * @param $newaddr string New email address + * @return Array (true on success or Status on failure, info string) + */ + public static function trySetUserEmail( User $user, $newaddr ) { + global $wgEnableEmail, $wgEmailAuthentication; + $info = ''; // none + + if ( $wgEnableEmail ) { + $oldaddr = $user->getEmail(); + if ( ( $newaddr != '' ) && ( $newaddr != $oldaddr ) ) { + # The user has supplied a new email address on the login page + # new behaviour: set this new emailaddr from login-page into user database record + $user->setEmail( $newaddr ); + if ( $wgEmailAuthentication ) { + # Mail a temporary password to the dirty address. + # User can come back through the confirmation URL to re-enable email. + $type = $oldaddr != '' ? 'changed' : 'set'; + $result = $user->sendConfirmationMail( $type ); + if ( !$result->isGood() ) { + return array( $result, 'mailerror' ); + } + $info = 'eauth'; + } + } elseif ( $newaddr != $oldaddr ) { // if the address is the same, don't change it + $user->setEmail( $newaddr ); + } + if ( $oldaddr != $newaddr ) { + wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) ); + } + } + + return array( true, $info ); + } + + /** + * @param $user User + * @return array + */ public static function loadOldSearchNs( $user ) { $searchableNamespaces = SearchEngine::searchableNamespaces(); // Back compat with old format @@ -1349,27 +1471,62 @@ class Preferences { /** Some tweaks to allow js prefs to work */ class PreferencesForm extends HTMLForm { + // Override default value from HTMLForm + protected $mSubSectionBeforeFields = false; + + private $modifiedUser; + + public function setModifiedUser( $user ) { + $this->modifiedUser = $user; + } + + public function getModifiedUser() { + if ( $this->modifiedUser === null ) { + return $this->getUser(); + } else { + return $this->modifiedUser; + } + } + + /** + * Get extra parameters for the query string when redirecting after + * successful save. + * + * @return array() + */ + public function getExtraSuccessRedirectParameters() { + return array(); + } + + /** + * @param $html string + * @return String + */ function wrapForm( $html ) { $html = Xml::tags( 'div', array( 'id' => 'preferences' ), $html ); return parent::wrapForm( $html ); } + /** + * @return String + */ function getButtons() { $html = parent::getButtons(); - global $wgUser; - - $sk = $wgUser->getSkin(); $t = SpecialPage::getTitleFor( 'Preferences', 'reset' ); - $html .= "\n" . $sk->link( $t, wfMsgHtml( 'restoreprefs' ) ); + $html .= "\n" . Linker::link( $t, $this->msg( 'restoreprefs' )->escaped() ); $html = Xml::tags( 'div', array( 'class' => 'mw-prefs-buttons' ), $html ); return $html; } + /** + * @param $data array + * @return array + */ function filterDataForSubmit( $data ) { // Support for separating MultiSelect preferences into multiple preferences // Due to lack of array support. @@ -1389,4 +1546,20 @@ class PreferencesForm extends HTMLForm { return $data; } + /** + * Get the whole body of the form. + */ + function getBody() { + return $this->displaySection( $this->mFieldTree, '', 'mw-prefsection-' ); + } + + /** + * Get the for a given section key. Normally this is the + * prefs-$key message but we'll allow extensions to override it. + */ + function getLegend( $key ) { + $legend = parent::getLegend( $key ); + wfRunHooks( 'PreferencesGetLegend', array( $this, $key, &$legend ) ); + return $legend; + } }