show link cursor
[mediawiki.git] / maintenance / archives / upgradeWatchlist.php
blob1027bb8796609a7958fd1159efc7e19259d9e37e
1 <?php
3 print "This script is obsolete!";
4 print "It is retained in the source here in case some of its
5 code might be useful for ad-hoc conversion tasks, but it is
6 not maintained and probably won't even work as is.";
7 exit();
9 # Convert watchlists to new format
11 global $IP;
12 include_once( "../LocalSettings.php" );
13 include_once( "$IP/Setup.php" );
15 $wgTitle = Title::newFromText( "Rebuild links script" );
16 set_time_limit(0);
18 $wgDBuser = "wikiadmin";
19 $wgDBpassword = $wgDBadminpassword;
21 $sql = "DROP TABLE IF EXISTS watchlist";
22 wfQuery( $sql, DB_WRITE );
23 $sql = "CREATE TABLE watchlist (
24 wl_user int(5) unsigned NOT NULL,
25 wl_page int(8) unsigned NOT NULL,
26 UNIQUE KEY (wl_user, wl_page)
27 ) TYPE=MyISAM PACK_KEYS=1";
28 wfQuery( $sql, DB_WRITE );
30 $lc = new LinkCache;
32 # Now, convert!
33 $sql = "SELECT user_id,user_watch FROM user";
34 $res = wfQuery( $sql, DB_READ );
35 $nu = wfNumRows( $res );
36 $sql = "INSERT into watchlist (wl_user,wl_page) VALUES ";
37 $i = $n = 0;
38 while( $row = wfFetchObject( $res ) ) {
39 $list = explode( "\n", $row->user_watch );
40 $bits = array();
41 foreach( $list as $title ) {
42 if( $id = $lc->addLink( $title ) and ! $bits[$id]++) {
43 $sql .= ($i++ ? "," : "") . "({$row->user_id},{$id})";
46 if( ($n++ % 100) == 0 ) echo "$n of $nu users done...\n";
48 echo "$n users done.\n";
49 if( $i ) {
50 wfQuery( $sql, DB_WRITE );
54 # Add index
55 # is this necessary?
56 $sql = "ALTER TABLE watchlist
57 ADD INDEX wl_user (wl_user),
58 ADD INDEX wl_page (wl_page)";
59 #wfQuery( $sql, DB_WRITE );