Extension:Prefix Security/GroupsAdministration v1.0.0


 * Copy the code into a file (GroupsAdministration.php)

  " );				}				else {				 	$wgOut->addWikiText( wfMsg( 'groupsadministration-none' ) );				}				$dbr->freeResult( $res );		  		$action = $wgTitle->escapeLocalUrl;				$wgOut->addHTML( "    " );			}

if( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
 * 1) GET REQUESTS
 * 1) GET REQUESTS

# GET REQUEST: delete group - question #============================================#				if( $wgRequest->getText( 'action' ) == "delete_group" ) { $group_name = $wgRequest->getText( 'group_name' ); $action = $wgTitle->escapeLocalURL; $wgOut->addWikiText( wfMsg( 'groupsadministration-delete-areyousure', $group_name ) ); $wgOut->addHTML( "				 						  																			" ); }

# GET REQUEST: edit group #============================================#				if( $wgRequest->getText( 'action' ) == "edit_group" ) { $this->edit_group( "", $textbox_width ); }				# GET REQUEST: edit group #============================================#				if( $wgRequest->getText( 'edit_group' ) != "" || $wgRequest->getText( 'add_new_user' ) != ""					|| $wgRequest->getText( 'find_user' ) != "" || $wgRequest->getText( 'delete_selected_users' )					|| $wgRequest->getText( 'delete_user_yes' ) || $wgRequest->getText( 'delete_user_no' ) ) { $this->edit_group( "", $textbox_width ); }				# PRE GET REQUEST: remove user from group - question #============================================#				if ( ( $group_name = $wgRequest->getText( 'group_name' ) ) 				&& ( $remove_user = $wgRequest->getText( 'remove_user' ) ) ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-delete-user-areyousure2' ) ); $wgOut->addHTML( "				 						  						  						  																			" ); }			}

if ( $wgRequest->wasPosted ) {
 * 1) POST REQUESTS
 * 1) POST REQUESTS

# POST REQUEST: create new group #============================================#				if( $wgRequest->getText( 'create_new_group' ) != "" ) { if( $operand == 0 ) $wgOut->addWikiText( wfMsg( 'groupsadministration-missing' ) ); else if( $operand == 1 ) { #$wgOut->addWikiText( wfMsg( 'groupsadministration-success', $wgRequest->getText( 'new_group') ) ); $this->edit_group( $wgRequest->getText( 'new_group' ), $textbox_width ); }					else $wgOut->addWikiText( wfMsg( 'groupsadministration-failed', $wgRequest->getText( 'new_group' ) ) ); return; }

# POST REQUEST: delete group - yes #============================================#				if( $wgRequest->getText( 'delete_group_yes' ) != "" ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-delete-ok', $wgRequest->getText( 'group_name' ) ) ); return; }

# POST REQUEST: edit group #============================================#				if( $wgRequest->getText( 'edit_group' ) != "" || $wgRequest->getText( 'add_new_user' ) != ""					|| $wgRequest->getText( 'find_user' ) != "" || $wgRequest->getText( 'delete_selected_users' )					|| $wgRequest->getText( 'delete_user_yes' ) || $wgRequest->getText( 'delete_user_no' ) ) { $this->edit_group( "", $textbox_width ); }

# POST REQUEST: edit group - add user #============================================#				if( $wgRequest->getText( 'add_new_user' ) != "" ) { if( $operand == 0 ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-new-user-added', $add_user_name, $group_name ) ); return; }					else if( $operand == 1 ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-new-user-exist', $add_user_name, $group_name ) ); return; }					else if( $operand == 2 ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-new-user-not-found', $add_user_name ) ); return; }					else if( $operand == 3 ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-new-user-invalid', $add_user_name ) ); return; }					else if( $operand == 4 ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-new-user-missing' ) ); return; }				}

# POST REQUEST: edit group - find user #============================================#				if( $wgRequest->getText( 'find_user' ) != "" ) { if( $operand == 0 ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-find-user-list' ) ); foreach( $finded_users_array as $finded ) { $wgOut->addWikiText( "* ".$finded ); }						return; }					else if( $operand == 1 ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-find-user-nothing' ) ); return; }					else if( $operand == 2 ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-new-user-missing' ) ); return; }				}

# POST REQUEST: edit group - delete selected users - question #============================================#				if( $wgRequest->getText( 'delete_selected_users' ) != "" ) { if( $operand == 0 ) { $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-delete-user-choose' ) ); return; }					else if( $operand == 1 ) { $action = $wgTitle->escapeLocalURL; $user_number = $wgRequest->getInt( 'user_number' ); $group_name = $wgRequest->getText( 'group_name' ); if( $user_number == $num_to_delete ) $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-delete-user-areyousure1' ) ); else $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-delete-user-areyousure2' ) ); $wgOut->addHTML( "				 							  			<input type='hidden' name='group_name' value='$group_name'>				  			<input type='hidden' name='users_to_delete' value=\"$users_to_delete\">							<input type='submit' name='delete_user_yes' value='Yes'>							<input type='submit' name='delete_user_no' value='No'>						" ); }				}

# POST REQUEST: edit group - delete yes #============================================#				if( $wgRequest->getText( 'delete_user_yes' ) != "" ) { if( $operand == 1 ) $wgOut->addWikiText( wfMsg( 'groupsadministration-edit-delete-ok', "user has" ) ); return; }			}		}

/**		 * Function: edit_group * - Creates edit area upon edit button click */		function edit_group( $group_name = "", $textbox_width = "size='20'" ) { global $wgRequest; global $wgTitle; global $wgOut; global $wgUser; global $wgGroupPermissions; global $wgArticlePath; $server_param = strstr( $wgArticlePath, "?" ) ? "&" : "?";		 	if( $group_name == "" ) $group_name = $wgRequest->getText( 'group_name' );

$dbr =& wfGetDB( DB_SLAVE ); $sql = "SELECT * FROM ".$this->DatabasePrefixExists."user_groups WHERE ug_group='$group_name'"; $res = $dbr->query( $sql ); $count = $dbr->numRows( $res ); if( $count == 0 ) return; $user_id_array = array; while( $row = $dbr->fetchObject( $res ) ) { $user_id_array[] = $row->ug_user; }			$dbr->freeResult( $res ); $num = 0; $action = $wgTitle->escapeLocalUrl; $wgOut->addHTML( "				 Group \"".$group_name."\" 				<form name='form_delete_selected' method='post' action='$action'>				Users:				<ul>			" ); $remove_action = "$action{$server_param}edit_group=true&group_name=$group_name&"; foreach( $user_id_array as $user_id ) { $num++; $user_name = $wgUser->whoIs( $user_id ); $name_u = "user_name_".$num; $name_c = "delete_checkbox_".$num; $wgOut->addHTML( "					<input type='hidden' name='$name_u' value='$user_name'>					<li>{$user_name} (<a href='{$remove_action}remove_user={$user_id}'>remove user</a>)</li>				" ); }			$wgOut->addHTML( "</ul> " );

if( $count == 0 ) { $wgOut->addWikiText( " There are no users for this group." ); $wgOut->addHTML( "					<input type='hidden' name='user_number' value='$num'>					<input type='hidden' name='group_name' value='$group_name'>					<input type='text' name='new_user' title='To add or find user type the name here' $textbox_width>					<input type='submit' name='add_new_user' value='Add User'>					<input type='submit' name='find_user' value='Find'>				" ); }			else { $wgOut->addHTML( "					<input type='hidden' name='user_number' value='$num'>					<input type='hidden' name='group_name' value='$group_name'>					<input type='text' name='new_user' title='To add or find user type the name here' $textbox_width>					<input type='submit' name='add_new_user' value='Add User'>					<input type='submit' name='find_user' value='Find'> 				" ); }			$wgOut->addHTML( "<font size='1'> * Warning: if you delete all users than the group will be deleted to!!! " ); $wgOut->addHTML( " " ); }

/**		 * Function: canAdministrate * - Retrieves username listed in $wgGroupPermissions['logged']['prefixAdministration'] array * - If this array does not exist then only Sysops can Administrate */		function canAdministrate { global $wgUser; global $wgOut; global $wgGroupPermissions;

$user_accepted = true; if( isset( $wgGroupPermissions['logged']['prefixAdministration'] ) ) { $username = $wgUser->whoIs( $wgUser->getId ); if( in_array( $username, $wgGroupPermissions['logged']['prefixAdministration'] ) ) return true; else { #if( !$wgUser->isSysop ) { if( !is_sysop ) { return false; }				}		 	}		  	else { #if( !$wgUser->isSysop ) { if( !$this->is_sysop ) { return false; }			}			return true; }		/**		 * Function is_sysop * - Check in the database if current user is in the 'sysop' group */		function is_sysop { global $wgUser; $dbr =& wfGetDB( DB_SLAVE ); $res = $dbr->query( "SELECT * FROM user_groups WHERE ug_group = 'sysop'" ); while( $row = $dbr->fetchObject( $res ) ) { if( $wgUser->getId == $row->ug_user ) { return true; }			}			return false; }

/**		 * Function: DatabasePrefixExists * - Returns the database table prefix if exist, else returns "" */		function DatabasePrefixExists { global $wgGroupPermissions; if( !isset( $wgGroupPermissions['logged']['databasePrefix'] ) ) return ""; return $wgGroupPermissions['logged']['databasePrefix']; }	} }

else { echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" ); die( -1 ); }

?>