From: Tim Starling Date: Sun, 15 May 2005 06:18:48 +0000 (+0000) Subject: Renamed group table to groups, and renamed the fields from group_xxx to gr_xxx. Added... X-Git-Tag: 1.5.0alpha2~190 X-Git-Url: http://git.cyclocoop.org/%22.%28%24lien.?a=commitdiff_plain;h=63190801a84c5c0cf20c7547f7f15f7ab42c72ec;p=lhc%2Fweb%2Fwiklou.git Renamed group table to groups, and renamed the fields from group_xxx to gr_xxx. Added static group support to Special:Listusers. --- diff --git a/includes/Group.php b/includes/Group.php index 958cfe0fa4..cfaeb46fef 100644 --- a/includes/Group.php +++ b/includes/Group.php @@ -52,9 +52,9 @@ class Group { if($this->id) { // By ID $dbr =& wfGetDB( DB_SLAVE ); - $r = $dbr->selectRow('group', - array('group_id', 'group_name', 'group_description', 'group_rights'), - array( 'group_id' => $this->id ), + $r = $dbr->selectRow('groups', + array('gr_id', 'gr_name', 'gr_description', 'gr_rights'), + array( 'gr_id' => $this->id ), $fname ); if ( $r ) { $this->loadFromRow( $r ); @@ -65,9 +65,9 @@ class Group { } else { // By name $dbr =& wfGetDB( DB_SLAVE ); - $r = $dbr->selectRow('group', - array('group_id', 'group_name', 'group_description', 'group_rights'), - array( 'group_name' => $this->name ), + $r = $dbr->selectRow('groups', + array('gr_id', 'gr_name', 'gr_description', 'gr_rights'), + array( 'gr_name' => $this->name ), $fname ); if ( $r ) { $this->loadFromRow( $r ); @@ -80,10 +80,10 @@ class Group { /** Initialise from a result row */ function loadFromRow( &$row ) { - $this->id = $row->group_id; - $this->name = $row->group_name; - $this->description = $row->group_description; - $this->rights = $row->group_rights; + $this->id = $row->gr_id; + $this->name = $row->gr_name; + $this->description = $row->gr_description; + $this->rights = $row->gr_rights; $this->dataLoaded = true; } @@ -95,18 +95,20 @@ class Group { $fname = 'Group::addToDatabase'; $dbw =& wfGetDB( DB_MASTER ); - $dbw->insert( 'group', + $dbw->insert( 'groups', array( - 'group_name' => $this->name, - 'group_description' => $this->description, - 'group_rights' => $this->rights + 'gr_name' => $this->name, + 'gr_description' => $this->description, + 'gr_rights' => $this->rights ), $fname ); $this->id = $dbw->insertId(); } - /** Save the group datas into database */ + /** Save the group data into database */ function save() { + global $wgMemc; + if ( Group::getStaticGroups() ) { wfDebugDieBacktrace( "Can't modify groups in static mode" ); } @@ -115,19 +117,24 @@ class Group { $fname = 'Group::save'; $dbw =& wfGetDB( DB_MASTER ); - $dbw->update( 'group', + $dbw->update( 'groups', array( /* SET */ - 'group_name' => $this->name, - 'group_description' => $this->description, - 'group_rights' => $this->rights + 'gr_name' => $this->name, + 'gr_description' => $this->description, + 'gr_rights' => $this->rights ), array( /* WHERE */ - 'group_id' => $this->id + 'gr_id' => $this->id ), $fname - ); + ); + + $wgMemc->set( Group::getCacheKey( $this->id ), $this, 3600 ); } + /** Delete a group */ function delete() { + global $wgMemc; + if ( Group::getStaticGroups() ) { wfDebugDieBacktrace( "Can't modify groups in static mode" ); } @@ -140,9 +147,20 @@ class Group { $dbw->delete( 'user_group', array( 'ug_group' => $this->id ), $fname ); // Now delete the group - $dbw->delete( 'group', array( 'group_id' => $this->id ), $fname ); + $dbw->delete( 'groups', array( 'gr_id' => $this->id ), $fname ); + + $wgMemc->delete( Group::getCacheKey( $this->id ) ); } + /** + * Get memcached key + * @static + */ + function getCacheKey( $id ) { + global $wgDBname; + return "$wgDBname:groups:id:$id"; + } + // Factories /** * Uses Memcached if available. @@ -161,7 +179,8 @@ class Group { } } - $key = "$wgDBname:groups:id:$id"; + $key = Group::getCacheKey( $id ); + if( $group = $wgMemc->get( $key ) ) { wfDebug( "$fname loaded group $id from cache\n" ); return $group; @@ -222,8 +241,8 @@ class Group { wfProfileIn( $fname ); $dbr =& wfGetDB( DB_SLAVE ); - $groupTable = $dbr->tableName( 'group' ); - $sql = "SELECT group_id, group_name, group_description, group_rights FROM $groupTable"; + $groupTable = $dbr->tableName( 'groups' ); + $sql = "SELECT gr_id, gr_name, gr_description, gr_rights FROM $groupTable"; $res = $dbr->query($sql, $fname); $groups = array(); @@ -231,7 +250,7 @@ class Group { while($row = $dbr->fetchObject( $res ) ) { $group = new Group; $group->loadFromRow( $row ); - $groups[$row->group_id] = $group; + $groups[$row->gr_id] = $group; } wfProfileOut( $fname ); @@ -282,7 +301,7 @@ class Group { if ( $staticGroups ) { foreach( $staticGroups as $id => $group ) { if ( $group->getName() === $name ) { - return $group->getID(); + return $group->getId(); } } return 0; @@ -290,12 +309,12 @@ class Group { $dbr =& wfGetDB( DB_SLAVE ); - $r = $dbr->selectRow( 'group', array( 'group_id' ), array( 'group_name' => $name ), $fname ); + $r = $dbr->selectRow( 'groups', array( 'gr_id' ), array( 'gr_name' => $name ), $fname ); if($r === false) { return 0; } else { - return $r->group_id; + return $r->gr_id; } } diff --git a/includes/SpecialListusers.php b/includes/SpecialListusers.php index 3794c851d8..28837db8c9 100644 --- a/includes/SpecialListusers.php +++ b/includes/SpecialListusers.php @@ -66,19 +66,16 @@ class ListUsersPage extends QueryPage { '' . wfMsg( 'grouplevels-editgroup-name' ) . ' '; @@ -101,17 +98,15 @@ class ListUsersPage extends QueryPage { */ /** Show groups instead */ $user = $dbr->tableName( 'user' ); - $group = $dbr->tableName( 'group' ); $user_groups = $dbr->tableName( 'user_groups' ); $userspace = NS_USER; - $sql = "SELECT group_name as type, $userspace AS namespace, user_name AS title, user_name as value " . + $sql = "SELECT CONCAT('Listusers ', ug_group) as type, $userspace AS namespace, user_name AS title, user_name as value " . "FROM $user ". - "LEFT JOIN $user_groups ON user_id =ug_user " . - "LEFT JOIN $group ON ug_group = group_id "; + "LEFT JOIN $user_groups ON user_id =ug_user "; if($this->requestedGroup != '') { - $sql .= "WHERE group_id= '" . IntVal( $this->requestedGroup ) . "' "; + $sql .= "WHERE ug_group = '" . IntVal( $this->requestedGroup ) . "' "; if($this->requestedUser != '') { $sql .= "AND user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' '; } @@ -119,7 +114,7 @@ class ListUsersPage extends QueryPage { if($this->requestedUser !='') { $sql .= "WHERE user_name = " . $dbr->addQuotes( $this->requestedUser ) . ' '; } - } + } return $sql; } @@ -160,7 +155,11 @@ class ListUsersPage extends QueryPage { } if( is_object( $result ) && $result->type != '') { - $this->appendGroups( $skin->makeLink( wfMsgForContent( 'administrators' ), $result->type ) ); + $group = Group::newFromId( intval( strstr( $result->type, ' ' ) ) ); + if ( $group ) { + $groupName = $group->getExpandedName(); + $this->appendGroups( $skin->makeLink( wfMsgForContent( 'administrators' ), $groupName ) ); + } } $this->previousResult = $result; diff --git a/maintenance/archives/patch-rename-group.sql b/maintenance/archives/patch-rename-group.sql new file mode 100644 index 0000000000..026b60bdc4 --- /dev/null +++ b/maintenance/archives/patch-rename-group.sql @@ -0,0 +1,10 @@ +-- Rename groups table to groups, which is not a keyword +-- It was called group in a few alpha versions + +RENAME TABLE /*$wgDBprefix*/`group` TO /*$wgDBprefix*/groups; +ALTER TABLE /*$wgDBprefix*/groups + CHANGE group_id gr_id int(5) unsigned NOT NULL auto_increment, + CHANGE group_name gr_name varchar(50) NOT NULL default '', + CHANGE group_description gr_description varchar(255) NOT NULL default '', + CHANGE group_rights gr_rights tinyblob; + diff --git a/maintenance/archives/patch-userlevels-defaultgroups.sql b/maintenance/archives/patch-userlevels-defaultgroups.sql index 242c94ea4c..065653da94 100644 --- a/maintenance/archives/patch-userlevels-defaultgroups.sql +++ b/maintenance/archives/patch-userlevels-defaultgroups.sql @@ -3,27 +3,27 @@ -- Should probably be inserted when someone create a new database -- -INSERT INTO /*$wgDBprefix*/`group` (group_id,group_name,group_description,group_rights) +INSERT INTO /*$wgDBprefix*/groups (gr_id,gr_name,gr_description,gr_rights) VALUES ( 1,':group-anon-name',':group-anon-desc', 'read,edit,createaccount' ); -INSERT INTO /*$wgDBprefix*/`group` (group_id,group_name,group_description,group_rights) +INSERT INTO /*$wgDBprefix*/groups (gr_id,gr_name,gr_description,gr_rights) VALUES ( 2,':group-loggedin-name',':group-loggedin-desc', 'read,edit,move,upload,validate,createaccount' ); -INSERT INTO /*$wgDBprefix*/`group` (group_id,group_name,group_description,group_rights) +INSERT INTO /*$wgDBprefix*/groups (gr_id,gr_name,gr_description,gr_rights) VALUES ( 3,':group-admin-name',':group-admin-desc', 'read,edit,move,upload,validate,createaccount,delete,undelete,protect,block,upload,asksql,rollback,patrol,editinterface,import' ); -INSERT INTO /*$wgDBprefix*/`group` (group_id,group_name,group_description,group_rights) +INSERT INTO /*$wgDBprefix*/groups (gr_id,gr_name,gr_description,gr_rights) VALUES ( 4,':group-bureaucrat-name',':group-bureaucrat-desc', 'read,edit,move,upload,validate,createaccount,delete,undelete,protect,block,upload,asksql,rollback,patrol,editinterface,import,makesysop' ); -INSERT INTO /*$wgDBprefix*/`group` (group_id,group_name,group_description,group_rights) +INSERT INTO /*$wgDBprefix*/groups (gr_id,gr_name,gr_description,gr_rights) VALUES ( 5,':group-steward-name',':group-steward-desc', 'read,edit,move,upload,validate,createaccount,delete,undelete,protect,block,upload,asksql,rollback,patrol,editinterface,import,makesysop,userrights,grouprights,siteadmin' diff --git a/maintenance/archives/patch-userlevels-rights.sql b/maintenance/archives/patch-userlevels-rights.sql index aff208dfd5..7f1cabfc88 100644 --- a/maintenance/archives/patch-userlevels-rights.sql +++ b/maintenance/archives/patch-userlevels-rights.sql @@ -1,5 +1,5 @@ -- Oct. 24 2004 --- Adds the group_rights field missing from early dev work +-- Adds the gr_rights field missing from early dev work -- Hold group name and description -ALTER TABLE /*$wgDBprefix*/`group` ADD group_rights tinyblob; +ALTER TABLE /*$wgDBprefix*/groups ADD gr_rights tinyblob; diff --git a/maintenance/archives/patch-userlevels.sql b/maintenance/archives/patch-userlevels.sql index 96db38e41f..ab3a9a7ba8 100644 --- a/maintenance/archives/patch-userlevels.sql +++ b/maintenance/archives/patch-userlevels.sql @@ -4,12 +4,12 @@ -- This is under development to provide a showcase in HEAD :o) -- Hold group name and description -CREATE TABLE /*$wgDBprefix*/`group` ( - group_id int(5) unsigned NOT NULL auto_increment, - group_name varchar(50) NOT NULL default '', - group_description varchar(255) NOT NULL default '', - group_rights tinyblob, - PRIMARY KEY (group_id) +CREATE TABLE /*$wgDBprefix*/groups ( + gr_id int(5) unsigned NOT NULL auto_increment, + gr_name varchar(50) NOT NULL default '', + gr_description varchar(255) NOT NULL default '', + gr_rights tinyblob, + PRIMARY KEY (gr_id) ) TYPE=InnoDB; diff --git a/maintenance/parserTests.php b/maintenance/parserTests.php index 919925250d..184f8761c0 100644 --- a/maintenance/parserTests.php +++ b/maintenance/parserTests.php @@ -327,7 +327,7 @@ class ParserTest { 'recentchanges', 'watchlist', 'math', 'searchindex', 'interwiki', 'querycache', - 'objectcache', 'group' + 'objectcache', 'groups' ); } @@ -405,11 +405,11 @@ class ParserTest { ) ); # Hack: initialize a group - $db->insert( 'group', array( - 'group_id' => 1, - 'group_name' => 'Anonymous', - 'group_description' => 'Anonymous users', - 'group_rights' => 'read' ) ); + $db->insert( 'groups', array( + 'gr_id' => 1, + 'gr_name' => 'Anonymous', + 'gr_description' => 'Anonymous users', + 'gr_rights' => 'read' ) ); # Hack: Insert an image to work with $db->insert( 'image', array( diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 00e88a4b2e..9926966ed9 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -816,12 +816,12 @@ CREATE TABLE /*$wgDBprefix*/logging ( -- Hold group name and description -CREATE TABLE /*$wgDBprefix*/`group` ( - group_id int(5) unsigned NOT NULL auto_increment, - group_name varchar(50) NOT NULL default '', - group_description varchar(255) NOT NULL default '', - group_rights tinyblob, - PRIMARY KEY (group_id) +CREATE TABLE /*$wgDBprefix*/groups ( + gr_id int(5) unsigned NOT NULL auto_increment, + gr_name varchar(50) NOT NULL default '', + gr_description varchar(255) NOT NULL default '', + gr_rights tinyblob, + PRIMARY KEY (gr_id) ) TYPE=InnoDB; diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 6a0f24e042..4399f520c1 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -9,6 +9,11 @@ require_once 'convertLinks.inc'; require_once 'InitialiseMessages.inc'; +$wgRenamedTables = array( +# from to patch file + array( 'group', 'groups', 'patch-rename-group.sql' ), +); + $wgNewTables = array( # table patch file (in maintenance/archives) array( 'linkscc', 'patch-linkscc.sql' ), @@ -18,7 +23,7 @@ $wgNewTables = array( array( 'categorylinks', 'patch-categorylinks.sql' ), array( 'logging', 'patch-logging.sql' ), array( 'user_rights', 'patch-user_rights.sql' ), - array( 'group', 'patch-userlevels.sql' ), + array( 'groups', 'patch-userlevels.sql' ), ); $wgNewFields = array( @@ -33,7 +38,7 @@ $wgNewFields = array( array( 'user', 'user_token', 'patch-user_token.sql' ), array( 'user', 'user_email_token', 'patch-user_email_token.sql' ), array( 'user_rights', 'ur_user', 'patch-rename-user_groups-and_rights.sql' ), - array( 'group', 'group_rights', 'patch-userlevels-rights.sql' ), + array( 'groups', 'gr_rights', 'patch-userlevels-rights.sql' ), array( 'logging', 'log_params', 'patch-log_params.sql' ), array( 'archive', 'ar_rev_id', 'patch-archive-rev_id.sql' ), array( 'archive', 'ar_text_id', 'patch-archive-text_id.sql' ), @@ -43,6 +48,23 @@ $wgNewFields = array( array( 'image', 'img_metadata', 'patch-img_metadata.sql' ), ); +function rename_table( $from, $to, $patch ) { + global $wgDatabase; + if ( $wgDatabase->tableExists( $from ) ) { + if ( $wgDatabase->tableExists( $to ) ) { + echo "...can't move table $from to $to, $to already exists.\n"; + } else { + echo "Moving table $from to $to..."; + dbsource( "maintenance/archives/$patch", $wgDatabase ); + echo "ok\n"; + } + } else { + // Source table does not exist + // Renames are done before creations, so this is typical for a new installation + // Ignore silently + } +} + function add_table( $name, $patch ) { global $wgDatabase; if ( $wgDatabase->tableExists( $name ) ) { @@ -226,32 +248,17 @@ function do_user_update() { } } -# Assumes that the group table has been added. +# Assumes that the groups table has been added. function do_group_update() { global $wgDatabase; $res = $wgDatabase->safeQuery( 'SELECT COUNT(*) AS c FROM !', - $wgDatabase->tableName( 'group' ) ); + $wgDatabase->tableName( 'groups' ) ); $row = $wgDatabase->fetchObject( $res ); $wgDatabase->freeResult( $res ); if( $row->c == 0 ) { echo "Adding default group definitions... "; dbsource( "maintenance/archives/patch-userlevels-defaultgroups.sql", $wgDatabase ); echo "ok\n"; - } else { - echo "...group definitions already in place.\n"; - $res = $wgDatabase->safeQuery( "SELECT COUNT(*) AS n FROM ! - WHERE group_name IN ('Sysops','Bureaucrat') - AND group_rights NOT LIKE '%sysop%'", - $wgDatabase->tableName( 'group' ) ); - $row = $wgDatabase->fetchObject( $res ); - $wgDatabase->freeResult( $res ); - if( $row->n ) { - echo "Fixing sysops group permissions and add group editing right... "; - dbsource( "maintenance/archives/patch-group-sysopfix.sql", $wgDatabase ); - echo "ok\n"; - } else { - echo "...sysop group permissions look ok.\n"; - } } } @@ -500,8 +507,13 @@ function do_namespace_size_on( $table, $prefix ) { } function do_all_updates() { - global $wgNewTables, $wgNewFields; + global $wgNewTables, $wgNewFields, $wgRenamedTables; + # Rename tables + foreach ( $wgRenamedTables as $tableRecord ) { + rename_table( $tableRecord[0], $tableRecord[1], $tableRecord[2] ); + } + # Add missing tables foreach ( $wgNewTables as $tableRecord ) { add_table( $tableRecord[0], $tableRecord[1] );