WARNING: HUGE COMMIT
[lhc/web/wiklou.git] / includes / SpecialPreferences.php
index 49c562d..9f01ae2 100644 (file)
@@ -1,7 +1,8 @@
 <?php
 /**
  * Hold things related to displaying and saving user preferences.
- * @addtogroup SpecialPage
+ * @file
+ * @ingroup SpecialPage
  */
 
 /**
@@ -17,14 +18,14 @@ function wfSpecialPreferences() {
 /**
  * Preferences form handling
  * This object will show the preferences form and can save it as well.
- * @addtogroup SpecialPage
+ * @ingroup SpecialPage
  */
 class PreferencesForm {
        var $mQuickbar, $mOldpass, $mNewpass, $mRetypePass, $mStubs;
        var $mRows, $mCols, $mSkin, $mMath, $mDate, $mUserEmail, $mEmailFlag, $mNick;
        var $mUserLanguage, $mUserVariant;
        var $mSearch, $mRecent, $mRecentDays, $mHourDiff, $mSearchLines, $mSearchChars, $mAction;
-       var $mReset, $mPosted, $mToggles, $mSearchNs, $mRealName, $mImageSize;
+       var $mReset, $mPosted, $mToggles, $mUseAjaxSearch, $mSearchNs, $mRealName, $mImageSize;
        var $mUnderline, $mWatchlistEdits;
 
        /**
@@ -65,6 +66,8 @@ class PreferencesForm {
                $this->mSuccess = $request->getCheck( 'success' );
                $this->mWatchlistDays = $request->getVal( 'wpWatchlistDays' );
                $this->mWatchlistEdits = $request->getVal( 'wpWatchlistEdits' );
+               $this->mUseAjaxSearch = $request->getCheck( 'wpUseAjaxSearch' );
+               $this->mDisableMWSuggest = $request->getCheck( 'wpDisableMWSuggest' );
 
                $this->mSaveprefs = $request->getCheck( 'wpSaveprefs' ) &&
                        $this->mPosted &&
@@ -97,6 +100,8 @@ class PreferencesForm {
                if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
                        $this->mUserLanguage = 'nolanguage';
                }
+
+               wfRunHooks( 'InitPreferencesForm', array( $this, $request ) );
        }
 
        function execute() {
@@ -159,7 +164,7 @@ class PreferencesForm {
                global $wgLang, $wgContLang;
                if ( $val !== false && (
                        in_array( $val, (array)$wgLang->getDatePreferences() ) ||
-                       in_array( $val, (array)$wgContLang->getDatePreferences() ) ) ) 
+                       in_array( $val, (array)$wgContLang->getDatePreferences() ) ) )
                {
                        return $val;
                } else {
@@ -205,34 +210,35 @@ class PreferencesForm {
        function savePreferences() {
                global $wgUser, $wgOut, $wgParser;
                global $wgEnableUserEmail, $wgEnableEmail;
-               global $wgEmailAuthentication;
-               global $wgAuth;
+               global $wgEmailAuthentication, $wgRCMaxAge;
+               global $wgAuth, $wgEmailConfirmToEdit;
 
 
                if ( '' != $this->mNewpass && $wgAuth->allowPasswordChange() ) {
                        if ( $this->mNewpass != $this->mRetypePass ) {
-                               wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'badretype' ) );
+                               wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass, 'badretype' ) );
                                $this->mainPrefsForm( 'error', wfMsg( 'badretype' ) );
                                return;
                        }
 
                        if (!$wgUser->checkPassword( $this->mOldpass )) {
-                               wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'wrongpassword' ) );
+                               wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass, 'wrongpassword' ) );
                                $this->mainPrefsForm( 'error', wfMsg( 'wrongpassword' ) );
                                return;
                        }
-                       
+
                        try {
                                $wgUser->setPassword( $this->mNewpass );
-                               wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'success' ) );
+                               wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass, 'success' ) );
                                $this->mNewpass = $this->mOldpass = $this->mRetypePass = '';
                        } catch( PasswordError $e ) {
-                               wfRunHooks( "PrefsPasswordAudit", array( $wgUser, $this->mNewpass, 'error' ) );
+                               wfRunHooks( 'PrefsPasswordAudit', array( $wgUser, $this->mNewpass, 'error' ) );
                                $this->mainPrefsForm( 'error', $e->getMessage() );
                                return;
                        }
                }
                $wgUser->setRealName( $this->mRealName );
+               $oldOptions = $wgUser->mOptions;
 
                if( $wgUser->getOption( 'language' ) !== $this->mUserLanguage ) {
                        $needRedirect = true;
@@ -242,13 +248,13 @@ class PreferencesForm {
 
                # Validate the signature and clean it up as needed
                global $wgMaxSigChars;
-               if( strlen( $this->mNick ) > $wgMaxSigChars ) {
+               if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
                        global $wgLang;
                        $this->mainPrefsForm( 'error',
                                wfMsg( 'badsiglength', $wgLang->formatNum( $wgMaxSigChars ) ) );
                        return;
                } elseif( $this->mToggles['fancysig'] ) {
-                       if( Parser::validateSig( $this->mNick ) !== false ) {
+                       if( $wgParser->validateSig( $this->mNick ) !== false ) {
                                $this->mNick = $wgParser->cleanSig( $this->mNick );
                        } else {
                                $this->mainPrefsForm( 'error', wfMsg( 'badsig' ) );
@@ -273,7 +279,7 @@ class PreferencesForm {
                $wgUser->setOption( 'contextlines', $this->validateIntOrNull( $this->mSearchLines ) );
                $wgUser->setOption( 'contextchars', $this->validateIntOrNull( $this->mSearchChars ) );
                $wgUser->setOption( 'rclimit', $this->validateIntOrNull( $this->mRecent ) );
-               $wgUser->setOption( 'rcdays', $this->validateInt( $this->mRecentDays, 1, 7 ) );
+               $wgUser->setOption( 'rcdays', $this->validateInt($this->mRecentDays, 1, ceil($wgRCMaxAge / (3600*24))));
                $wgUser->setOption( 'wllimit', $this->validateIntOrNull( $this->mWatchlistEdits, 0, 1000 ) );
                $wgUser->setOption( 'rows', $this->validateInt( $this->mRows, 4, 1000 ) );
                $wgUser->setOption( 'cols', $this->validateInt( $this->mCols, 4, 1000 ) );
@@ -283,6 +289,8 @@ class PreferencesForm {
                $wgUser->setOption( 'thumbsize', $this->mThumbSize );
                $wgUser->setOption( 'underline', $this->validateInt($this->mUnderline, 0, 2) );
                $wgUser->setOption( 'watchlistdays', $this->validateFloat( $this->mWatchlistDays, 0, 7 ) );
+               $wgUser->setOption( 'ajaxsearch', $this->mUseAjaxSearch );
+               $wgUser->setOption( 'disablesuggest', $this->mDisableMWSuggest );
 
                # Set search namespace options
                foreach( $this->mSearchNs as $i => $value ) {
@@ -297,12 +305,6 @@ class PreferencesForm {
                foreach ( $this->mToggles as $tname => $tvalue ) {
                        $wgUser->setOption( $tname, $tvalue );
                }
-               if (!$wgAuth->updateExternalDB($wgUser)) {
-                       $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
-                       return;
-               }
-               $wgUser->setCookies();
-               $wgUser->saveSettings();
 
                $error = false;
                if( $wgEnableEmail ) {
@@ -311,9 +313,10 @@ class PreferencesForm {
                        if( ($newadr != '') && ($newadr != $oldadr) ) {
                                # the user has supplied a new email address on the login page
                                if( $wgUser->isValidEmailAddr( $newadr ) ) {
-                                       $wgUser->mEmail = $newadr; # new behaviour: set this new emailaddr from login-page into user database record
-                                       $wgUser->mEmailAuthenticated = null; # but flag as "dirty" = unauthenticated
-                                       $wgUser->saveSettings();
+                                       # new behaviour: set this new emailaddr from login-page into user database record
+                                       $wgUser->setEmail( $newadr );
+                                       # 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.
@@ -328,22 +331,38 @@ class PreferencesForm {
                                        $error = wfMsg( 'invalidemailaddress' );
                                }
                        } else {
+                               if( $wgEmailConfirmToEdit && empty( $newadr ) ) {
+                                       $this->mainPrefsForm( 'error', wfMsg( 'noemailtitle' ) );
+                                       return;
+                               }
                                $wgUser->setEmail( $this->mUserEmail );
-                               $wgUser->setCookies();
-                               $wgUser->saveSettings();
                        }
                        if( $oldadr != $newadr ) {
-                               wfRunHooks( "PrefsEmailAudit", array( $wgUser, $oldadr, $newadr ) );
+                               wfRunHooks( 'PrefsEmailAudit', array( $wgUser, $oldadr, $newadr ) );
                        }
                }
 
+               if( !$wgAuth->updateExternalDB( $wgUser ) ){
+                       $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
+                       return;
+               }
+
+               $msg = '';
+               if ( !wfRunHooks( 'SavePreferences', array( $this, $wgUser, &$msg, $oldOptions ) ) ) {
+                       $this->mainPrefsForm( 'error', $msg );
+                       return;
+               }
+
+               $wgUser->setCookies();
+               $wgUser->saveSettings();
+
                if( $needRedirect && $error === false ) {
-                       $title =& SpecialPage::getTitleFor( "Preferences" );
-                       $wgOut->redirect($title->getFullURL('success'));
+                       $title = SpecialPage::getTitleFor( 'Preferences' );
+                       $wgOut->redirect( $title->getFullURL( 'success' ) );
                        return;
                }
 
-               $wgOut->setParserOptions( ParserOptions::newFromUser( $wgUser ) );
+               $wgOut->parserOptions( ParserOptions::newFromUser( $wgUser ) );
                $this->mainPrefsForm( $error === false ? 'success' : 'error', $error);
        }
 
@@ -383,6 +402,8 @@ class PreferencesForm {
                $this->mWatchlistEdits = $wgUser->getOption( 'wllimit' );
                $this->mUnderline = $wgUser->getOption( 'underline' );
                $this->mWatchlistDays = $wgUser->getOption( 'watchlistdays' );
+               $this->mUseAjaxSearch = $wgUser->getBoolOption( 'ajaxsearch' );
+               $this->mDisableMWSuggest = $wgUser->getBoolOption( 'disablesuggest' );
 
                $togs = User::getToggles();
                foreach ( $togs as $tname ) {
@@ -395,6 +416,8 @@ class PreferencesForm {
                                $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
                        }
                }
+
+               wfRunHooks( 'ResetPreferences', array( $this, $wgUser ) );
        }
 
        /**
@@ -452,7 +475,7 @@ class PreferencesForm {
        }
 
        function addRow($td1, $td2) {
-               return "<tr><td align='right'>$td1</td><td align='left'>$td2</td></tr>";
+               return "<tr><td class='mw-label'>$td1</td><td class='mw-input'>$td2</td></tr>";
        }
 
        /**
@@ -484,7 +507,7 @@ class PreferencesForm {
                }
 
                return Xml::tags( 'tr', null, $td1 . $td2 ). $td3 . "\n";
-       
+
        }
 
        /**
@@ -498,19 +521,21 @@ class PreferencesForm {
                global $wgRCShowWatchingUsers, $wgEnotifRevealEditorAddress;
                global $wgEnableEmail, $wgEnableUserEmail, $wgEmailAuthentication;
                global $wgContLanguageCode, $wgDefaultSkin, $wgSkipSkins, $wgAuth;
+               global $wgEmailConfirmToEdit, $wgAjaxSearch, $wgEnableMWSuggest;
 
                $wgOut->setPageTitle( wfMsg( 'preferences' ) );
                $wgOut->setArticleRelated( false );
                $wgOut->setRobotpolicy( 'noindex,nofollow' );
+               $wgOut->addScriptFile( 'prefs.js' );
 
                $wgOut->disallowUserJs();  # Prevent hijacked user scripts from sniffing passwords etc.
 
                if ( $this->mSuccess || 'success' == $status ) {
-                       $wgOut->addWikitext( '<div class="successbox"><strong>'. wfMsg( 'savedprefs' ) . '</strong></div>' );
+                       $wgOut->wrapWikiMsg( '<div class="successbox"><strong>$1</strong></div>', 'savedprefs' );
                } else  if ( 'error' == $status ) {
-                       $wgOut->addWikitext( '<div class="errorbox"><strong>' . $message  . '</strong></div>' );
+                       $wgOut->addWikiText( '<div class="errorbox"><strong>' . $message  . '</strong></div>' );
                } else if ( '' != $status ) {
-                       $wgOut->addWikitext( $message . "\n----" );
+                       $wgOut->addWikiText( $message . "\n----" );
                }
 
                $qbs = $wgLang->getQuickbarSettings();
@@ -546,7 +571,7 @@ class PreferencesForm {
                                $skin = $wgUser->getSkin();
                                $emailauthenticated = wfMsg('emailnotauthenticated').'<br />' .
                                        $skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Confirmemail' ),
-                                               wfMsg( 'emailconfirmlink' ) );
+                                               wfMsg( 'emailconfirmlink' ) ) . '<br />';
                        }
                } else {
                        $emailauthenticated = '';
@@ -554,7 +579,7 @@ class PreferencesForm {
                }
 
                if ($this->mUserEmail == '') {
-                       $emailauthenticated = wfMsg( 'noemailprefs' );
+                       $emailauthenticated = wfMsg( 'noemailprefs' ) . '<br />';
                }
 
                $ps = $this->namespacesCheckboxes();
@@ -580,7 +605,11 @@ class PreferencesForm {
 
                $userInformationHtml =
                        $this->tableRow( wfMsgHtml( 'username' ), htmlspecialchars( $wgUser->getName() ) ) .
-                       $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getID() ) );
+                       $this->tableRow( wfMsgHtml( 'uid' ), htmlspecialchars( $wgUser->getID() ) ) .
+                       $this->tableRow(
+                               wfMsgHtml( 'prefs-edits' ),
+                               $wgLang->formatNum( User::edits( $wgUser->getId() ) )
+                       );
 
                if( wfRunHooks( 'PreferencesUserInformationPanel', array( $this, &$userInformationHtml ) ) ) {
                        $wgOut->addHtml( $userInformationHtml );
@@ -603,14 +632,14 @@ class PreferencesForm {
                                        Xml::label( wfMsg('youremail'), 'wpUserEmail' ),
                                        Xml::input( 'wpUserEmail', 25, $this->mUserEmail, array( 'id' => 'wpUserEmail' ) ),
                                        Xml::tags('div', array( 'class' => 'prefsectiontip' ),
-                                               wfMsgExt( 'prefs-help-email', 'parseinline' )
+                                               wfMsgExt( $wgEmailConfirmToEdit ? 'prefs-help-email-required' : 'prefs-help-email', 'parseinline' )
                                        )
                                )
                        );
                }
 
                global $wgParser, $wgMaxSigChars;
-               if( strlen( $this->mNick ) > $wgMaxSigChars ) {
+               if( mb_strlen( $this->mNick ) > $wgMaxSigChars ) {
                        $invalidSig = $this->tableRow(
                                '&nbsp;',
                                Xml::element( 'span', array( 'class' => 'error' ),
@@ -632,10 +661,10 @@ class PreferencesForm {
                                Xml::input( 'wpNick', 25, $this->mNick,
                                        array(
                                                'id' => 'wpNick',
-                                               // Note: $wgMaxSigChars is currently enforced in UTF-8 bytes,
-                                               // but 'maxlength' attribute is enforced in characters.
-                                               // It's still possible to put in an overlong string
-                                               // 'legitimately' by typing non-ASCII chars.
+                                               // Note: $wgMaxSigChars is enforced in Unicode characters,
+                                               // both on the backend and now in the browser.
+                                               // Badly-behaved requests may still try to submit
+                                               // an overlong string, however.
                                                'maxlength' => $wgMaxSigChars ) )
                        ) .
                        $invalidSig .
@@ -681,7 +710,7 @@ class PreferencesForm {
                }
 
                # Password
-               if( $wgAuth->allowPasswordChange() ) {  
+               if( $wgAuth->allowPasswordChange() ) {
                        $wgOut->addHTML(
                                $this->tableRow( Xml::element( 'h2', null, wfMsg( 'changepassword' ) ) ) .
                                $this->tableRow(
@@ -710,10 +739,13 @@ class PreferencesForm {
 
                        $moreEmail = '';
                        if ($wgEnableUserEmail) {
+                               // fixme -- the "allowemail" pseudotoggle is a hacked-together
+                               // inversion for the "disableemail" preference.
                                $emf = wfMsg( 'allowemail' );
                                $disabled = $disableEmailPrefs ? ' disabled="disabled"' : '';
                                $moreEmail =
-                               "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>";
+                                       "<input type='checkbox' $emfc $disabled value='1' name='wpEmailFlag' id='wpEmailFlag' /> <label for='wpEmailFlag'>$emf</label>" .
+                                       $this->getToggle( 'ccmeonemails', '', $disableEmailPrefs );
                        }
 
 
@@ -725,8 +757,7 @@ class PreferencesForm {
                                        $enotifwatchlistpages.
                                        $enotifusertalkpages.
                                        $enotifminoredits.
-                                       $moreEmail.
-                                       $this->getToggle( 'ccmeonemails' )
+                                       $moreEmail
                                )
                        );
                }
@@ -843,40 +874,62 @@ class PreferencesForm {
                # Date/Time
                #
 
-               $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'datetime' ) . "</legend>\n" );
+               $wgOut->addHTML(
+                       Xml::openElement( 'fieldset' ) .
+                       Xml::element( 'legend', null, wfMsg( 'datetime' ) ) . "\n"
+               );
 
                if ($dateopts) {
-                       $wgOut->addHTML( "<fieldset>\n<legend>" . wfMsg( 'dateformat' ) . "</legend>\n" );
+                       $wgOut->addHTML(
+                               Xml::openElement( 'fieldset' ) .
+                               Xml::element( 'legend', null, wfMsg( 'dateformat' ) ) . "\n"
+                       );
                        $idCnt = 0;
                        $epoch = '20010115161234'; # Wikipedia day
                        foreach( $dateopts as $key ) {
                                if( $key == 'default' ) {
-                                       $formatted = wfMsgHtml( 'datedefault' );
+                                       $formatted = wfMsg( 'datedefault' );
                                } else {
-                                       $formatted = htmlspecialchars( $wgLang->timeanddate( $epoch, false, $key ) );
+                                       $formatted = $wgLang->timeanddate( $epoch, false, $key );
                                }
-                               ($key == $this->mDate) ? $checked = ' checked="checked"' : $checked = '';
-                               $wgOut->addHTML( "<div><input type='radio' name=\"wpDate\" id=\"wpDate$idCnt\" ".
-                                       "value=\"$key\"$checked /> <label for=\"wpDate$idCnt\">$formatted</label></div>\n" );
+                               $wgOut->addHTML(
+                                       Xml::tags( 'div', null,
+                                               Xml::radioLabel( $formatted, 'wpDate', $key, "wpDate$idCnt", $key == $this->mDate )
+                                       ) . "\n"
+                               );
                                $idCnt++;
                        }
-                       $wgOut->addHTML( "</fieldset>\n" );
+                       $wgOut->addHTML( Xml::closeElement( 'fieldset' ) . "\n" );
                }
 
                $nowlocal = $wgLang->time( $now = wfTimestampNow(), true );
                $nowserver = $wgLang->time( $now, false );
 
-               $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'timezonelegend' ). '</legend><table>' .
+               $wgOut->addHTML(
+                       Xml::openElement( 'fieldset' ) .
+                       Xml::element( 'legend', null, wfMsg( 'timezonelegend' ) ) .
+                       Xml::openElement( 'table' ) .
                        $this->addRow( wfMsg( 'servertime' ), $nowserver ) .
                        $this->addRow( wfMsg( 'localtime' ), $nowlocal ) .
                        $this->addRow(
-                               '<label for="wpHourDiff">' . wfMsg( 'timezoneoffset' ) . '</label>',
-                               "<input type='text' name='wpHourDiff' id='wpHourDiff' value=\"" . htmlspecialchars( $this->mHourDiff ) . "\" size='6' />"
-                       ) . "<tr><td colspan='2'>
-                               <input type='button' value=\"" . wfMsg( 'guesstimezone' ) ."\"
-                               onclick='javascript:guessTimezone()' id='guesstimezonebutton' style='display:none;' />
-                               </td></tr></table><div class='prefsectiontip'>ยน" .  wfMsg( 'timezonetext' ) . "</div></fieldset>
-               </fieldset>\n\n" );
+                               Xml::label( wfMsg( 'timezoneoffset' ), 'wpHourDiff'  ),
+                               Xml::input( 'wpHourDiff', 6, $this->mHourDiff, array( 'id' => 'wpHourDiff' ) ) ) .
+                       "<tr>
+                               <td></td>
+                               <td class='mw-submit'>" .
+                                       Xml::element( 'input',
+                                               array( 'type' => 'button',
+                                                       'value' => wfMsg( 'guesstimezone' ),
+                                                       'onclick' => 'javascript:guessTimezone()',
+                                                       'id' => 'guesstimezonebutton',
+                                                       'style' => 'display:none;' ) ) .
+                               "</td>
+                       </tr>" .
+                       Xml::closeElement( 'table' ) .
+                       Xml::tags( 'div', array( 'class' => 'prefsectiontip' ), wfMsgExt( 'timezonetext', 'parseinline' ) ).
+                       Xml::closeElement( 'fieldset' ) .
+                       Xml::closeElement( 'fieldset' ) . "\n\n"
+               );
 
                # Editing
                #
@@ -905,18 +958,18 @@ class PreferencesForm {
 
                # Recent changes
                $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-rc' ) . '</legend>' );
-               
+
                $rc  = '<table><tr>';
                $rc .= '<td>' . Xml::label( wfMsg( 'recentchangesdays' ), 'wpRecentDays' ) . '</td>';
-               $rc .= '<td>' . Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . '</td>';         
+               $rc .= '<td>' . Xml::input( 'wpRecentDays', 3, $this->mRecentDays, array( 'id' => 'wpRecentDays' ) ) . '</td>';
                $rc .= '</tr><tr>';
                $rc .= '<td>' . Xml::label( wfMsg( 'recentchangescount' ), 'wpRecent' ) . '</td>';
                $rc .= '<td>' . Xml::input( 'wpRecent', 3, $this->mRecent, array( 'id' => 'wpRecent' ) ) . '</td>';
                $rc .= '</tr></table>';
                $wgOut->addHtml( $rc );
-               
+
                $wgOut->addHtml( '<br />' );
-               
+
                $toggles[] = 'hideminor';
                if( $wgRCShowWatchingUsers )
                        $toggles[] = 'shownumberswatching';
@@ -927,7 +980,7 @@ class PreferencesForm {
 
                # Watchlist
                $wgOut->addHtml( '<fieldset><legend>' . wfMsgHtml( 'prefs-watchlist' ) . '</legend>' );
-               
+
                $wgOut->addHtml( wfInputLabel( wfMsg( 'prefs-watchlist-days' ), 'wpWatchlistDays', 'wpWatchlistDays', 3, $this->mWatchlistDays ) );
                $wgOut->addHtml( '<br /><br />' );
 
@@ -936,7 +989,7 @@ class PreferencesForm {
                $wgOut->addHtml( '<br /><br />' );
 
                $wgOut->addHtml( $this->getToggles( array( 'watchlisthideown', 'watchlisthidebots', 'watchlisthideminor' ) ) );
-               
+
                if( $wgUser->isAllowed( 'createpage' ) || $wgUser->isAllowed( 'createtalk' ) )
                        $wgOut->addHtml( $this->getToggle( 'watchcreations' ) );
                foreach( array( 'edit' => 'watchdefault', 'move' => 'watchmoves', 'delete' => 'watchdeletion' ) as $action => $toggle ) {
@@ -947,24 +1000,45 @@ class PreferencesForm {
                $this->mUsedToggles['watchdefault'] = true;
                $this->mUsedToggles['watchmoves'] = true;
                $this->mUsedToggles['watchdeletion'] = true;
-               
+
                $wgOut->addHtml( '</fieldset>' );
 
                # Search
-               $wgOut->addHTML( '<fieldset><legend>' . wfMsg( 'searchresultshead' ) . '</legend><table>' .
+               $ajaxsearch = $wgAjaxSearch ?
+                       $this->addRow(
+                               Xml::label( wfMsg( 'useajaxsearch' ), 'wpUseAjaxSearch' ),
+                               Xml::check( 'wpUseAjaxSearch', $this->mUseAjaxSearch, array( 'id' => 'wpUseAjaxSearch' ) )
+                       ) : '';
+               $mwsuggest = $wgEnableMWSuggest ?
+                       $this->addRow(
+                               Xml::label( wfMsg( 'mwsuggest-disable' ), 'wpDisableMWSuggest' ),
+                               Xml::check( 'wpDisableMWSuggest', $this->mDisableMWSuggest, array( 'id' => 'wpDisableMWSuggest' ) )
+                       ) : '';
+               $wgOut->addHTML(
+                       Xml::openElement( 'fieldset' ) .
+                       Xml::element( 'legend', null, wfMsg( 'searchresultshead' ) ) .
+                       Xml::openElement( 'table' ) .
+                       $ajaxsearch .
                        $this->addRow(
-                               wfLabel( wfMsg( 'resultsperpage' ), 'wpSearch' ),
-                               wfInput( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
+                               Xml::label( wfMsg( 'resultsperpage' ), 'wpSearch' ),
+                               Xml::input( 'wpSearch', 4, $this->mSearch, array( 'id' => 'wpSearch' ) )
                        ) .
                        $this->addRow(
-                               wfLabel( wfMsg( 'contextlines' ), 'wpSearchLines' ),
-                               wfInput( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
+                               Xml::label( wfMsg( 'contextlines' ), 'wpSearchLines' ),
+                               Xml::input( 'wpSearchLines', 4, $this->mSearchLines, array( 'id' => 'wpSearchLines' ) )
                        ) .
                        $this->addRow(
-                               wfLabel( wfMsg( 'contextchars' ), 'wpSearchChars' ),
-                               wfInput( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
+                               Xml::label( wfMsg( 'contextchars' ), 'wpSearchChars' ),
+                               Xml::input( 'wpSearchChars', 4, $this->mSearchChars, array( 'id' => 'wpSearchChars' ) )
                        ) .
-               "</table><fieldset><legend>" . wfMsg( 'defaultns' ) . "</legend>$ps</fieldset></fieldset>" );
+                       $mwsuggest .
+                       Xml::closeElement( 'table' ) .
+                       Xml::openElement( 'fieldset' ) .
+                       Xml::element( 'legend', null, wfMsg( 'defaultns' ) ) .
+                       $ps .
+                       Xml::closeElement( 'fieldset' ) .
+                       Xml::closeElement( 'fieldset' )
+               );
 
                # Misc
                #
@@ -994,6 +1068,8 @@ class PreferencesForm {
                }
                $wgOut->addHTML( '</fieldset>' );
 
+               wfRunHooks( 'RenderPreferencesForm', array( $this, $wgOut ) );
+
                $token = htmlspecialchars( $wgUser->editToken() );
                $skin = $wgUser->getSkin();
                $wgOut->addHTML( "
@@ -1011,7 +1087,5 @@ class PreferencesForm {
                $wgOut->addHtml( Xml::tags( 'div', array( 'class' => "prefcache" ),
                        wfMsgExt( 'clearyourcache', 'parseinline' ) )
                );
-
        }
 }
-?>