adding generic hook points to SpecialPreferences
authorDaniel Kinzler <daniel@users.mediawiki.org>
Mon, 30 Jul 2007 22:52:37 +0000 (22:52 +0000)
committerDaniel Kinzler <daniel@users.mediawiki.org>
Mon, 30 Jul 2007 22:52:37 +0000 (22:52 +0000)
docs/hooks.txt
includes/SpecialPreferences.php

index 95cea3d..55bca1e 100644 (file)
@@ -482,6 +482,10 @@ $query: query options passed to Title::getFullURL()
 $imagePage: ImagePage object ($this)
 $output: $wgOut
 
+'InitPreferencesForm': called at the end of PreferencesForm's constructor
+$form: the PreferencesForm
+$request: the web request to initialized from
+
 'InternalParseBeforeLinks': during Parser's internalParse method before links but
 after noinclude/includeonly/onlyinclude and other processing.
 &$this: Parser object
@@ -574,6 +578,20 @@ $form : PreferencesForm object
 &$obj: RawPage object
 &$text: The text that's going to be the output
 
+'RenderPreferencesForm': called at the end of PreferencesForm::mainPrefsForm
+$form: the PreferencesForm
+$out: output page to render to, probably $wgOut
+
+'ResetPreferences': called at the end of PreferencesForm::resetPrefs
+$form: the PreferencesForm
+$user: the User object to load preferences from
+
+'SavePreferences': called at the end of PreferencesForm::savePreferences; 
+                   returning false prevents the preferences from being saved.
+$form: the PreferencesForm
+$user: the User object to save preferences to
+$message: change this to set an error message (ignored if the hook does notreturn fals)
+
 'SearchUpdate': Prior to search update completion
 $id : Page id
 $namespace : Page namespace
index 50d9212..2a88117 100644 (file)
@@ -97,6 +97,8 @@ class PreferencesForm {
                if ( !preg_match( '/^[a-z\-]*$/', $this->mUserLanguage ) ) {
                        $this->mUserLanguage = 'nolanguage';
                }
+
+               wfRunHooks( "InitPreferencesForm", array( $this, $request ) );
        }
 
        function execute() {
@@ -298,9 +300,17 @@ class PreferencesForm {
                        $wgUser->setOption( $tname, $tvalue );
                }
                if (!$wgAuth->updateExternalDB($wgUser)) {
-                       $this->mainPrefsForm( wfMsg( 'externaldberror' ) );
+                       $this->mainPrefsForm( 'error', wfMsg( 'externaldberror' ) );
+                       return;
+               }
+
+               $msg = '';
+               if ( !wfRunHooks( "SavePreferences", array( $this, $wgUser, &$msg ) ) ) {
+                       print "(($msg))";
+                       $this->mainPrefsForm( 'error', $msg ); 
                        return;
                }
+
                $wgUser->setCookies();
                $wgUser->saveSettings();
 
@@ -395,6 +405,8 @@ class PreferencesForm {
                                $this->mSearchNs[$i] = $wgUser->getOption( 'searchNs'.$i );
                        }
                }
+
+               wfRunHooks( "ResetPreferences", array( $this, $wgUser ) );
        }
 
        /**
@@ -994,6 +1006,8 @@ class PreferencesForm {
                }
                $wgOut->addHTML( '</fieldset>' );
 
+               wfRunHooks( "RenderPreferencesForm", array( $this, $wgOut ) );
+
                $token = htmlspecialchars( $wgUser->editToken() );
                $skin = $wgUser->getSkin();
                $wgOut->addHTML( "