From 428125255bd0ae343ce0f9ee2b0c875cb19a72c7 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Mon, 16 Jan 2006 19:18:29 +0000 Subject: [PATCH] Couple more useful functions for later scripts --- maintenance/userFunctions.inc | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/maintenance/userFunctions.inc b/maintenance/userFunctions.inc index 8e43a6d203..6f6a5487fa 100644 --- a/maintenance/userFunctions.inc +++ b/maintenance/userFunctions.inc @@ -33,6 +33,21 @@ function GetUsers() { return( $users ); } +# Resolve a username to a user ID +function GetUserID( $username ) { + $dbr =& wfGetDB( DB_SLAVE ); + $sql = 'SELECT user_id FROM ' . $dbr->tableName( 'user' ) . ' WHERE user_name = "' . $username . '"'; + $res = $dbr->query( $sql ); + if( $res !== false ) { + while( $row = $dbr->fetchObject( $res ) ) { + $ret = $row->user_id; + } + } else { + $ret = false; + } + return( $ret ); +} + # Delete one or more users function DeleteUsers( $users ) { # Need a master, obviously @@ -46,4 +61,22 @@ function DeleteUsers( $users ) { $dbw->commit(); } +/** + * Add a user to the named group(s) + * + * @param integer $user User ID + * @param mixed $groups Single string or array of strings corresponding to group names + * @return bool + */ +function SetUserGroups( $user, $groups ) { + $dbw =& wfGetDB( DB_MASTER ); + foreach( $groups as $group ) { + $row = array( 'ug_user' => $user, 'ug_group' => $group ); + if( !$dbw->insert( 'user_groups', $row, 'SetUserGroups' ) ) { + return( false ); + } + } + return( true ); +} + ?> \ No newline at end of file -- 2.20.1