From 0ec422d3036def0a1cff49696080c94daaaa92ed Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Mon, 22 Aug 2011 18:32:48 +0000 Subject: [PATCH] Use local context instead of global variables --- includes/Preferences.php | 5 +-- includes/specials/SpecialPreferences.php | 41 +++++++++++------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/includes/Preferences.php b/includes/Preferences.php index 0c8bf29161..c8d3b50863 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -1215,12 +1215,13 @@ class Preferences { /** * @param $user User + * @param $context RequestContext * @param $formClass string * @return HtmlForm */ - static function getFormObject( $user, $formClass = 'PreferencesForm' ) { + 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' ) ); diff --git a/includes/specials/SpecialPreferences.php b/includes/specials/SpecialPreferences.php index eeb7fd2e96..38ae2239e0 100644 --- a/includes/specials/SpecialPreferences.php +++ b/includes/specials/SpecialPreferences.php @@ -31,20 +31,19 @@ class SpecialPreferences extends SpecialPage { parent::__construct( 'Preferences' ); } - function execute( $par ) { - global $wgOut, $wgUser, $wgRequest; - + public function execute( $par ) { $this->setHeaders(); $this->outputHeader(); - $wgOut->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc. + $out = $this->getOutput(); + $out->disallowUserJs(); # Prevent hijacked user scripts from sniffing passwords etc. - if ( $wgUser->isAnon() ) { - $wgOut->showErrorPage( 'prefsnologin', 'prefsnologintext', array( $this->getTitle()->getPrefixedDBkey() ) ); + $user = $this->getUser(); + if ( $user->isAnon() ) { + $out->showErrorPage( 'prefsnologin', 'prefsnologintext', array( $this->getTitle()->getPrefixedDBkey() ) ); return; } if ( wfReadOnly() ) { - $wgOut->readOnlyPage(); - return; + throw new ReadOnlyError; } if ( $par == 'reset' ) { @@ -52,44 +51,42 @@ class SpecialPreferences extends SpecialPage { return; } - $wgOut->addModules( 'mediawiki.special.preferences' ); + $out->addModules( 'mediawiki.special.preferences' ); - if ( $wgRequest->getCheck( 'success' ) ) { - $wgOut->wrapWikiMsg( + if ( $this->getRequest()->getCheck( 'success' ) ) { + $out->wrapWikiMsg( "
\n$1\n
", 'savedprefs' ); } - $htmlForm = Preferences::getFormObject( $wgUser ); + $htmlForm = Preferences::getFormObject( $user, $this->getContext() ); $htmlForm->setSubmitCallback( array( 'Preferences', 'tryUISubmit' ) ); $htmlForm->show(); } - function showResetForm() { - global $wgOut; - - $wgOut->addWikiMsg( 'prefs-reset-intro' ); + private function showResetForm() { + $this->getOutput()->addWikiMsg( 'prefs-reset-intro' ); $htmlForm = new HTMLForm( array(), $this->getContext(), 'prefs-restore' ); $htmlForm->setSubmitText( wfMsg( 'restoreprefs' ) ); $htmlForm->setTitle( $this->getTitle( 'reset' ) ); - $htmlForm->setSubmitCallback( array( __CLASS__, 'submitReset' ) ); + $htmlForm->setSubmitCallback( array( $this, 'submitReset' ) ); $htmlForm->suppressReset(); $htmlForm->show(); } - static function submitReset( $formData ) { - global $wgUser, $wgOut; - $wgUser->resetOptions(); - $wgUser->saveSettings(); + public function submitReset( $formData ) { + $user = $this->getUser(); + $user->resetOptions(); + $user->saveSettings(); $url = SpecialPage::getTitleFor( 'Preferences' )->getFullURL( 'success' ); - $wgOut->redirect( $url ); + $this->getOutput()->redirect( $url ); return true; } -- 2.20.1