no need for position:absolute
[lhc/web/wiklou.git] / maintenance / rebuildrecentchanges.inc
1 <?php
2 /**
3 * Rebuild recent changes table.
4 *
5 * @todo document
6 * @package MediaWiki
7 * @subpackage Maintenance
8 */
9
10 /** */
11 function rebuildRecentChangesTablePass1()
12 {
13 $fname = 'rebuildRecentChangesTablePass1';
14 $dbw =& wfGetDB( DB_MASTER );
15 extract( $dbw->tableNames( 'recentchanges', 'cur', 'old' ) );
16
17 $dbw->delete( 'recentchanges', '*' );
18
19 print( "Loading from CUR table...\n" );
20
21 $dbw->insertSelect( 'recentchanges', 'cur',
22 array(
23 'rc_timestamp' => 'cur_timestamp',
24 'rc_cur_time' => 'cur_timestamp',
25 'rc_user' => 'cur_user',
26 'rc_user_text' => 'cur_user_text',
27 'rc_namespace' => 'cur_namespace',
28 'rc_title' => 'cur_title',
29 'rc_comment' => 'cur_comment',
30 'rc_minor' => 'cur_minor_edit',
31 'rc_bot' => 0,
32 'rc_new' => 'cur_is_new',
33 'rc_cur_id' => 'cur_id',
34 'rc_this_oldid' => 0,
35 'rc_last_oldid' => 0,
36 'rc_type' => $dbw->conditional( 'cur_is_new != 0', RC_NEW, RC_EDIT ),
37 ), '*', $fname, array( 'ORDER BY' => 'cur_timestamp DESC', 'LIMIT' => 5000 )
38 );
39
40 print( "Loading from OLD table...\n" );
41
42 $sql = "INSERT INTO $recentchanges (rc_timestamp,rc_cur_time,rc_user," .
43 "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_bot,rc_new," .
44 "rc_cur_id,rc_this_oldid,rc_last_oldid,rc_type) SELECT old_timestamp,cur_timestamp," .
45 "old_user,old_user_text,old_namespace,old_title,old_comment," .
46 "old_minor_edit,0,0,cur_id,old_id,0,0 FROM $old,$cur " .
47 "WHERE old_namespace=cur_namespace AND old_title=cur_title ORDER BY old_timestamp DESC " .
48 "LIMIT 5000";
49 $dbw->query( $sql );
50
51 $sql = "SELECT rc_timestamp FROM $recentchanges " .
52 "ORDER BY rc_timestamp DESC" . $dbw->limitResult( 1, 5000 );
53 $res = $dbw->query( $sql );
54 $obj = $dbw->fetchObject( $res );
55 if( $obj ) {
56 $ts = $obj->rc_timestamp;
57
58 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$ts}'";
59 $dbw->query( $sql );
60 }
61 }
62
63 function rebuildRecentChangesTablePass2()
64 {
65 $dbw =& wfGetDB( DB_MASTER );
66 extract( $dbw->tableNames( 'recentchanges', 'cur', 'old' ) );
67
68 $ns = $id = $count = 0;
69 $title = $ct = "";
70
71 print( "Updating links...\n" );
72
73 # Fill in the rc_last_oldid field, which points to the previous edit
74 #
75 $sql = "SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM $recentchanges " .
76 "ORDER BY rc_cur_id,rc_timestamp";
77 $res = $dbw->query( $sql, DB_MASTER );
78
79 $lastCurId = 0;
80 $lastOldId = 0;
81 while ( $obj = $dbw->fetchObject( $res ) ) {
82 $new = 0;
83 if( $obj->rc_cur_id != $lastCurId ) {
84 # Switch! Look up the previous last edit, if any
85 $lastCurId = IntVal( $obj->rc_cur_id );
86 $emit = $obj->rc_timestamp;
87 $sql2 = "SELECT old_id FROM $old,$cur " .
88 "WHERE old_namespace=cur_namespace AND old_title=cur_title AND cur_id={$lastCurId} ".
89 "AND old_timestamp<'{$emit}' ORDER BY old_timestamp DESC LIMIT 1";
90 $res2 = $dbw->query( $sql2 );
91 if( $row = $dbw->fetchObject( $res2 ) ) {
92 $lastOldId = IntVal( $row->old_id );
93 } else {
94 # No previous edit
95 $lastOldId = 0;
96 $new = 1;
97 }
98 $dbw->freeResult( $res2 );
99 }
100 if( $lastCurId == 0 ) {
101 print "Uhhh, something wrong? No curid\n";
102 } else {
103 $sql3 = "UPDATE $recentchanges SET rc_last_oldid=$lastOldId,rc_new=$new,rc_type=$new " .
104 "WHERE rc_cur_id={$lastCurId} AND rc_this_oldid={$obj->rc_this_oldid}";
105 $dbw->query( $sql3 );
106 $lastOldId = IntVal( $obj->rc_this_oldid );
107 }
108 }
109 $dbw->freeResult( $res );
110 }
111
112 ?>