[MediaWiki-commits] [Gerrit] Simplified the setup code by combining some functions - change (mediawiki...OAuth)
CSteipp has submitted this change and it was merged. Change subject: Simplified the setup code by combining some functions .. Simplified the setup code by combining some functions Change-Id: I435cb3032f3b09cc209a3c36987105ebdfb6cd2b --- M OAuth.php M OAuth.setup.php M api/MWOAuthAPI.setup.php M frontend/MWOAuthUI.setup.php 4 files changed, 55 insertions(+), 85 deletions(-) Approvals: CSteipp: Verified; Looks good to me, approved jenkins-bot: Verified diff --git a/OAuth.php b/OAuth.php index faf1668..a0deb37 100644 --- a/OAuth.php +++ b/OAuth.php @@ -38,25 +38,14 @@ require( __DIR__ . '/OAuth.setup.php' ); MWOAuthSetup::defineSourcePaths( $wgAutoloadClasses, $wgExtensionMessagesFiles ); -# Define JS/CSS modules and file locations -MWOAuthUISetup::defineResourceModules( $wgResourceModules ); - -$wgLogTypes[] = 'mwoauthconsumer'; -# Log name and description as well as action handlers -MWOAuthUISetup::defineLogBasicDescription( $wgLogNames, $wgLogHeaders, $wgFilterLogTypes ); -MWOAuthUISetup::defineLogActionHandlers( $wgLogActions, $wgLogActionsHandlers ); - -# Basic hook handlers -MWOAuthSetup::defineHookHandlers( $wgHooks ); -# GUI-related hook handlers -MWOAuthUISetup::defineHookHandlers( $wgHooks ); -# API-related hook handlers -MWOAuthAPISetup::defineHookHandlers( $wgHooks ); +# Setup steps that does not depend on configuration +MWOAuthSetup::unconditionalSetup(); +MWOAuthUISetup::unconditionalSetup(); +MWOAuthAPISetup::unconditionalSetup(); # Actually register special pages and set default $wgMWOAuthCentralWiki $wgExtensionFunctions[] = function() { global $wgMWOAuthCentralWiki, $wgMWOAuthSharedUserIDs; - global $wgSpecialPages, $wgSpecialPageGroups; if ( $wgMWOAuthCentralWiki === false ) { // Treat each wiki as its own central wiki as there is no actual one @@ -65,5 +54,5 @@ // There is actually a central wiki, requiring global user IDs via hook $wgMWOAuthSharedUserIDs = true; } - MWOAuthUISetup::defineSpecialPages( $wgSpecialPages, $wgSpecialPageGroups ); + MWOAuthUISetup::conditionalSetup(); }; diff --git a/OAuth.setup.php b/OAuth.setup.php index a1b9795..bdc5f16 100644 --- a/OAuth.setup.php +++ b/OAuth.setup.php @@ -82,13 +82,15 @@ } /** -* @param array $hooks $wgHooks +* This function must NOT depend on any config vars +* * @return void */ - public static function defineHookHandlers( $hooks ) { - $hooks['LoadExtensionSchemaUpdates'][] = 'MWOAuthUpdaterHooks::addSchemaUpdates'; + public static function unconditionalSetup() { + global $wgHooks; - $hooks['UnitTestsList'][] = function( array $files ) { + $wgHooks['LoadExtensionSchemaUpdates'][] = 'MWOAuthUpdaterHooks::addSchemaUpdates'; + $wgHooks['UnitTestsList'][] = function( array $files ) { $directoryIterator = new RecursiveDirectoryIterator( __DIR__ . '/tests/' ); foreach ( new RecursiveIteratorIterator( $directoryIterator ) as $fileInfo ) { if ( substr( $fileInfo-getFilename(), -8 ) === 'Test.php' ) { diff --git a/api/MWOAuthAPI.setup.php b/api/MWOAuthAPI.setup.php index 5179a07..1e57e9a 100644 --- a/api/MWOAuthAPI.setup.php +++ b/api/MWOAuthAPI.setup.php @@ -4,6 +4,22 @@ */ class MWOAuthAPISetup { /** +* This function must NOT depend on any config vars +* +* @return void +*/ + public static function unconditionalSetup() { + global $wgHooks; + + $wgHooks['UserLoadFromSession'][] = __CLASS__ . '::onUserLoadFromSession'; + $wgHooks['UserLoadAfterLoadFromSession'][] = __CLASS__ . '::onUserLoadAfterLoadFromSession'; + $wgHooks['UserGetRights'][] = __CLASS__ . '::onUserGetRights'; + $wgHooks['UserIsEveryoneAllowed'][] = __CLASS__ . '::onUserIsEveryoneAllowed'; + $wgHooks['ApiCheckCanExecute'][] = __CLASS__ . '::onApiCheckCanExecute'; + $wgHooks['RecentChange_save'][] = __CLASS__ . '::onRecentChange_save'; + } + + /** * Create the appropriate type of exception to throw, based on MW_API * * @param string $msgKey Key for the error message @@ -52,20 +68,6 @@ throw self::makeException( 'mwoauth-invalid-authorization', $result-getMessage() ); } return $result; - } - - /** -* Register hooks handlers -* @param Array $hooks $wgHooks (assoc array of hooks and handlers) -* @return void -*/ - public static function defineHookHandlers( array $hooks ) { - $hooks['UserLoadFromSession'][] = __CLASS__ . '::onUserLoadFromSession'; -
[MediaWiki-commits] [Gerrit] Simplified the setup code by combining some functions - change (mediawiki...OAuth)
Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/78416 Change subject: Simplified the setup code by combining some functions .. Simplified the setup code by combining some functions Change-Id: I435cb3032f3b09cc209a3c36987105ebdfb6cd2b --- M OAuth.php M OAuth.setup.php M api/MWOAuthAPI.setup.php M frontend/MWOAuthUI.setup.php 4 files changed, 56 insertions(+), 84 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OAuth refs/changes/16/78416/1 diff --git a/OAuth.php b/OAuth.php index faf1668..a0deb37 100644 --- a/OAuth.php +++ b/OAuth.php @@ -38,25 +38,14 @@ require( __DIR__ . '/OAuth.setup.php' ); MWOAuthSetup::defineSourcePaths( $wgAutoloadClasses, $wgExtensionMessagesFiles ); -# Define JS/CSS modules and file locations -MWOAuthUISetup::defineResourceModules( $wgResourceModules ); - -$wgLogTypes[] = 'mwoauthconsumer'; -# Log name and description as well as action handlers -MWOAuthUISetup::defineLogBasicDescription( $wgLogNames, $wgLogHeaders, $wgFilterLogTypes ); -MWOAuthUISetup::defineLogActionHandlers( $wgLogActions, $wgLogActionsHandlers ); - -# Basic hook handlers -MWOAuthSetup::defineHookHandlers( $wgHooks ); -# GUI-related hook handlers -MWOAuthUISetup::defineHookHandlers( $wgHooks ); -# API-related hook handlers -MWOAuthAPISetup::defineHookHandlers( $wgHooks ); +# Setup steps that does not depend on configuration +MWOAuthSetup::unconditionalSetup(); +MWOAuthUISetup::unconditionalSetup(); +MWOAuthAPISetup::unconditionalSetup(); # Actually register special pages and set default $wgMWOAuthCentralWiki $wgExtensionFunctions[] = function() { global $wgMWOAuthCentralWiki, $wgMWOAuthSharedUserIDs; - global $wgSpecialPages, $wgSpecialPageGroups; if ( $wgMWOAuthCentralWiki === false ) { // Treat each wiki as its own central wiki as there is no actual one @@ -65,5 +54,5 @@ // There is actually a central wiki, requiring global user IDs via hook $wgMWOAuthSharedUserIDs = true; } - MWOAuthUISetup::defineSpecialPages( $wgSpecialPages, $wgSpecialPageGroups ); + MWOAuthUISetup::conditionalSetup(); }; diff --git a/OAuth.setup.php b/OAuth.setup.php index f2540d5..a17005c 100644 --- a/OAuth.setup.php +++ b/OAuth.setup.php @@ -82,10 +82,13 @@ } /** -* @param array $hooks $wgHooks +* This function must NOT depend on any config vars +* * @return void */ - public static function defineHookHandlers( $hooks ) { - $hooks['LoadExtensionSchemaUpdates'][] = 'MWOAuthUpdaterHooks::addSchemaUpdates'; + public static function unconditionalSetup() { + global $wgHooks; + + $wgHooks['LoadExtensionSchemaUpdates'][] = 'MWOAuthUpdaterHooks::addSchemaUpdates'; } } diff --git a/api/MWOAuthAPI.setup.php b/api/MWOAuthAPI.setup.php index 111f27d..4d0fd52 100644 --- a/api/MWOAuthAPI.setup.php +++ b/api/MWOAuthAPI.setup.php @@ -4,6 +4,22 @@ */ class MWOAuthAPISetup { /** +* This function must NOT depend on any config vars +* +* @return void +*/ + public static function unconditionalSetup() { + global $wgHooks; + + $wgHooks['UserLoadFromSession'][] = __CLASS__ . '::onUserLoadFromSession'; + $wgHooks['UserLoadAfterLoadFromSession'][] = __CLASS__ . '::onUserLoadAfterLoadFromSession'; + $wgHooks['UserGetRights'][] = __CLASS__ . '::onUserGetRights'; + $wgHooks['UserIsEveryoneAllowed'][] = __CLASS__ . '::onUserIsEveryoneAllowed'; + $wgHooks['ApiCheckCanExecute'][] = __CLASS__ . '::onApiCheckCanExecute'; + $wgHooks['RecentChange_save'][] = __CLASS__ . '::onRecentChange_save'; + } + + /** * Create the appropriate type of exception to throw, based on MW_API * * @param string $msgKey Key for the error message @@ -52,20 +68,6 @@ throw self::makeException( 'mwoauth-invalid-authorization', $result-getMessage() ); } return $result; - } - - /** -* Register hooks handlers -* @param Array $hooks $wgHooks (assoc array of hooks and handlers) -* @return void -*/ - public static function defineHookHandlers( array $hooks ) { - $hooks['UserLoadFromSession'][] = __CLASS__ . '::onUserLoadFromSession'; - $hooks['UserLoadAfterLoadFromSession'][] = __CLASS__ . '::onUserLoadAfterLoadFromSession'; - $hooks['UserGetRights'][] = __CLASS__ . '::onUserGetRights'; - $hooks['UserIsEveryoneAllowed'][] = __CLASS__ . '::onUserIsEveryoneAllowed'; - $hooks['ApiCheckCanExecute'][] = __CLASS__ . '::onApiCheckCanExecute'; -