From bbfc760c1f790ca9110190eccf18bd34d1814889 Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Sun, 24 Oct 2004 09:21:53 +0000 Subject: [PATCH] Rename fields of user_rights and user_groups table to tablename_columnname schema --- includes/DefaultSettings.php | 11 +++++---- includes/Parser.php | 2 +- includes/SpecialListadmins.php | 6 ++--- includes/SpecialListusers.php | 4 ++-- includes/SpecialMakesysop.php | 14 +++++------ includes/SpecialStatistics.php | 2 +- includes/User.php | 24 +++++++++---------- .../patch-rename-user_groups-and_rights.sql | 9 +++++++ maintenance/archives/patch-user_rights.sql | 4 ++-- maintenance/archives/patch-userlevels.sql | 6 ++--- maintenance/tables.sql | 10 ++++---- maintenance/updaters.inc | 1 + 12 files changed, 52 insertions(+), 41 deletions(-) create mode 100644 maintenance/archives/patch-rename-user_groups-and_rights.sql diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 3cac609b8f..093a37532a 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -771,11 +771,12 @@ $wgImageLimits = array ( array(10000,10000) ); -# Navigation links for the user sidebar. -# 'text' is the name of the MediaWiki message that contains the label of this link -# 'href' is the name of the MediaWiki message that contains the link target of this link. -# Link targets starting with http are considered remote links. Ones not starting with -# http are considered as names of local wiki pages. +/** Navigation links for the user sidebar. + * 'text' is the name of the MediaWiki message that contains the label of this link + * 'href' is the name of the MediaWiki message that contains the link target of this link. + * Link targets starting with http are considered remote links. Ones not starting with + * http are considered as names of local wiki pages. + */ $wgNavigationLinks = array ( array( 'text'=>'mainpage', 'href'=>'mainpage' ), array( 'text'=>'portal', 'href'=>'portal-url' ), diff --git a/includes/Parser.php b/includes/Parser.php index 42c85acab5..52f14f9471 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -2460,7 +2460,7 @@ class Parser if( $istemplate ) $headline = $sk->editSectionScriptForOther($templatetitle, $templatesection, $headline); else - $headline = $sk->editSectionScript($this->title, $sectionCount+1,$headline); + $headline = $sk->editSectionScript($this->mTitle, $sectionCount+1,$headline); } # give headline the correct tag diff --git a/includes/SpecialListadmins.php b/includes/SpecialListadmins.php index aa617a0c2d..5d057305e4 100644 --- a/includes/SpecialListadmins.php +++ b/includes/SpecialListadmins.php @@ -31,9 +31,9 @@ class ListAdminsPage extends PageQueryPage { $user = $dbr->tableName( 'user' ); $user_rights = $dbr->tableName( 'user_rights' ); $userspace = Namespace::getUser(); - return "SELECT r.user_rights as type,{$userspace} as namespace,". - "u.user_name as title, u.user_name as value ". - "FROM {$user} u,{$user_rights} r WHERE r.user_id=u.user_id AND r.user_rights LIKE '%sysop%'"; + return "SELECT ur_rights as type,{$userspace} as namespace,". + "user_name as title, user_name as value ". + "FROM {$user} ,{$user_rights} WHERE user_id=ur_uid AND ur_rights LIKE '%sysop%'"; } } diff --git a/includes/SpecialListusers.php b/includes/SpecialListusers.php index c25da6bfc9..6f9f0e26fa 100644 --- a/includes/SpecialListusers.php +++ b/includes/SpecialListusers.php @@ -29,8 +29,8 @@ class ListUsersPage extends QueryPage { $user = $dbr->tableName( 'user' ); $user_rights = $dbr->tableName( 'user_rights' ); $userspace = Namespace::getUser(); - return "SELECT r.user_rights as type, $userspace as namespace, u.user_name as title, " . - "u.user_name as value FROM $user u LEFT JOIN $user_rights r ON u.user_id = r.user_id"; + return "SELECT ur_rights as type, $userspace as namespace, user_name as title, " . + "user_name as value FROM $user LEFT JOIN $user_rights ON user_id = ur_uid"; } function sortDescending() { diff --git a/includes/SpecialMakesysop.php b/includes/SpecialMakesysop.php index 48799d1bba..d1da928016 100644 --- a/includes/SpecialMakesysop.php +++ b/includes/SpecialMakesysop.php @@ -160,10 +160,10 @@ class MakesysopForm { } if ( $username{0} == "#" ) { $id = intval( substr( $username, 1 ) ); - $sql = "SELECT user_id,user_rights FROM $user_rights WHERE user_id=$id FOR UPDATE"; + $sql = "SELECT ur_uid,ur_rights FROM $user_rights WHERE ur_uid=$id FOR UPDATE"; } else { $encName = $dbw->strencode( $username ); - $sql = "SELECT u.user_id, user_rights FROM $usertable u LEFT JOIN $user_rights r ON u.user_id=r.user_id WHERE user_name = '{$username}' FOR UPDATE"; + $sql = "SELECT ur_uid, ur_rights FROM $usertable LEFT JOIN $user_rights ON user_id=ur_uid WHERE user_name = '{$username}' FOR UPDATE"; } $prev = $dbw->ignoreErrors( TRUE ); @@ -176,15 +176,15 @@ class MakesysopForm { } $row = $dbw->fetchObject( $res ); - $id = intval( $row->user_id ); + $id = intval( $row->ur_uid ); $rightsNotation = array(); if ( $wgUser->isDeveloper() ) { $newrights = (string)$this->mRights; $rightsNotation[] = "=$this->mRights"; } else { - if( $row->user_rights ){ - $rights = explode(",", $row->user_rights ); + if( $row->ur_rights ){ + $rights = explode(",", $row->ur_rights ); if(! in_array("sysop", $rights ) ){ $rights[] = "sysop"; $rightsNotation[] = "+sysop "; @@ -209,8 +209,8 @@ class MakesysopForm { } else { #$sql = "UPDATE $user_rights SET user_rights = '{$newrights}' WHERE user_id = $id LIMIT 1"; #$dbw->query($sql); - $dbw->replace( $user_rights, array( array( 'user_id', 'user_rights' )), - array( 'user_id' => $id, 'user_rights' => $newrights ) , $fname ); + $dbw->replace( $user_rights, array( array( 'ur_uid', 'ur_rights' )), + array( 'ur_uid' => $id, 'ur_rights' => $newrights ) , $fname ); $wgMemc->delete( "$dbName:user:id:$id" ); $log = new LogPage( 'rights' ); diff --git a/includes/SpecialStatistics.php b/includes/SpecialStatistics.php index ec40c09520..ee716e637e 100644 --- a/includes/SpecialStatistics.php +++ b/includes/SpecialStatistics.php @@ -46,7 +46,7 @@ function wfSpecialStatistics() { $row = $dbr->fetchObject( $res ); $total = $row->total; - $sql = "SELECT COUNT(user_id) AS total FROM $user_rights WHERE user_rights LIKE '%sysop%'"; + $sql = "SELECT COUNT(ur_uid) AS total FROM $user_rights WHERE ur_rights LIKE '%sysop%'"; $res = $dbr->query( $sql, $fname ); $row = $dbr->fetchObject( $res ); $admins = $row->total; diff --git a/includes/User.php b/includes/User.php index 957548118a..e6cec31fa2 100644 --- a/includes/User.php +++ b/includes/User.php @@ -356,11 +356,11 @@ class User { $this->mToken = $s->user_token; $this->mRights = explode( ",", strtolower( - $dbr->selectField( 'user_rights', 'user_rights', array( 'user_id' => $this->mId ) ) + $dbr->selectField( 'user_rights', 'ur_rights', array( 'ur_uid' => $this->mId ) ) ) ); // Get groups id - $res = $dbr->select( 'user_groups', array( 'group_id' ), array( 'user_id' => $this->mId ) ); + $res = $dbr->select( 'user_groups', array( 'ug_gid' ), array( 'ug_uid' => $this->mId ) ); while($group = $dbr->fetchRow($res)) { $this->mGroups[] = $group[0]; } @@ -769,19 +769,19 @@ class User { 'user_id' => $this->mId ), $fname ); - $dbw->set( 'user_rights', 'user_rights', implode( ',', $this->mRights ), - 'user_id='. $this->mId, $fname ); + $dbw->set( 'user_rights', 'ur_rights', implode( ',', $this->mRights ), + 'ur_uid='. $this->mId, $fname ); $wgMemc->delete( "$wgDBname:user:id:$this->mId" ); // delete old groups - $dbw->delete( 'user_groups', array( 'user_id' => $this->mId), $fname); + $dbw->delete( 'user_groups', array( 'ug_uid' => $this->mId), $fname); // save new ones foreach ($this->mGroups as $group) { $dbw->replace( 'user_groups', - array(array('user_id','group_id')), + array(array('ug_uid','ug_gid')), array( - 'user_id' => $this->mId, - 'group_id' => $group + 'ug_uid' => $this->mId, + 'ug_gid' => $group ), $fname ); } @@ -827,16 +827,16 @@ class User { $this->mId = $dbw->insertId(); $dbw->insert( 'user_rights', array( - 'user_id' => $this->mId, - 'user_rights' => implode( ',', $this->mRights ) + 'ur_uid' => $this->mId, + 'ur_rights' => implode( ',', $this->mRights ) ), $fname ); foreach ($this->mGroups as $group) { $dbw->insert( 'user_groups', array( - 'user_id' => $this->mId, - 'group_id' => $group + 'ug_uid' => $this->mId, + 'ug_gid' => $group ), $fname ); } diff --git a/maintenance/archives/patch-rename-user_groups-and_rights.sql b/maintenance/archives/patch-rename-user_groups-and_rights.sql new file mode 100644 index 0000000000..288cedf9d1 --- /dev/null +++ b/maintenance/archives/patch-rename-user_groups-and_rights.sql @@ -0,0 +1,9 @@ + +ALTER TABLE user_groups + CHANGE user_id ug_uid INT(5) UNSIGNED NOT NULL DEFAULT '0', + CHANGE group_id ug_gid INT(5) UNSIGNED NOT NULL DEFAULT '0'; + +ALTER TABLE user_rights + CHANGE user_id ur_uid INT(5) UNSIGNED NOT NULL, + CHANGE user_rights ur_rights TINYBLOB NOT NULL DEFAULT ''; + diff --git a/maintenance/archives/patch-user_rights.sql b/maintenance/archives/patch-user_rights.sql index 5d799dea44..6f4095d55d 100644 --- a/maintenance/archives/patch-user_rights.sql +++ b/maintenance/archives/patch-user_rights.sql @@ -6,8 +6,8 @@ -- database but keep user rights local to the wiki. CREATE TABLE user_rights ( - user_id int(5) unsigned NOT NULL, - user_rights tinyblob NOT NULL default '', + ur_uid int(5) unsigned NOT NULL, + ur_rights tinyblob NOT NULL default '', UNIQUE KEY user_id (user_id) ) PACK_KEYS=1; diff --git a/maintenance/archives/patch-userlevels.sql b/maintenance/archives/patch-userlevels.sql index c21f78c61e..1a719003dc 100644 --- a/maintenance/archives/patch-userlevels.sql +++ b/maintenance/archives/patch-userlevels.sql @@ -13,7 +13,7 @@ CREATE TABLE `group` ( -- Relation table between user and groups CREATE TABLE user_groups ( - user_id int(5) unsigned NOT NULL default '0', - group_id int(5) unsigned NOT NULL default '0', - PRIMARY KEY (user_id,group_id) + ug_uid int(5) unsigned NOT NULL default '0', + ug_gid int(5) unsigned NOT NULL default '0', + PRIMARY KEY (ug_uid,ug_gid) ); diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 80780b940a..a2c444e892 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -20,8 +20,8 @@ CREATE TABLE user ( -- TODO: de-blob this; it should be a property table CREATE TABLE user_rights ( - user_id int(5) unsigned NOT NULL, - user_rights tinyblob NOT NULL default '', + ur_uid int(5) unsigned NOT NULL, + ur_rights tinyblob NOT NULL default '', UNIQUE KEY user_id (user_id) ); @@ -352,7 +352,7 @@ CREATE TABLE `group` ( -- Relation table between user and groups CREATE TABLE user_groups ( - user_id int(5) unsigned NOT NULL default '0', - group_id int(5) unsigned NOT NULL default '0', - PRIMARY KEY (user_id,group_id) + ug_uid int(5) unsigned NOT NULL default '0', + ug_gid int(5) unsigned NOT NULL default '0', + PRIMARY KEY (ug_uid,ug_gid) ); diff --git a/maintenance/updaters.inc b/maintenance/updaters.inc index 3a2c6b8f83..de1ac33599 100644 --- a/maintenance/updaters.inc +++ b/maintenance/updaters.inc @@ -31,6 +31,7 @@ $wgNewFields = array( array( 'recentchanges', 'rc_patrolled', 'patch-rc-patrol.sql' ), array( 'user', 'user_real_name', 'patch-user-realname.sql' ), array( 'user', 'user_token', 'patch-user_token.sql' ), + array( 'user_rights', 'ur_uid', 'patch-rename-user_groups-and_rights.sql' ), ); function add_table( $name, $patch ) { -- 2.20.1