prefs toc styling
[lhc/web/wiklou.git] / maintenance / rebuildrecentchanges.inc
1 <?php
2
3 # Rebuild recent changes table.
4 #
5
6 function rebuildRecentChangesTablePass1()
7 {
8 $sql = "DELETE FROM recentchanges";
9 wfQuery( $sql, DB_WRITE );
10
11 print( "Loading from CUR table...\n" );
12
13 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,rc_user," .
14 "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_bot,rc_new," .
15 "rc_cur_id,rc_this_oldid,rc_last_oldid) SELECT cur_timestamp," .
16 "cur_timestamp,cur_user,cur_user_text,cur_namespace,cur_title," .
17 "cur_comment,cur_minor_edit,0,cur_is_new,cur_id,0,0 FROM cur " .
18 "ORDER BY inverse_timestamp LIMIT 5000";
19 wfQuery( $sql, DB_WRITE );
20
21 print( "Loading from OLD table...\n" );
22
23 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,rc_user," .
24 "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_bot,rc_new," .
25 "rc_cur_id,rc_this_oldid,rc_last_oldid) SELECT old_timestamp,cur_timestamp," .
26 "old_user,old_user_text,old_namespace,old_title,old_comment," .
27 "old_minor_edit,0,0,cur_id,old_id,0 FROM old,cur " .
28 "WHERE old_namespace=cur_namespace AND old_title=cur_title ORDER BY old.inverse_timestamp " .
29 "LIMIT 5000";
30 wfQuery( $sql, DB_WRITE );
31
32 $sql = "SELECT rc_timestamp FROM recentchanges " .
33 "ORDER BY rc_timestamp DESC LIMIT 5000,1";
34 $res = wfQuery( $sql, DB_WRITE );
35 $obj = wfFetchObject( $res );
36 $ts = $obj->rc_timestamp;
37
38 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$ts}'";
39 wfQuery( $sql, DB_WRITE );
40 }
41
42 function rebuildRecentChangesTablePass2()
43 {
44 $ns = $id = $count = 0;
45 $title = $ct = "";
46
47 print( "Updating links...\n" );
48
49 # Fill in the rc_last_oldid field, which points to the previous edit
50 #
51 $sql = "SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM recentchanges " .
52 "ORDER BY rc_cur_id,rc_timestamp";
53 $res = wfQuery( $sql, DB_WRITE );
54
55 $lastCurId = 0;
56 $lastOldId = 0;
57 while ( $obj = wfFetchObject( $res ) ) {
58 $new = 0;
59 if( $obj->rc_cur_id != $lastCurId ) {
60 # Switch! Look up the previous last edit, if any
61 $lastCurId = IntVal( $obj->rc_cur_id );
62 $emit = wfInvertTimestamp( $obj->rc_timestamp );
63 $sql2 = "SELECT old_id FROM old,cur " .
64 "WHERE old_namespace=cur_namespace AND old_title=cur_title AND cur_id={$lastCurId} ".
65 "AND old.inverse_timestamp>'{$emit}' ORDER BY old.inverse_timestamp LIMIT 1";
66 $res2 = wfQuery( $sql2, DB_WRITE );
67 if( $row = wfFetchObject( $res2 ) ) {
68 $lastOldId = IntVal( $row->old_id );
69 } else {
70 # No previous edit
71 $lastOldId = 0;
72 $new = 1;
73 }
74 wfFreeResult( $res2 );
75 }
76 if( $lastCurId == 0 ) {
77 print "Uhhh, something wrong? No curid\n";
78 } else {
79 $sql3 = "UPDATE recentchanges SET rc_last_oldid=$lastOldId,rc_new=$new,rc_type=$new WHERE rc_cur_id={$lastCurId} AND rc_this_oldid={$obj->rc_this_oldid}";
80 wfQuery( $sql3, DB_WRITE );
81 $lastOldId = IntVal( $obj->rc_this_oldid );
82 }
83 }
84 wfFreeResult( $res );
85 }
86
87 ?>