summaryrefslogtreecommitdiff
path: root/maintenance/archives/upgradeWatchlist.php
blob: 250c667740e1da59e8b53d9154d276a8e0aec5bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
 * @deprecated
 * @addtogroup MaintenanceArchive
 */

/** */
print "This script is obsolete!";
print "It is retained in the source here in case some of its
code might be useful for ad-hoc conversion tasks, but it is
not maintained and probably won't even work as is.";
exit();

# Convert watchlists to new format

global $IP;
require_once( "../LocalSettings.php" );
require_once( "$IP/Setup.php" );

$wgTitle = Title::newFromText( "Rebuild links script" );
set_time_limit(0);

$wgDBuser			= "wikiadmin";
$wgDBpassword		= $wgDBadminpassword;

$sql = "DROP TABLE IF EXISTS watchlist";
wfQuery( $sql, DB_MASTER );
$sql = "CREATE TABLE watchlist (
  wl_user int(5) unsigned NOT NULL,
  wl_page int(8) unsigned NOT NULL,
  UNIQUE KEY (wl_user, wl_page)
) TYPE=MyISAM PACK_KEYS=1";
wfQuery( $sql, DB_MASTER );

$lc = new LinkCache;

# Now, convert!
$sql = "SELECT user_id,user_watch FROM user";
$res = wfQuery( $sql, DB_SLAVE );
$nu = wfNumRows( $res );
$sql = "INSERT into watchlist (wl_user,wl_page) VALUES ";
$i = $n = 0;
while( $row = wfFetchObject( $res ) ) {
	$list = explode( "\n", $row->user_watch );
	$bits = array();
	foreach( $list as $title ) {
		if( $id = $lc->addLink( $title ) and ! $bits[$id]++) {
			$sql .= ($i++ ? "," : "") . "({$row->user_id},{$id})";
		}
	}
	if( ($n++ % 100) == 0 ) echo "$n of $nu users done...\n";
}
echo "$n users done.\n";
if( $i ) {
	wfQuery( $sql, DB_MASTER );
}


# Add index
# is this necessary?
$sql = "ALTER TABLE watchlist
  ADD INDEX wl_user (wl_user),
  ADD INDEX wl_page (wl_page)";
#wfQuery( $sql, DB_MASTER );

?>