do_categorylinks_update(); flush();
do_image_name_unique_update(); flush();
do_logging_update(); flush();
+ do_user_rights_update(); flush();
if ( isTemplateInitialised() ) {
print "Template namespace already initialised\n";
function getSQL() {
$dbr =& wfGetDB( DB_SLAVE );
$user = $dbr->tableName( 'user' );
+ $user_rights = $dbr->tableName( 'user_rights' );
$userspace = Namespace::getUser();
- return 'SELECT user_rights as type,'.$userspace.' as namespace,'.
- 'user_name as title, user_name as value '.
- "FROM $user ".
- 'WHERE user_rights LIKE "%sysop%"';
+ 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%\"";
}
}
function getSQL() {
$dbr =& wfGetDB( DB_SLAVE );
- $usertable = $dbr->tableName( 'user' );
+ $user = $dbr->tableName( 'user' );
+ $user_rights = $dbr->tableName( 'user_rights' );
$userspace = Namespace::getUser();
- return "SELECT user_rights as type, $userspace as namespace, user_name as title, " .
- "user_name as value FROM $usertable";
+ 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";
}
function sortDescending() {
{
global $wgOut, $wgUser, $wgLang;
global $wgDBname, $wgMemc, $wgLocalDatabases;
+
+ $fname = 'MakesysopForm::doSubmit';
$dbw =& wfGetDB( DB_MASTER );
- $parts = explode( "@", $this->mUser );
- $usertable = $dbw->tableName( 'user' );
+ $parts = explode( '@', $this->mUser );
+ $user_rights = $dbw->tableName( 'user_rights' );
+ $usertable = $dbw->tableName( 'user' );
- if( count( $parts ) == 2 && $wgUser->isDeveloper() && strpos( '.', $usertable ) === false ){
+ if( count( $parts ) == 2 && $wgUser->isDeveloper() && strpos( '.', $user_rights ) === false ){
$username = $dbw->strencode( $parts[0] );
if ( array_key_exists( $parts[1], $wgLocalDatabases ) ) {
$dbName = $wgLocalDatabases[$parts[1]];
- $usertable = $dbName . "." . $usertable;
+ $user_rights = $dbName . '.' . $user_rights;
+ $usertable = $usertable . '.' . $usertable;
} else {
$this->showFail();
return;
}
if ( $username{0} == "#" ) {
$id = intval( substr( $username, 1 ) );
- $sql = "SELECT user_id,user_rights FROM $usertable WHERE user_id=$id FOR UPDATE";
+ $sql = "SELECT user_id,user_rights FROM $user_rights WHERE user_id=$id FOR UPDATE";
} else {
$encName = $dbw->strencode( $username );
- $sql = "SELECT user_id, user_rights FROM $usertable WHERE user_name = '{$username}' FOR UPDATE";
+ $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";
}
$prev = $dbw->ignoreErrors( TRUE );
if ( count( $rightsNotation ) == 0 ) {
$this->showFail();
} else {
- $sql = "UPDATE $usertable SET user_rights = '{$newrights}' WHERE user_id = $id LIMIT 1";
- $dbw->query($sql);
+ #$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 );
$wgMemc->delete( "$dbName:user:id:$id" );
$log = new LogPage( 'rights' );
$wgOut->addHTML( "<h2>" . wfMsg( "sitestats" ) . "</h2>\n" );
$dbr =& wfGetDB( DB_SLAVE );
- extract( $dbr->tableNames( 'cur', 'site_stats', 'user' ) );
+ extract( $dbr->tableNames( 'cur', 'site_stats', 'user', 'user_rights' ) );
$sql = "SELECT COUNT(cur_id) AS total FROM $cur";
$res = $dbr->query( $sql, $fname );
$row = $dbr->fetchObject( $res );
$total = $row->total;
- $sql = "SELECT COUNT(user_id) AS total FROM $user " .
- "WHERE user_rights LIKE '%sysop%'";
+ $sql = "SELECT COUNT(user_id) AS total FROM $user_rights WHERE user_rights LIKE '%sysop%'";
$res = $dbr->query( $sql, $fname );
$row = $dbr->fetchObject( $res );
$admins = $row->total;
} # the following stuff is for non-anonymous users only
$s = $dbr->getArray( 'user', array( 'user_name','user_password','user_newpassword','user_email',
- 'user_real_name','user_options','user_rights','user_touched' ),
+ 'user_real_name','user_options','user_touched' ),
array( 'user_id' => $this->mId ), $fname );
if ( $s !== false ) {
$this->mPassword = $s->user_password;
$this->mNewpassword = $s->user_newpassword;
$this->decodeOptions( $s->user_options );
- $this->mRights = explode( ",", strtolower( $s->user_rights ) );
$this->mTouched = wfTimestamp(TS_MW,$s->user_touched);
+ $this->mRights = explode( ",", strtolower(
+ $dbr->getField( 'user_rights', 'user_rights', array( 'user_id' => $this->mId ) )
+ ) );
}
$this->mDataLoaded = true;
'user_real_name' => $this->mRealName,
'user_email' => $this->mEmail,
'user_options' => $this->encodeOptions(),
- 'user_rights' => implode( ",", $this->mRights ),
'user_touched' => $dbw->timestamp($this->mTouched)
), array( /* WHERE */
'user_id' => $this->mId
), $fname
);
+ $dbw->set( 'user_rights', 'user_rights', implode( ",", $this->mRights ),
+ 'user_id='. $this->mId, $fname );
$wgMemc->delete( "$wgDBname:user:id:$this->mId" );
}
'user_newpassword' => $this->mNewpassword,
'user_email' => $this->mEmail,
'user_real_name' => $this->mRealName,
- 'user_rights' => implode( ',', $this->mRights ),
'user_options' => $this->encodeOptions()
), $fname
);
$this->mId = $dbw->insertId();
+ $dbw->insert( 'user_rights',
+ array(
+ 'user_id' => $this->mId,
+ 'user_rights' => implode( ',', $this->mRights )
+ ), $fname
+ );
+
}
function spreadBlock()
--- /dev/null
+-- Split user table into two parts:
+-- user
+-- user_rights
+-- The later contains only the permissions of the user. This way,
+-- you can store the accounts for several wikis in one central
+-- 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 '',
+ UNIQUE KEY user_id (user_id)
+) PACK_KEYS=1;
+
+INSERT INTO user_rights SELECT user_id,user_rights FROM user;
+
+ALTER TABLE user DROP COLUMN user_rights;
user_id int(5) unsigned NOT NULL auto_increment,
user_name varchar(255) binary NOT NULL default '',
user_real_name varchar(255) binary NOT NULL default '',
- user_rights tinyblob NOT NULL default '',
user_password tinyblob NOT NULL default '',
user_newpassword tinyblob NOT NULL default '',
user_email tinytext NOT NULL default '',
UNIQUE KEY user_id (user_id)
) PACK_KEYS=1;
+CREATE TABLE user_rights (
+ user_id int(5) unsigned NOT NULL,
+ user_rights tinyblob NOT NULL default '',
+ UNIQUE KEY user_id (user_id)
+) PACK_KEYS=1;
+
CREATE TABLE user_newtalk (
user_id int(5) NOT NULL default '0',
user_ip varchar(40) NOT NULL default ''
}
}
+function do_user_rights_update() {
+ global $wgDatabase;
+ if ( $wgDatabase->tableExists( 'user_rights' ) ) {
+ echo "...user_rights table already exists.\n";
+ } else {
+ echo 'Creating user rights table...';
+ dbsource( 'maintenance/archives/patch-user_rights.sql', $wgDatabase );
+ echo "ok\n";
+ }
+}
+
?>
GRANT DELETE,INSERT,SELECT,UPDATE ON `{$wgDBname}`.*
TO {$wgDBuser}@localhost.localdomain IDENTIFIED BY '{$wgDBpassword}';
-GRANT SELECT (user_id,user_name,user_rights,user_options) ON `{$wgDBname}`.user
+GRANT SELECT (user_id,user_name,user_options) ON `{$wgDBname}`.user
+ TO {$wgDBsqluser}@'%' IDENTIFIED BY '{$wgDBsqlpassword}';
+GRANT SELECT ON `{$wgDBname}`.user_rights
TO {$wgDBsqluser}@'%' IDENTIFIED BY '{$wgDBsqlpassword}';
GRANT SELECT ON `{$wgDBname}`.cur
TO {$wgDBsqluser}@'%' IDENTIFIED BY '{$wgDBsqlpassword}';
GRANT SELECT ON `{$wgDBname}`.math
TO {$wgDBsqluser}@'%' IDENTIFIED BY '{$wgDBsqlpassword}';
-GRANT SELECT (user_id,user_name,user_rights,user_options)
+GRANT SELECT (user_id,user_name,user_options)
ON `{$wgDBname}`.user
TO {$wgDBsqluser}@localhost IDENTIFIED BY '{$wgDBsqlpassword}';
+GRANT SELECT ON `{$wgDBname}`.user_rights
+ TO {$wgDBsqluser}@localhost IDENTIFIED BY '{$wgDBsqlpassword}';
GRANT SELECT ON `{$wgDBname}`.cur
TO {$wgDBsqluser}@localhost IDENTIFIED BY '{$wgDBsqlpassword}';
GRANT SELECT ON `{$wgDBname}`.old
GRANT SELECT ON `{$wgDBname}`.math
TO {$wgDBsqluser}@localhost IDENTIFIED BY '{$wgDBsqlpassword}';
-GRANT SELECT (user_id,user_name,user_rights,user_options)
+GRANT SELECT (user_id,user_name,user_options)
ON `{$wgDBname}`.user
TO {$wgDBsqluser}@localhost.localdomain IDENTIFIED BY '{$wgDBsqlpassword}';
+GRANT SELECT ON `{$wgDBname}`.user_rights
+ TO {$wgDBsqluser}@localhost.localdomain IDENTIFIED BY '{$wgDBsqlpassword}';
GRANT SELECT ON `{$wgDBname}`.cur
TO {$wgDBsqluser}@localhost.localdomain IDENTIFIED BY '{$wgDBsqlpassword}';
GRANT SELECT ON `{$wgDBname}`.old