* Add log events
authorAaron Schulz <aaron@users.mediawiki.org>
Tue, 1 Apr 2008 22:43:41 +0000 (22:43 +0000)
committerAaron Schulz <aaron@users.mediawiki.org>
Tue, 1 Apr 2008 22:43:41 +0000 (22:43 +0000)
* Play around with size stuff a little
* Use "__METHOD__"

maintenance/rebuildrecentchanges.inc

index 7686646..deef6a1 100644 (file)
@@ -11,12 +11,12 @@ function rebuildRecentChangesTable() {
        rebuildRecentChangesTablePass1();
        rebuildRecentChangesTablePass2();
        rebuildRecentChangesTablePass3();
+       rebuildRecentChangesTablePass4();
 }
 
 /** */
 function rebuildRecentChangesTablePass1()
 {
-       $fname = 'rebuildRecentChangesTablePass1';
        $dbw = wfGetDB( DB_MASTER );
 
        $dbw->delete( 'recentchanges', '*' );
@@ -54,7 +54,7 @@ function rebuildRecentChangesTablePass1()
                ), array(
                        'rev_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $cutoff ) ),
                        'rev_page=page_id'
-               ), $fname,
+               ), __METHOD__,
                array(), // INSERT options
                array( 'ORDER BY' => 'rev_timestamp DESC', 'LIMIT' => 5000 ) // SELECT options
        );
@@ -68,7 +68,7 @@ function rebuildRecentChangesTablePass2()
        print( "Updating links and size differences...\n" );
 
        # Fill in the rc_last_oldid field, which points to the previous edit
-       $sql = "SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM $recentchanges " .
+       $sql = "SELECT rc_cur_id,rc_this_oldid FROM $recentchanges " .
          "ORDER BY rc_cur_id,rc_timestamp";
        $res = $dbw->query( $sql, DB_MASTER );
 
@@ -79,20 +79,19 @@ function rebuildRecentChangesTablePass2()
                if( $obj->rc_cur_id != $lastCurId ) {
                        # Switch! Look up the previous last edit, if any
                        $lastCurId = intval( $obj->rc_cur_id );
-                       $emit = $obj->rc_timestamp;
-                       $sql2 = "SELECT rev_id, rev_len FROM $revision " .
+                       $sql2 = "SELECT rev_id,rev_len FROM $revision " .
                                "WHERE rev_page={$lastCurId} ".
-                               "AND rev_timestamp<'{$emit}' ORDER BY rev_timestamp DESC LIMIT 1";
+                               "AND rev_id < '{$obj->rc_this_oldid}' ORDER BY rev_id DESC LIMIT 1";
                        $res2 = $dbw->query( $sql2 );
                        if( $row = $dbw->fetchObject( $res2 ) ) {
-                               $lastOldId = intval( $row->rev_id );
-                               $lastSize = $row->rev_len; # Grab the last text size
-                               if(!is_numeric($lastSize)) $lastSize = 'NULL'; # Set last text size to null if not available
+                               $lastOldId = intval($row->rev_id);
+                               # Grab the last text size if available
+                               $lastSize = !is_null($row->rev_len) ? intval($row->rev_len) : 'NULL';
                        } else {
                                # No previous edit
                                $lastOldId = 0;
                                $lastSize = 'NULL';
-                               $new = 1;
+                               $new = 1; // probably true
                        }
                        $dbw->freeResult( $res2 );
                }
@@ -101,7 +100,7 @@ function rebuildRecentChangesTablePass2()
                } else {
                        # Grab the entry's text size
                        $size = $dbw->selectField( 'revision', 'rev_len', array('rev_id' => $obj->rc_this_oldid ) );
-                       $size = $size ? $size : 'NULL';
+                       $size = !is_null($size) ? intval($size) : 'NULL';
                        
                        $sql3 = "UPDATE $recentchanges SET rc_last_oldid=$lastOldId,rc_new=$new,rc_type=$new," .
                                "rc_old_len=$lastSize,rc_new_len=$size " .
@@ -115,6 +114,67 @@ function rebuildRecentChangesTablePass2()
 }
 
 function rebuildRecentChangesTablePass3()
+{
+       $dbw = wfGetDB( DB_MASTER );
+
+       print( "Loading from user, page, and logging tables...\n" );
+       
+       global $wgRCMaxAge;
+       // Some logs don't go in RC. This can't really detect all of those.
+       // At least do the basics logs for a standard install...
+       // FIXME: this needs to be maintained
+       $basicRCLogs = array( 
+               'block',
+               'protect',
+               'rights',
+               'delete',
+               'upload',
+               'move',
+               'import',
+               'merge' );
+       // Escape...blah blah
+       $selectLogs = array();
+       foreach( $basicRCLogs as $logtype ) {
+               $safetype = $dbw->strencode( $logtype );
+               $selectLogs[] = "'$safetype'";
+       }
+       
+       $cutoff = time() - $wgRCMaxAge;
+       $dbw->insertSelect( 'recentchanges', array( 'logging', 'page', 'user' ),
+               array(
+                       'rc_timestamp'  => 'log_timestamp',
+                       'rc_cur_time'   => 'log_timestamp',
+                       'rc_user'       => 'log_user',
+                       'rc_user_text'  => 'user_name',
+                       'rc_namespace'  => 'log_namespace',
+                       'rc_title'      => 'log_title',
+                       'rc_comment'    => 'log_comment',
+                       'rc_minor'      => 0,
+                       'rc_bot'        => 0,
+                       'rc_patrolled'  => 1,
+                       'rc_new'        => 0,
+                       'rc_this_oldid' => 0,
+                       'rc_last_oldid' => 0,
+                       'rc_type'       => RC_LOG,
+                       'rc_cur_id'     => 'page_id',
+                       'rc_log_type'   => 'log_type',
+                       'rc_log_action' => 'log_action',
+                       'rc_logid'      => 'log_id',
+                       'rc_params'     => 'log_params',
+                       'rc_deleted'    => 'log_deleted'
+               ), array(
+                       'log_timestamp > ' . $dbw->addQuotes( $dbw->timestamp( $cutoff ) ),
+                       'log_user=user_id',
+                       'log_namespace=page_namespace',
+                       'log_title=page_title',
+                       'log_type IN(' . implode(',',$selectLogs) . ')'
+               ), __METHOD__,
+               array(), // INSERT options
+               array( 'ORDER BY' => 'log_timestamp DESC', 'LIMIT' => 5000 ) // SELECT options
+       );
+}
+
+function rebuildRecentChangesTablePass4()
 {
        global $wgGroupPermissions, $wgUseRCPatrol;