CSteipp has uploaded a new change for review.
https://gerrit.wikimedia.org/r/91329
Change subject: Utility function to get central id from username
......................................................................
Utility function to get central id from username
Fixes TODO from gerrit 88251, SpecialMWOAuthListConsumers.php, so that
Special:MWOAuthListConsumers can be run on any wiki instead of the
central wiki only.
Change-Id: Ie17cacd68452ffea808d63b3d5b74078577c75be
---
M backend/MWOAuthUtils.php
1 file changed, 35 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OAuth
refs/changes/29/91329/1
diff --git a/backend/MWOAuthUtils.php b/backend/MWOAuthUtils.php
index 3417f73..3916cc4 100644
--- a/backend/MWOAuthUtils.php
+++ b/backend/MWOAuthUtils.php
@@ -404,6 +404,41 @@
}
/**
+ * Given a username, get the user ID for that user on the central wiki
+ *
+ * @param string $username
+ * @throws MWException
+ * @return integer|bool ID or false if not found
+ */
+ public static function getCentralIdFromUserName( $username ) {
+ global $wgMWOAuthCentralWiki, $wgMWOAuthSharedUserIDs,
$wgMWOAuthSharedUserSource;
+
+ if ( $wgMWOAuthSharedUserIDs ) { // global ID required via hook
+ if ( !Hooks::isRegistered(
'OAuthGetCentralIdFromUserName' ) ) {
+ throw new MWException( "No handler for
'OAuthGetCentralIdFromLocalUser' hook" );
+ }
+
+ $id = null;
+ // Let CentralAuth check that $user is attached to a
global account and
+ // that the foreign local account on the central wiki
is also attached to it
+ wfRunHooks( 'OAuthGetCentralIdFromUserName',
+ array( $username, $wgMWOAuthCentralWiki, &$id,
$wgMWOAuthSharedUserSource ) );
+ // If there is no such user, the extension should set
the ID to false
+ if ( $id === null ) {
+ $id = false;
+ }
+ } else {
+ $id = false;
+ $user = User::newFromName( $username );
+ if ( $user instanceof User && $user->getId() > 0 ) {
+ $id = $user->getId();
+ }
+ }
+
+ return $id;
+ }
+
+ /**
* Get the effective secret key/token to use for OAuth purposes.
*
* For example, the "secret key" and "access secret" values that are
--
To view, visit https://gerrit.wikimedia.org/r/91329
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie17cacd68452ffea808d63b3d5b74078577c75be
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OAuth
Gerrit-Branch: master
Gerrit-Owner: CSteipp <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits