r43434 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43433‎ | r43434 | r43435 >
Date:01:44, 13 November 2008
Author:laner
Status:old
Tags:
Comment:
Made debug code a little less stupid.
Modified paths:
  • /trunk/extensions/LdapAuthentication/LdapAuthentication.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LdapAuthentication/LdapAuthentication.php
@@ -41,6 +41,17 @@
4242 # Support is available at http://www.mediawiki.org/wiki/Extension_talk:LDAP_Authentication
4343 #
4444
 45+/**
 46+ * Add extension information to Special:Version
 47+ */
 48+$wgExtensionCredits['other'][] = array(
 49+ 'name' => 'LDAP Authentication Plugin',
 50+ 'version' => '1.2a (beta)',
 51+ 'author' => 'Ryan Lane',
 52+ 'description' => 'LDAP Authentication plugin with support for multiple LDAP authentication methods',
 53+ 'url' => 'http://www.mediawiki.org/wiki/Extension:LDAP_Authentication',
 54+ );
 55+
4556 //constants for search base
4657 define("GROUPDN", 0);
4758 define("USERDN", 1);
@@ -262,6 +273,7 @@
263274 }
264275
265276 $ldapconn = $this->connect();
 277+ //This seems really expensive.
266278 if ( $ldapconn ) {
267279 $this->printDebug( "Connected successfully", NONSENSITIVE );
268280
@@ -1229,7 +1241,7 @@
12301242
12311243 $searchnested = $wgLDAPGroupSearchNestedGroups[$_SESSION['wsDomain']];
12321244
1233 - $this->printDebug( "Required groups:" . implode( ",",$reqgroups ) . "", NONSENSITIVE );
 1245+ $this->printDebug( "Required groups:", NONSENSITIVE, $reqgroups );
12341246
12351247 $groups = $this->getUserGroups( $ldapconn, $userDN );
12361248
@@ -1285,7 +1297,7 @@
12861298 return false;
12871299 }
12881300
1289 - $this->printDebug( "Checking groups:" . implode( ",", $groups ) . "", SENSITIVE );
 1301+ $this->printDebug( "Checking groups:", SENSITIVE, $groups );
12901302
12911303 $reqgroups = $wgLDAPRequiredGroups[$_SESSION['wsDomain']];
12921304 for ( $i = 0; $i < count( $reqgroups ); $i++ ) {
@@ -1295,7 +1307,7 @@
12961308 $groupstocheck = array();
12971309 foreach ( $groups as $group ) {
12981310 $returnedgroups = $this->getUserGroups( $ldapconn, $group, false, false );
1299 - $this->printDebug( "Group $group is in the following groups:" . implode( ",", $returnedgroups ) . "", SENSITIVE );
 1311+ $this->printDebug( "Group $group is in the following groups:", SENSITIVE, $returnedgroups );
13001312 foreach ( $returnedgroups as $checkme ) {
13011313 if ( in_array( $checkme, $checkedgroups ) ) {
13021314 //We already checked this, move on
@@ -1465,6 +1477,7 @@
14661478 }
14671479
14681480 $info = @ldap_search( $ldapconn, $base, $filter );
 1481+ //TODO: Active Directory always returns something, we need to take this into account
14691482 if ( !$info ) {
14701483 $this->printDebug( "No entries returned from search.", SENSITIVE );
14711484
@@ -1473,7 +1486,7 @@
14741487 return array( array(), array() );
14751488 }
14761489
1477 - $entries = @ldap_get_entries( $ldapconn,$info );
 1490+ $entries = @ldap_get_entries( $ldapconn, $info );
14781491
14791492 //We need to shift because the first entry will be a count
14801493 array_shift( $entries );
@@ -1493,8 +1506,8 @@
14941507 array_push( $both_groups, $groups );
14951508 array_push( $both_groups, $shortnamegroups );
14961509
1497 - $this->printDebug( "Returned groups:" . implode( ",", $groups ) . "", SENSITIVE );
1498 - $this->printDebug( "Returned groups:" . implode( ",", $shortnamegroups ) . "", SENSITIVE );
 1510+ $this->printDebug( "Returned groups:", SENSITIVE, $groups );
 1511+ $this->printDebug( "Returned groups:", SENSITIVE, $shortnamegroups );
14991512
15001513 return $both_groups;
15011514 }
@@ -1537,6 +1550,8 @@
15381551 global $wgLDAPGroupsPrevail, $wgGroupPermissions;
15391552 global $wgLDAPLocallyManagedGroups;
15401553
 1554+ //TODO: this is *really* ugly code. clean it up!
 1555+
15411556 $this->printDebug( "Entering setGroups.", NONSENSITIVE );
15421557
15431558 # add groups permissions
@@ -1548,23 +1563,23 @@
15491564 if ( isset( $wgLDAPLocallyManagedGroups[$_SESSION['wsDomain']] ) ) {
15501565 $locallyManagedGrps = $wgLDAPLocallyManagedGroups[$_SESSION['wsDomain']];
15511566 $locallyManagedGrps = array_unique( array_merge( $defaultLocallyManagedGrps, $locallyManagedGrps ) );
1552 - $this->printDebug( "Locally managed groups: " . implode( ",", $locallyManagedGrps ) . "", SENSITIVE );
 1567+ $this->printDebug( "Locally managed groups: ", SENSITIVE, $locallyManagedGrps );
15531568 } else {
15541569 $locallyManagedGrps = $defaultLocallyManagedGrps;
1555 - $this->printDebug( "Locally managed groups is unset, using defaults: " . implode( ",", $locallyManagedGrps ) . "", SENSITIVE );
 1570+ $this->printDebug( "Locally managed groups is unset, using defaults: ", SENSITIVE, $locallyManagedGrps );
15561571 }
15571572
15581573
15591574 # Add ldap groups as local groups
15601575 if ( isset( $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) && $wgLDAPGroupsPrevail[$_SESSION['wsDomain']] ) {
1561 - $this->printDebug( "Adding all groups to wgGroupPermissions: " . implode( ",", $this->allLDAPGroups ) . "", SENSITIVE );
 1576+ $this->printDebug( "Adding all groups to wgGroupPermissions: ", SENSITIVE, $this->allLDAPGroups );
15621577 foreach ( $this->allLDAPGroups as $ldapgroup )
15631578 if ( !array_key_exists( $ldapgroup, $wgGroupPermissions ) )
15641579 $wgGroupPermissions[$ldapgroup] = array();
15651580 }
15661581
1567 - $this->printDebug( "Available groups are: " . implode( ",", $localAvailGrps ) . "", NONSENSITIVE );
1568 - $this->printDebug( "Effective groups are: " . implode( ",", $localUserGrps ) . "", NONSENSITIVE );
 1582+ $this->printDebug( "Available groups are: ", NONSENSITIVE, $localAvailGrps );
 1583+ $this->printDebug( "Effective groups are: ", NONSENSITIVE, $localUserGrps );
15691584
15701585 # note: $localUserGrps does not need to be updated with $cGroup added,
15711586 # as $localAvailGrps contains $cGroup only once.
@@ -1582,9 +1597,7 @@
15831598 $this->printDebug( "Checking to see if user is in: $cGroup", NONSENSITIVE );
15841599 if ( $this->hasLDAPGroup( $cGroup ) ) {
15851600 $this->printDebug( "Adding user to: $cGroup", NONSENSITIVE );
1586 - # so use the addGroup function
15871601 $user->addGroup( $cGroup );
1588 - # completed for $cGroup.
15891602 }
15901603 }
15911604 }
@@ -1634,11 +1647,17 @@
16351648 * @param string $debugVal
16361649 * @access private
16371650 */
1638 - function printDebug( $debugText, $debugVal ) {
 1651+ function printDebug( $debugText, $debugVal, $debugArr = Null ) {
16391652 global $wgLDAPDebug;
16401653
1641 - if ( $wgLDAPDebug > $debugVal ) {
1642 - echo $debugText . "<br />";
 1654+ if ( isset( $debugArr ) ) {
 1655+ if ( $wgLDAPDebug > $debugVal ) {
 1656+ echo $debugText . implode( ",", $debugArr ) . "<br />";
 1657+ }
 1658+ } else {
 1659+ if ( $wgLDAPDebug > $debugVal ) {
 1660+ echo $debugText . "<br />";
 1661+ }
16431662 }
16441663 }
16451664
@@ -1748,17 +1767,6 @@
17491768
17501769 }
17511770
1752 -/**
1753 - * Add extension information to Special:Version
1754 - */
1755 -$wgExtensionCredits['other'][] = array(
1756 - 'name' => 'LDAP Authentication Plugin',
1757 - 'version' => '1.2a (beta)',
1758 - 'author' => 'Ryan Lane',
1759 - 'description' => 'LDAP Authentication plugin with support for multiple LDAP authentication methods',
1760 - 'url' => 'http://www.mediawiki.org/wiki/Extension:LDAP_Authentication',
1761 - );
1762 -
17631771 // The following was derived from the SSL Authentication plugin
17641772 // http://www.mediawiki.org/wiki/SSL_authentication
17651773

Status & tagging log