include_once -> require_once
[lhc/web/wiklou.git] / maintenance / archives / upgradeWatchlist.php
1 <?php
2
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();
8
9 # Convert watchlists to new format
10
11 global $IP;
12 require_once( "../LocalSettings.php" );
13 require_once( "$IP/Setup.php" );
14
15 $wgTitle = Title::newFromText( "Rebuild links script" );
16 set_time_limit(0);
17
18 $wgDBuser = "wikiadmin";
19 $wgDBpassword = $wgDBadminpassword;
20
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 );
29
30 $lc = new LinkCache;
31
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})";
44 }
45 }
46 if( ($n++ % 100) == 0 ) echo "$n of $nu users done...\n";
47 }
48 echo "$n users done.\n";
49 if( $i ) {
50 wfQuery( $sql, DB_WRITE );
51 }
52
53
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 );
60
61 ?>