]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - maintenance/rebuildrecentchanges.inc
MediaWiki 1.5.8 (initial commit)
[autoinstallsdev/mediawiki.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 page and revision tables...\n" );
20         
21         global $wgRCMaxAge;
22         $cutoff = time() - $wgRCMaxAge;
23         $dbw->insertSelect( 'recentchanges', array( 'page', 'revision' ),
24                 array(
25                         'rc_timestamp'  => 'rev_timestamp',
26                         'rc_cur_time'   => 'rev_timestamp',
27                         'rc_user'       => 'rev_user',
28                         'rc_user_text'  => 'rev_user_text',
29                         'rc_namespace'  => 'page_namespace',
30                         'rc_title'      => 'page_title',
31                         'rc_comment'    => 'rev_comment',
32                         'rc_minor'      => 'rev_minor_edit',
33                         'rc_bot'        => 0,
34                         'rc_new'        => 'page_is_new',
35                         'rc_cur_id'     => 'page_id',
36                         'rc_this_oldid' => 'rev_id',
37                         'rc_last_oldid' => 0, // is this ok?
38                         'rc_type'       => $dbw->conditional( 'page_is_new != 0', RC_NEW, RC_EDIT ),
39                 ), array(
40                         'rev_timestamp > ' . $dbw->timestamp( $cutoff ),
41                         'rev_page=page_id'
42                 ), $fname, array( 'ORDER BY' => 'rev_timestamp', 'LIMIT' => 5000 )
43         );
44 }
45
46 function rebuildRecentChangesTablePass2()
47 {
48         $dbw =& wfGetDB( DB_MASTER );
49         extract( $dbw->tableNames( 'recentchanges', 'revision' ) );
50
51         $ns = $id = $count = 0;
52         $title = $ct =  "";
53
54         print( "Updating links...\n" );
55
56         # Fill in the rc_last_oldid field, which points to the previous edit
57         #
58         $sql = "SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM $recentchanges " .
59           "ORDER BY rc_cur_id,rc_timestamp";
60         $res = $dbw->query( $sql, DB_MASTER );
61
62         $lastCurId = 0;
63         $lastOldId = 0;
64         while ( $obj = $dbw->fetchObject( $res ) ) {
65                 $new = 0;
66                 if( $obj->rc_cur_id != $lastCurId ) {
67                         # Switch! Look up the previous last edit, if any
68                         $lastCurId = IntVal( $obj->rc_cur_id );
69                         $emit = $obj->rc_timestamp;
70                         $sql2 = "SELECT rev_id FROM $revision " .
71                                 "WHERE rev_page={$lastCurId} ".
72                                 "AND rev_timestamp<'{$emit}' ORDER BY rev_timestamp DESC LIMIT 1";
73                         $res2 = $dbw->query( $sql2 );
74                         if( $row = $dbw->fetchObject( $res2 ) ) {
75                                 $lastOldId = intval( $row->rev_id );
76                         } else {
77                                 # No previous edit
78                                 $lastOldId = 0;
79                                 $new = 1;
80                         }
81                         $dbw->freeResult( $res2 );
82                 }
83                 if( $lastCurId == 0 ) {
84                         print "Uhhh, something wrong? No curid\n";
85                 } else {
86                         $sql3 = "UPDATE $recentchanges SET rc_last_oldid=$lastOldId,rc_new=$new,rc_type=$new " .
87                                 "WHERE rc_cur_id={$lastCurId} AND rc_this_oldid={$obj->rc_this_oldid}";
88                         $dbw->query( $sql3 );
89                         $lastOldId = IntVal( $obj->rc_this_oldid );
90                 }
91         }
92         $dbw->freeResult( $res );
93 }
94
95 ?>