Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

rebuildrecentchanges.inc

Go to the documentation of this file.
00001 <?php 00002 00003 # Rebuild recent changes table. 00004 # 00005 00006 function rebuildRecentChangesTablePass1() 00007 { 00008 $sql = "DELETE FROM recentchanges"; 00009 wfQuery( $sql, DB_WRITE ); 00010 00011 print( "Loading from CUR table...\n" ); 00012 00013 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,rc_user," . 00014 "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_bot,rc_new," . 00015 "rc_cur_id,rc_this_oldid,rc_last_oldid) SELECT cur_timestamp," . 00016 "cur_timestamp,cur_user,cur_user_text,cur_namespace,cur_title," . 00017 "cur_comment,cur_minor_edit,0,cur_is_new,cur_id,0,0 FROM cur " . 00018 "ORDER BY inverse_timestamp LIMIT 5000"; 00019 wfQuery( $sql, DB_WRITE ); 00020 00021 print( "Loading from OLD table...\n" ); 00022 00023 $sql = "INSERT INTO recentchanges (rc_timestamp,rc_cur_time,rc_user," . 00024 "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_bot,rc_new," . 00025 "rc_cur_id,rc_this_oldid,rc_last_oldid) SELECT old_timestamp,cur_timestamp," . 00026 "old_user,old_user_text,old_namespace,old_title,old_comment," . 00027 "old_minor_edit,0,0,cur_id,old_id,0 FROM old,cur " . 00028 "WHERE old_namespace=cur_namespace AND old_title=cur_title ORDER BY old.inverse_timestamp " . 00029 "LIMIT 5000"; 00030 wfQuery( $sql, DB_WRITE ); 00031 00032 $sql = "SELECT rc_timestamp FROM recentchanges " . 00033 "ORDER BY rc_timestamp DESC LIMIT 5000,1"; 00034 $res = wfQuery( $sql, DB_WRITE ); 00035 $obj = wfFetchObject( $res ); 00036 $ts = $obj->rc_timestamp; 00037 00038 $sql = "DELETE FROM recentchanges WHERE rc_timestamp < '{$ts}'"; 00039 wfQuery( $sql, DB_WRITE ); 00040 } 00041 00042 function rebuildRecentChangesTablePass2() 00043 { 00044 $ns = $id = $count = 0; 00045 $title = $ct = ""; 00046 00047 print( "Updating links...\n" ); 00048 00049 # Fill in the rc_last_oldid field, which points to the previous edit 00050 # 00051 $sql = "SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM recentchanges " . 00052 "ORDER BY rc_cur_id,rc_timestamp"; 00053 $res = wfQuery( $sql, DB_WRITE ); 00054 00055 $lastCurId = 0; 00056 $lastOldId = 0; 00057 while ( $obj = wfFetchObject( $res ) ) { 00058 $new = 0; 00059 if( $obj->rc_cur_id != $lastCurId ) { 00060 # Switch! Look up the previous last edit, if any 00061 $lastCurId = IntVal( $obj->rc_cur_id ); 00062 $emit = wfInvertTimestamp( $obj->rc_timestamp ); 00063 $sql2 = "SELECT old_id FROM old,cur " . 00064 "WHERE old_namespace=cur_namespace AND old_title=cur_title AND cur_id={$lastCurId} ". 00065 "AND old.inverse_timestamp>'{$emit}' ORDER BY old.inverse_timestamp LIMIT 1"; 00066 $res2 = wfQuery( $sql2, DB_WRITE ); 00067 if( $row = wfFetchObject( $res2 ) ) { 00068 $lastOldId = IntVal( $row->old_id ); 00069 } else { 00070 # No previous edit 00071 $lastOldId = 0; 00072 $new = 1; 00073 } 00074 wfFreeResult( $res2 ); 00075 } 00076 if( $lastCurId == 0 ) { 00077 print "Uhhh, something wrong? No curid\n"; 00078 } else { 00079 $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}"; 00080 wfQuery( $sql3, DB_WRITE ); 00081 $lastOldId = IntVal( $obj->rc_this_oldid ); 00082 } 00083 } 00084 wfFreeResult( $res ); 00085 } 00086 00087 ?>

Generated on Tue Jun 29 23:40:06 2004 for Mediawiki by doxygen 1.3.7