From 04a321cb268c82d9cd26a7e4b9a211392892ed27 Mon Sep 17 00:00:00 2001 From: Daniel Kinzler Date: Mon, 30 Jul 2007 22:52:37 +0000 Subject: [PATCH] adding generic hook points to SpecialPreferences --- docs/hooks.txt | 18 ++++++++++++++++++ includes/SpecialPreferences.php | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/hooks.txt b/docs/hooks.txt index 95cea3dc83..55bca1ed85 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/SpecialPreferences.php b/includes/SpecialPreferences.php index 50d92125f5..2a88117ad9 100644 --- a/includes/SpecialPreferences.php +++ b/includes/SpecialPreferences.php @@ -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( '' ); + wfRunHooks( "RenderPreferencesForm", array( $this, $wgOut ) ); + $token = htmlspecialchars( $wgUser->editToken() ); $skin = $wgUser->getSkin(); $wgOut->addHTML( " -- 2.20.1