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';
- $hooks['RecentChange_save'][] = __CLASS__ .
'::onRecentChange_save';
}
/**
diff --git a/frontend/MWOAuthUI.setup.php b/frontend/MWOAuthUI.setup.php
index e0e1969..c3668b9 100644
--- a/frontend/MWOAuthUI.setup.php
+++ b/frontend/MWOAuthUI.setup.php
@@ -4,62 +4,40 @@
*/
class MWOAuthUISetup {
/**
- * @param array $pages $wgSpecialPages (list of special pages)
- * @param array $groups $wgSpecialPageGroups (assoc array of special
page groups)
+ * This function must NOT depend on any config vars
+ *
* @return void
*/
- public static function defineSpecialPages( array &$pages, array
&$groups ) {
- // Pages available on all wikis
- $pages['MWOAuth'] = 'SpecialMWOAuth';
- // Pages specific to the central OAuth management wiki
+ public static function unconditionalSetup() {
+ global $wgHooks;
+
+ $wgHooks['GetPreferences'][] =
'MWOAuthUIHooks::onGetPreferences';
+ }
+
+ /**
+ * @return void
+ */
+ public static function conditionalSetup() {
+ global $wgSpecialPages, $wgSpecialPageGroups;
+ global $wgLogTypes, $wgLogNames, $wgLogHeaders,
$wgLogActionsHandlers;
+ global $wgResourceModules;
+
+ $wgSpecialPages['MWOAuth'] = 'SpecialMWOAuth';
+
if ( MWOAuthUtils::isCentralWiki() ) {
- $pages['MWOAuthConsumerRegistration'] =
'SpecialMWOAuthConsumerRegistration';
- $groups['MWOAuthConsumerRegistration'] = 'users';
- $pages['MWOAuthManageConsumers'] =
'SpecialMWOAuthManageConsumers';
- $groups['MWOAuthManageConsumers'] = 'users';
- $pages['MWOAuthManageMyGrants'] =
'SpecialMWOAuthManageMyGrants';
+ $wgSpecialPages['MWOAuthConsumerRegistration'] =
'SpecialMWOAuthConsumerRegistration';
+ $wgSpecialPageGroups['MWOAuthConsumerRegistration'] =
'users';
+ $wgSpecialPages['MWOAuthManageConsumers'] =
'SpecialMWOAuthManageConsumers';
+ $wgSpecialPageGroups['MWOAuthManageConsumers'] =
'users';
+ $wgSpecialPages['MWOAuthManageMyGrants'] =
'SpecialMWOAuthManageMyGrants';
+
+ $wgLogTypes[] = 'mwoauthconsumer';
+ $wgLogNames['mwoauthconsumer'] =
'mwoauthconsumer-consumer-logpage';
+ $wgLogHeaders['mwoauthconsumer'] =
'mwoauthconsumer-consumer-logpagetext';
+ $wgLogActionsHandlers['mwoauthconsumer/*'] =
'LogFormatter';
}
- }
- /**
- * @param array $hooks $wgHooks
- * @return void
- */
- public static function defineHookHandlers( &$hooks ) {
- $hooks['GetPreferences'][] = 'MWOAuthUIHooks::onGetPreferences';
- }
-
- /**
- * @param array $logNames $wgLogNames (assoc array of log name message
keys)
- * @param array $logHeaders $wgLogHeaders (assoc array of log header
message keys)
- * @param array $filterLogTypes $wgFilterLogTypes
- * @return void
- */
- public static function defineLogBasicDescription(
- &$logNames, &$logHeaders, &$filterLogTypes
- ) {
- $logNames['mwoauthconsumer'] =
'mwoauthconsumer-consumer-logpage';
- $logHeaders['mwoauthconsumer'] =
'mwoauthconsumer-consumer-logpagetext';
- }
-
- /**
- * @param array$logActions $wgLogActions (assoc array of log action
message keys)
- * @param array $logActionsHandlers $wgLogActionsHandlers (assoc array
of log handlers)
- * @return void
- */
- public static function defineLogActionHandlers(
- &$logActions, &$logActionsHandlers
- ) {
- $logActionsHandlers['mwoauthconsumer/*'] = 'LogFormatter';
- }
-
- /**
- * Append resource module definitions
- * @param $modules Array $wgResourceModules
- * @return void
- */
- public static function defineResourceModules( array &$modules ) {
- $modules['ext.MWOAuth'] = array(
+ $wgResourceModules['ext.MWOAuth'] = array(
'styles' => 'ext.MWOAuth.css',
'localBasePath' => dirname( __FILE__ ) . '/modules',
'remoteExtPath' => 'OAuth/frontend/modules',
--
To view, visit https://gerrit.wikimedia.org/r/78416
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I435cb3032f3b09cc209a3c36987105ebdfb6cd2b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OAuth
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits