Fux PHP Notice: Undefined property: ContribsPager::$showSizeDiff in /www/w/includes...
[lhc/web/wiklou.git] / includes / Preferences.php
index 2723f75..c999a2e 100644 (file)
@@ -131,7 +131,7 @@ class Preferences {
         * @return void
         */
        static function profilePreferences( $user, &$defaultPreferences ) {
-               global $wgLang, $wgUser;
+               global $wgLang;
                ## User info #####################################
                // Information panel
                $defaultPreferences['username'] = array(
@@ -224,7 +224,7 @@ class Preferences {
                );
 
                if ( $wgAuth->allowPasswordChange() ) {
-                       $link = $wgUser->getSkin()->link( SpecialPage::getTitleFor( 'ChangePassword' ),
+                       $link = Linker::link( SpecialPage::getTitleFor( 'ChangePassword' ),
                                wfMsgHtml( 'prefs-resetpass' ), array(),
                                array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) );
 
@@ -314,7 +314,7 @@ class Preferences {
 
                // show a preview of the old signature first
                $oldsigWikiText = $wgParser->preSaveTransform( "~~~", new Title, $user, new ParserOptions );
-               $oldsigHTML = $wgOut->parseInline( $oldsigWikiText );
+               $oldsigHTML = $wgOut->parseInline( $oldsigWikiText, true, true );
                $defaultPreferences['oldsig'] = array(
                        'type' => 'info',
                        'raw' => true,
@@ -353,13 +353,20 @@ class Preferences {
                                $helpMessages[] = 'prefs-help-email-others';
                        }
 
+                       $link = Linker::link(
+                               SpecialPage::getTitleFor( 'ChangeEmail' ),
+                               wfMsgHtml( $user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail' ),
+                               array(),
+                               array( 'returnto' => SpecialPage::getTitleFor( 'Preferences' ) ) );
+
                        $defaultPreferences['emailaddress'] = array(
-                               'type' => $wgAuth->allowPropChange( 'emailaddress' ) ? 'email' : 'info',
-                               'default' => $user->getEmail(),
-                               'section' => 'personal/email',
+                               'type' => 'info',
+                               'raw' => true,
+                               'default' => $user->getEmail()
+                                       ? htmlspecialchars( $user->getEmail() ) . " ($link)"
+                                       : $link,
                                'label-message' => 'youremail',
-                               'help-messages' => $helpMessages,
-                               'validation-callback' => array( 'Preferences', 'validateEmail' ),
+                               'section' => 'personal/email',
                        );
 
                        global $wgEmailAuthentication;
@@ -382,14 +389,10 @@ class Preferences {
                                                $disableEmailPrefs = false;
                                        } else {
                                                $disableEmailPrefs = true;
-                                               $skin = $wgUser->getSkin();
                                                $emailauthenticated = wfMsgExt( 'emailnotauthenticated', 'parseinline' ) . '<br />' .
-                                                       $skin->link(
+                                                       Linker::linkKnown(
                                                                SpecialPage::getTitleFor( 'Confirmemail' ),
-                                                               wfMsg( 'emailconfirmlink' ),
-                                                               array(),
-                                                               array(),
-                                                               array( 'known', 'noclasses' )
+                                                               wfMsg( 'emailconfirmlink' )
                                                        ) . '<br />';
                                        }
                                } else {
@@ -482,17 +485,16 @@ 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, wfMsgHtml( 'prefs-custom-css' ) );
                        }
 
                        if ( $wgAllowUserJs ) {
                                $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/common.js' );
-                               $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
+                               $linkTools[] = Linker::link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
                        }
 
                        $defaultPreferences['commoncssjs'] = array(
@@ -517,6 +519,10 @@ class Preferences {
                }
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences Array
+        */
        static function filesPreferences( $user, &$defaultPreferences ) {
                ## Files #####################################
                $defaultPreferences['imagesize'] = array(
@@ -595,6 +601,10 @@ class Preferences {
                );
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences Array
+        */
        static function renderingPreferences( $user, &$defaultPreferences ) {
                ## Page Rendering ##############################
                global $wgAllowUserCssPrefs;
@@ -668,6 +678,10 @@ class Preferences {
                );
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences Array
+        */
        static function editingPreferences( $user, &$defaultPreferences ) {
                global $wgUseExternalEditor, $wgAllowUserCssPrefs;
 
@@ -733,11 +747,14 @@ class Preferences {
                        'section' => 'editing/advancedediting',
                        'label-message' => 'tog-showtoolbar',
                );
-               $defaultPreferences['minordefault'] = array(
-                       'type' => 'toggle',
-                       'section' => 'editing/advancedediting',
-                       'label-message' => 'tog-minordefault',
-               );
+
+               if ( $user->isAllowed( 'minoredit' ) ) {
+                       $defaultPreferences['minordefault'] = array(
+                               'type' => 'toggle',
+                               'section' => 'editing/advancedediting',
+                               'label-message' => 'tog-minordefault',
+                       );
+               }
 
                if ( $wgUseExternalEditor ) {
                        $defaultPreferences['externaleditor'] = array(
@@ -766,8 +783,12 @@ class Preferences {
                );
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences Array
+        */
        static function rcPreferences( $user, &$defaultPreferences ) {
-               global $wgRCMaxAge, $wgUseRCPatrol, $wgLang;
+               global $wgRCMaxAge, $wgLang;
 
                ## RecentChanges #####################################
                $defaultPreferences['rcdays'] = array(
@@ -799,7 +820,7 @@ class Preferences {
                        'section' => 'rc/advancedrc',
                );
 
-               if ( $wgUseRCPatrol ) {
+               if ( $user->useRCPatrol() ) {
                        $defaultPreferences['hidepatrolled'] = array(
                                'type' => 'toggle',
                                'section' => 'rc/advancedrc',
@@ -825,7 +846,6 @@ class Preferences {
        /**
         * @param $user User
         * @param $defaultPreferences
-        * @return void
         */
        static function watchlistPreferences( $user, &$defaultPreferences ) {
                global $wgUseRCPatrol, $wgEnableAPI;
@@ -920,6 +940,10 @@ class Preferences {
                }
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences Array
+        */
        static function searchPreferences( $user, &$defaultPreferences ) {
                global $wgContLang;
 
@@ -981,6 +1005,10 @@ class Preferences {
                );
        }
 
+       /**
+        * @param $user User
+        * @param $defaultPreferences Array
+        */
        static function miscPreferences( $user, &$defaultPreferences ) {
                ## Misc #####################################
                $defaultPreferences['diffonly'] = array(
@@ -1032,7 +1060,6 @@ class Preferences {
                        }
                }
                asort( $validSkinNames );
-               $sk = $user->getSkin();
 
                foreach ( $validSkinNames as $skinkey => $sn ) {
                        $linkTools = array();
@@ -1049,12 +1076,12 @@ 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, wfMsgHtml( 'prefs-custom-css' ) );
                        }
 
                        if ( $wgAllowUserJs ) {
                                $jsPage = Title::makeTitleSafe( NS_USER, $user->getName() . '/' . $skinkey . '.js' );
-                               $linkTools[] = $sk->link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
+                               $linkTools[] = Linker::link( $jsPage, wfMsgHtml( 'prefs-custom-js' ) );
                        }
 
                        $display = $sn . ' ' . wfMsg( 'parentheses', $wgLang->pipeList( $linkTools ) );
@@ -1064,6 +1091,9 @@ class Preferences {
                return $ret;
        }
 
+       /**
+        * @return array
+        */
        static function getDateOptions() {
                global $wgLang;
                $dateopts = $wgLang->getDatePreferences();
@@ -1095,6 +1125,9 @@ class Preferences {
                return $ret;
        }
 
+       /**
+        * @return array
+        */
        static function getImageSizes() {
                global $wgImageLimits;
 
@@ -1108,6 +1141,9 @@ class Preferences {
                return $ret;
        }
 
+       /**
+        * @return array
+        */
        static function getThumbSizes() {
                global $wgThumbLimits;
 
@@ -1121,6 +1157,11 @@ class Preferences {
                return $ret;
        }
 
+       /**
+        * @param $signature
+        * @param $alldata
+        * @return bool|string
+        */
        static function validateSignature( $signature, $alldata ) {
                global $wgParser, $wgMaxSigChars, $wgLang;
                if ( mb_strlen( $signature ) > $wgMaxSigChars ) {
@@ -1138,6 +1179,11 @@ class Preferences {
                }
        }
 
+       /**
+        * @param $signature string
+        * @param $alldata array
+        * @return string
+        */
        static function cleanSignature( $signature, $alldata ) {
                global $wgParser;
                if ( isset( $alldata['fancysig'] ) && $alldata['fancysig'] ) {
@@ -1150,6 +1196,11 @@ class Preferences {
                return $signature;
        }
 
+       /**
+        * @param $email
+        * @param $alldata
+        * @return bool|String
+        */
        static function validateEmail( $email, $alldata ) {
                if ( $email && !Sanitizer::validateEmail( $email ) ) {
                        return wfMsgExt( 'invalidemailaddress', 'parseinline' );
@@ -1162,9 +1213,15 @@ class Preferences {
                return true;
        }
 
-       static function getFormObject( $user, $formClass = 'PreferencesForm' ) {
+       /**
+        * @param $user User
+        * @param $context RequestContext
+        * @param $formClass string
+        * @return HtmlForm
+        */
+       static function getFormObject( $user, RequestContext $context, $formClass = 'PreferencesForm' ) {
                $formDescriptor = Preferences::getPreferences( $user );
-               $htmlForm = new $formClass( $formDescriptor, 'prefs' );
+               $htmlForm = new $formClass( $formDescriptor, $context, 'prefs' );
 
                $htmlForm->setId( 'mw-prefs-form' );
                $htmlForm->setSubmitText( wfMsg( 'saveprefs' ) );
@@ -1177,6 +1234,9 @@ class Preferences {
                return $htmlForm;
        }
 
+       /**
+        * @return array
+        */
        static function getTimezoneOptions() {
                $opt = array();
 
@@ -1185,7 +1245,7 @@ class Preferences {
                if ( $wgLocalTZoffset == date( 'Z' ) / 60 ) {
                        $server_tz_msg = wfMsg( 'timezoneuseserverdefault', $wgLocaltimezone );
                } else {
-                       $tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 );
+                       $tzstring = sprintf( '%+03d:%02d', floor( $wgLocalTZoffset / 60 ), abs( $wgLocalTZoffset ) % 60 );
                        $server_tz_msg = wfMsg( 'timezoneuseserverdefault', $tzstring );
                }
                $opt[$server_tz_msg] = "System|$wgLocalTZoffset";
@@ -1239,10 +1299,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] ) {
@@ -1268,8 +1338,13 @@ class Preferences {
                }
        }
 
+       /**
+        * @param $formData
+        * @param $entryPoint string
+        * @return bool|Status|string
+        */
        static function tryFormSubmit( $formData, $entryPoint = 'internal' ) {
-               global $wgUser, $wgEmailAuthentication, $wgEnableEmail;
+               global $wgUser;
 
                $result = true;
 
@@ -1287,34 +1362,6 @@ 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.
-                                       $type = $oldaddr != '' ? 'changed' : 'set';
-                                       $result = $wgUser->sendConfirmationMail( $type );
-                                       if ( !$result->isGood() ) {
-                                               return htmlspecialchars( $result->getWikiText( 'mailerror' ) );
-                                       } 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 ) ) {
@@ -1349,6 +1396,10 @@ class Preferences {
                return $result;
        }
 
+       /**
+        * @param $formData
+        * @return Status
+        */
        public static function tryUISubmit( $formData ) {
                $res = self::tryFormSubmit( $formData, 'ui' );
 
@@ -1370,6 +1421,46 @@ class Preferences {
                return Status::newGood();
        }
 
+       /*
+        * Try to set a user's email address.
+        * This does *not* try to validate the address.
+        * @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 );
+                               # But flag as "dirty" = unauthenticated
+                               $user->invalidateEmail();
+                               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';
+                               }
+                       } else {
+                               $user->setEmail( $newaddr );
+                       }
+                       if ( $oldaddr != $newaddr ) {
+                               wfRunHooks( 'PrefsEmailAudit', array( $user, $oldaddr, $newaddr ) );
+                       }
+               }
+
+               return array( true, $info );
+       }
+
        /**
         * @param $user User
         * @return array
@@ -1391,27 +1482,36 @@ class Preferences {
 
 /** Some tweaks to allow js prefs to work */
 class PreferencesForm extends HTMLForm {
+
+       /**
+        * @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, wfMsgHtml( 'restoreprefs' ) );
 
                $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.
@@ -1431,4 +1531,10 @@ class PreferencesForm extends HTMLForm {
 
                return $data;
        }
+       /**
+        * Get the whole body of the form.
+        */
+       function getBody() {
+               return $this->displaySection( $this->mFieldTree, '', 'mw-prefsection-' );
+       }
 }