http://www.mediawiki.org/wiki/Special:Code/MediaWiki/98649
Revision: 98649 Author: ashley Date: 2011-10-02 01:04:09 +0000 (Sun, 02 Oct 2011) Log Message: ----------- GlobalUserrights: make GlobalUserrights compatible with MW 1.18+, thanks to Krinkle for noticing that this extension didn't work. Lightly tested against 1.18 locally Modified Paths: -------------- trunk/extensions/GlobalUserrights/GlobalUserrights.php trunk/extensions/GlobalUserrights/GlobalUserrights_body.php Modified: trunk/extensions/GlobalUserrights/GlobalUserrights.php =================================================================== --- trunk/extensions/GlobalUserrights/GlobalUserrights.php 2011-10-01 23:43:52 UTC (rev 98648) +++ trunk/extensions/GlobalUserrights/GlobalUserrights.php 2011-10-02 01:04:09 UTC (rev 98649) @@ -17,7 +17,7 @@ 'path' => __FILE__, 'name' => 'GlobalUserrights', 'url' => 'http://www.mediawiki.org/wiki/Extension:GlobalUserrights', - 'version' => '1.0.2', + 'version' => '1.0.3', 'author' => 'Nathaniel Herman', 'descriptionmsg' => 'gur-desc', ); @@ -52,7 +52,7 @@ */ function efGURgetGroups( $user ) { if ( $user instanceof User ) { - $uid = $user->mId; + $uid = $user->getId(); } else { // if $user isn't an instance of user, assume it's the uid $uid = $user; @@ -61,19 +61,18 @@ $dbr = wfGetDB( DB_MASTER ); $groups = array(); - $res = $dbr->select( 'global_user_groups', + $res = $dbr->select( + 'global_user_groups', array( 'gug_group' ), - array( 'gug_user' => $uid ) + array( 'gug_user' => $uid ), + __FUNCTION__ ); - while ( $row = $dbr->fetchObject( $res ) ) { + foreach ( $res as $row ) { $groups[] = $row->gug_group; } - $dbr->freeResult( $res ); - return $groups; - } /** @@ -100,8 +99,13 @@ */ function efGURUpdateQueryInfo( $that, &$query ) { $dbr = wfGetDB( DB_SLAVE ); - list( $gug ) = $dbr->tableNamesN( 'global_user_groups' ); - $query['tables'] .= "LEFT JOIN $gug ON user_id=gug_user"; + + $query['tables'][] = 'global_user_groups'; + $query['join_conds']['global_user_groups'] = array( + 'LEFT JOIN', + 'user_id = gug_user' + ); + $query['fields'][3] = 'COUNT(ug_group) + COUNT(gug_group) AS numgroups'; // kind of yucky statement, I blame MySQL 5.0.13 http://bugs.mysql.com/bug.php?id=15610 $query['fields'][4] = 'GREATEST(COALESCE(ug_group, gug_group), COALESCE(gug_group, ug_group)) AS singlegroup'; Modified: trunk/extensions/GlobalUserrights/GlobalUserrights_body.php =================================================================== --- trunk/extensions/GlobalUserrights/GlobalUserrights_body.php 2011-10-01 23:43:52 UTC (rev 98648) +++ trunk/extensions/GlobalUserrights/GlobalUserrights_body.php 2011-10-02 01:04:09 UTC (rev 98649) @@ -1,88 +1,80 @@ <?php /** - * Special:Userrights for global groups + * Special:GlobalUserrights, Special:Userrights for global groups * * @file * @ingroup Extensions */ -if ( !defined( 'MEDIAWIKI' ) ) die(); - class GlobalUserrights extends UserrightsPage { /* Constructor */ public function __construct() { - parent::__construct( 'GlobalUserrights' ); + SpecialPage::__construct( 'GlobalUserrights' ); } - + /** * Save global user groups changes in the DB * * @param $username String: username * @param $reason String: reason */ - function saveUserGroups( $username, $reason = '' ) { - global $wgRequest; - $user = $this->fetchUser( $username ); - if ( !$user ) { - return; - } - - $allgroups = $this->getAllGroups(); - $addgroups = array(); - $removegroups = array(); - - foreach ( $allgroups as $group ) { - if ( $wgRequest->getCheck( "wpGroup-$group" ) ) { - $addgroups[] = $group; - } else { - $removegroups[] = $group; - } - } - + function doSaveUserGroups( $user, $add, $remove, $reason = '' ) { $oldGroups = efGURgetGroups( $user ); $newGroups = $oldGroups; - if ( $removegroups ) { - $newGroups = array_diff( $newGroups, $removegroups ); - $dbw = wfGetDB( DB_MASTER ); + // remove then add groups + if ( $remove ) { + $newGroups = array_diff( $newGroups, $remove ); $uid = $user->getId(); - foreach ( $removegroups as $group ) + foreach ( $remove as $group ) { // whole reason we're redefining this function is to make it use // $this->removeGroup instead of $user->removeGroup, etc. - $this->removeGroup( $uid, $group, $dbw ); + $this->removeGroup( $uid, $group ); + } } - if ( $addgroups ) { - $newGroups = array_merge( $newGroups, $addgroups ); - $dbw = wfGetDB( DB_MASTER ); + if ( $add ) { + $newGroups = array_merge( $newGroups, $add ); $uid = $user->getId(); - foreach ( $addgroups as $group ) - $this->addGroup( $uid, $group, $dbw ); + foreach ( $add as $group ) { + $this->addGroup( $uid, $group ); + } } // get rid of duplicate groups there might be $newGroups = array_unique( $newGroups ); - $user->invalidateCache(); // clear cache + // Ensure that caches are cleared + $user->invalidateCache(); // if anything changed, log it - if ( $newGroups != $oldGroups ) - $this->addLogEntry( $user, $oldGroups, $newGroups ); + if ( $newGroups != $oldGroups ) { + $this->addLogEntry( $user, $oldGroups, $newGroups, $reason ); + } + return array( $add, $remove ); } - function addGroup( $uid, $group, $dbw ) { - $dbw->insert( 'global_user_groups', array( - 'gug_user' => $uid, - 'gug_group' => $group ), + function addGroup( $uid, $group ) { + $dbw = wfGetDB( DB_MASTER ); + $dbw->insert( + 'global_user_groups', + array( + 'gug_user' => $uid, + 'gug_group' => $group + ), __METHOD__, 'IGNORE' ); $dbw->commit(); } - function removeGroup( $uid, $group, $dbw ) { - $dbw->delete( 'global_user_groups', array( - 'gug_user' => $uid, - 'gug_group' => $group ), + function removeGroup( $uid, $group ) { + $dbw = wfGetDB( DB_MASTER ); + $dbw->delete( + 'global_user_groups', + array( + 'gug_user' => $uid, + 'gug_group' => $group + ), __METHOD__ ); $dbw->commit(); @@ -91,30 +83,19 @@ /** * Add a gblrights log entry */ - function addLogEntry( $user, $oldGroups, $newGroups ) { - global $wgRequest; + function addLogEntry( $user, $oldGroups, $newGroups, $reason ) { $log = new LogPage( 'gblrights' ); + $log->addEntry( 'rights', $user->getUserPage(), - $wgRequest->getText( 'user-reason' ), - array( - $this->makeGroupNameList( $oldGroups ), - $this->makeGroupNameList( $newGroups ) - ) - ); + $reason, + array( + $this->makeGroupNameListForLog( $oldGroups ), + $this->makeGroupNameListForLog( $newGroups ) + ) + ); } - function fetchUser( $username ) { - global $wgOut; - $user = User::newFromName( $username ); - if ( !$user || $user->isAnon() ) { - $wgOut->addWikiMsg( 'nosuchusershort', $username ); - return null; - } - - return $user; - } - protected function showEditUserGroupsForm( $user, $groups ) { // override the $groups that is passed, which will be // the user's local groups @@ -139,7 +120,7 @@ } protected function showLogFragment( $user, $output ) { - $output->addHtml( Xml::element( 'h2', null, LogPage::logName( 'gblrights' ) . "\n" ) ); + $output->addHTML( Xml::element( 'h2', null, LogPage::logName( 'gblrights' ) . "\n" ) ); LogEventsList::showLogExtract( $output, 'gblrights', $user->getUserPage()->getPrefixedText() ); } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs