Fix for compatibility with short_open_tag = Off
[lhc/web/wiklou.git] / maintenance / archives / upgradeWatchlist.php
1 <?php
2 # Convert watchlists to new format
3
4 global $IP;
5 include_once( "../LocalSettings.php" );
6 include_once( "$IP/Setup.php" );
7
8 $wgTitle = Title::newFromText( "Rebuild links script" );
9 set_time_limit(0);
10
11 $wgDBuser = "wikiadmin";
12 $wgDBpassword = $wgDBadminpassword;
13
14 $sql = "DROP TABLE IF EXISTS watchlist";
15 wfQuery( $sql, DB_WRITE );
16 $sql = "CREATE TABLE watchlist (
17 wl_user int(5) unsigned NOT NULL,
18 wl_page int(8) unsigned NOT NULL,
19 UNIQUE KEY (wl_user, wl_page)
20 ) TYPE=MyISAM PACK_KEYS=1";
21 wfQuery( $sql, DB_WRITE );
22
23 $lc = new LinkCache;
24
25 # Now, convert!
26 $sql = "SELECT user_id,user_watch FROM user";
27 $res = wfQuery( $sql, DB_READ );
28 $nu = wfNumRows( $res );
29 $sql = "INSERT into watchlist (wl_user,wl_page) VALUES ";
30 $i = $n = 0;
31 while( $row = wfFetchObject( $res ) ) {
32 $list = explode( "\n", $row->user_watch );
33 $bits = array();
34 foreach( $list as $title ) {
35 if( $id = $lc->addLink( $title ) and ! $bits[$id]++) {
36 $sql .= ($i++ ? "," : "") . "({$row->user_id},{$id})";
37 }
38 }
39 if( ($n++ % 100) == 0 ) echo "$n of $nu users done...\n";
40 }
41 echo "$n users done.\n";
42 if( $i ) {
43 wfQuery( $sql, DB_WRITE );
44 }
45
46
47 # Add index
48 # is this necessary?
49 $sql = "ALTER TABLE watchlist
50 ADD INDEX wl_user (wl_user),
51 ADD INDEX wl_page (wl_page)";
52 #wfQuery( $sql, DB_WRITE );
53
54 ?>