[MediaWiki-l] Help!

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[MediaWiki-l] Help!

Elliott F. Cable
Ok, I've got another wiki merging with us - we use a global user  
table, they don't. We need to merge their entries in their user  
table, into our global user table - our solution was to take our  
highest user number so far (402) and add it to every UID in the user  
table, then go through each table and do the same for every place a  
UID appeared. I am VERY MUCH a PHP newbie - I am pretty dang good at  
hacking mediawiki to make it do what I want, but when it comes to  
writing code from scratch, well, I know nothing.

So, this is my first attempt at a script - of course it doesn't work,  
I have absolutely no idea what I'm doing, just went through some  
mediawiki, mint, and phpBB code and pulled out bits that looked  
relevant and threw them together. Could somebody either try to fix  
this, or write a quick script to go through a mySQL table and add a  
number (402) to every entry in a given column?


<?php
$success = false;
$db = array(
        'server' => 'localhost',
        'username' => '<snip>',
        'password' => '<snip>',
        'database' => '<snip>',
        'tblPrefix' => 'wiki_',
        'tblName' => 'archive',
        'connected' => 0
);

$targetAdd = 420;

$save = array();

function query($setrowname,$setrowdata,$whererowname,$whererowdata) {
        $thisresult = mysql_query(
                "UPDATE `{$this->db['tblPrefix']}{$this->db['tblName']}` SET `
{$setrowname}` = '{$setrowdata}' WHERE `{$whererowname}`=
{$whererowdata}"
        );
        return $thisresult;
}

if ( @mysql_connect($this->db['server'],$this->db['username'],$this-
 >db['password']) ) {
        if ( @mysql_select_db($this->db['database']) ) {
                $thisresult = mysql_query( "SELECT * FROM `{$this->db['tblPrefix']}
{$this->db['tblName']}` ORDER BY `id` ASC LIMIT $start, $limit" );
                $row = mysql_fetch_assoc($thisresult);
        }
}

foreach($row as $column => $value) {
        if( $column == 'user_id' ) {
                $oldUID = $value;
                $save[$oldUID] = $value + $targetAdd;
                query('user_id',$save[$oldUID],'user_id',$oldUID);
        }
}

return $success

?>
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: [MediaWiki-l] Help!

Brion Vibber
Elliott F. Cable wrote:
> So, this is my first attempt at a script - of course it doesn't work,  
> I have absolutely no idea what I'm doing, just went through some  
> mediawiki, mint, and phpBB code and pulled out bits that looked  
> relevant and threw them together. Could somebody either try to fix  
> this, or write a quick script to go through a mySQL table and add a  
> number (402) to every entry in a given column?

Do yourself a favor and skip the PHP; this is what SQL was made for. :)

UPDATE mytable SET mytable_user=mytable_user+402;

or to avoid breaking anonymous & scripted edits something like this should work:

UPDATE mytable SET mytable_user=IF(mytable_user,mytable_user+402,0);


You'll also need to take care that you don't have conflicting usernames, since
usernames must be unique.

-- brion vibber (brion @ pobox.com)


_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l

signature.asc (257 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [MediaWiki-l] Help!

Elliott F. Cable
Any tips on checking for usernames? A script in the maintenance dir  
for combining two user databases would be cool (-:

What about for the other tables in his install? They'll need to be  
updated to use the new user IDs too )-]

On May 15, 2006, at 1:12 PM, Brion Vibber wrote:

> Elliott F. Cable wrote:
>> So, this is my first attempt at a script - of course it doesn't work,
>> I have absolutely no idea what I'm doing, just went through some
>> mediawiki, mint, and phpBB code and pulled out bits that looked
>> relevant and threw them together. Could somebody either try to fix
>> this, or write a quick script to go through a mySQL table and add a
>> number (402) to every entry in a given column?
>
> Do yourself a favor and skip the PHP; this is what SQL was made  
> for. :)
>
> UPDATE mytable SET mytable_user=mytable_user+402;
>
> or to avoid breaking anonymous & scripted edits something like this  
> should work:
>
> UPDATE mytable SET mytable_user=IF(mytable_user,mytable_user+402,0);
>
>
> You'll also need to take care that you don't have conflicting  
> usernames, since
> usernames must be unique.
>
> -- brion vibber (brion @ pobox.com)
>
> _______________________________________________
> MediaWiki-l mailing list
> [hidden email]
> http://mail.wikipedia.org/mailman/listinfo/mediawiki-l

_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: [MediaWiki-l] Help!

Ira Abramov
Quoting Elliott F. Cable, from the post of Mon, 15 May:
> Any tips on checking for usernames? A script in the maintenance dir  
> for combining two user databases would be cool (-:

there are a few nice ways to do it right there in SQL (which is always
good to know, it's a pretty simple, thought powerful, language). if you
want the quickest way for you to chop up tables and search for doubles,
without learning SQL, I suggest you dump the two tables to CSV and use
your favorite text manipulation tools like sort, uniq, awk, whichever is
your favorite. there are of course countless ways to do such an export.
a quick google on "mysql export csv" returns code to do it in php and
SQL alike.

>
> What about for the other tables in his install? They'll need to be  
> updated to use the new user IDs too )-]

same commandline, different table...

> > Do yourself a favor and skip the PHP; this is what SQL was made  
> > for. :)
> >
> > UPDATE mytable SET mytable_user=mytable_user+402;
> >
> > or to avoid breaking anonymous & scripted edits something like this  
> > should work:
> >
> > UPDATE mytable SET mytable_user=IF(mytable_user,mytable_user+402,0);
> >

don't fear SQL, it's your friend :)

--
FCC restricted word
Ira Abramov
http://ira.abramov.org/email/
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l