Page move undo feature
[lhc/web/wiklou.git] / includes / RecentChange.php
index e35775b..6502d1f 100644 (file)
@@ -24,12 +24,12 @@ define( 'RC_MOVE_OVER_REDIRECT', 4);
  *     rc_title        non-prefixed db key
  *     rc_type         is new entry, used to determine whether updating is necessary
  *     rc_minor        is minor
- *     rc_cur_id       id of associated cur entry
+ *     rc_cur_id       page_id of associated page entry
  *     rc_user         user id who made the entry
  *     rc_user_text    user name who made the entry
  *     rc_comment      edit summary
- *     rc_this_oldid   old_id associated with this entry (or zero)
- *     rc_last_oldid   old_id associated with the entry before this one (or zero)
+ *     rc_this_oldid   rev_id associated with this entry (or zero)
+ *     rc_last_oldid   rev_id associated with the entry before this one (or zero)
  *     rc_bot          is bot, hidden
  *     rc_ip           IP address of the user in dotted quad notation
  *     rc_new          obsolete, use rc_type==RC_NEW
@@ -40,6 +40,10 @@ define( 'RC_MOVE_OVER_REDIRECT', 4);
  *     lastTimestamp   timestamp of previous entry, used in WHERE clause during update
  *     lang            the interwiki prefix, automatically set in save()
  * 
+ * temporary:          not stored in the database
+ *      notificationtimestamp
+ *      numberofWatchingusers
+ *
  * @todo document functions and variables
  * @package MediaWiki
  */
@@ -61,6 +65,8 @@ class RecentChange
        {
                $rc = new RecentChange;
                $rc->loadFromCurRow( $row );
+               $rc->notificationtimestamp = false;
+               $rc->numberofWatchingusers = false;
                return $rc;
        }
 
@@ -76,7 +82,7 @@ class RecentChange
                $this->mExtra = $extra;
        }
 
-       function getTitle()
+       function &getTitle()
        {
                if ( $this->mTitle === false ) {
                        $this->mTitle = Title::makeTitle( $this->mAttribs['rc_namespace'], $this->mAttribs['rc_title'] );
@@ -114,7 +120,7 @@ class RecentChange
                $this->mAttribs['rc_cur_time']=$dbw->timestamp($this->mAttribs['rc_cur_time']);
 
                # Insert new row
-               $dbw->insertArray( 'recentchanges', $this->mAttribs, $fname );
+               $dbw->insert( 'recentchanges', $this->mAttribs, $fname );
 
                # Update old rows, if necessary
                if ( $this->mAttribs['rc_type'] == RC_EDIT ) {
@@ -125,19 +131,25 @@ class RecentChange
                        $now = $this->mAttribs['rc_timestamp'];
                        $curId = $this->mAttribs['rc_cur_id'];
 
-                       # Update rc_this_oldid for the entries which were current
-                       $dbw->updateArray( 'recentchanges',
-                               array( /* SET */
-                                       'rc_this_oldid' => $oldid
-                               ), array( /* WHERE */
-                                       'rc_namespace' => $ns,
-                                       'rc_title' => $title,
-                                       'rc_timestamp' => $dbw->timestamp($lastTime)
-                               ), $fname
-                       );
+                       # Don't bother looking for entries that have probably
+                       # been purged, it just locks up the indexes needlessly.
+                       global $wgRCMaxAge;
+                       $age = time() - wfTimestamp( TS_UNIX, $lastTime );
+                       if( $age < $wgRCMaxAge ) {
+                               # Update rc_this_oldid for the entries which were current
+                               $dbw->update( 'recentchanges',
+                                       array( /* SET */
+                                               'rc_this_oldid' => $oldid
+                                       ), array( /* WHERE */
+                                               'rc_namespace' => $ns,
+                                               'rc_title' => $title,
+                                               'rc_timestamp' => $dbw->timestamp( $lastTime )
+                                       ), $fname
+                               );
+                       }
 
                        # Update rc_cur_time
-                       $dbw->updateArray( 'recentchanges', array( 'rc_cur_time' => $now ),
+                       $dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
                                array( 'rc_cur_id' => $curId ), $fname );
                }
 
@@ -159,7 +171,7 @@ class RecentChange
 
                $dbw =& wfGetDB( DB_MASTER );
 
-               $dbw->updateArray( 'recentchanges',
+               $dbw->update( 'recentchanges',
                        array( /* SET */
                                'rc_patrolled' => 1
                        ), array( /* WHERE */
@@ -199,6 +211,7 @@ class RecentChange
                        'rc_moved_to_ns'        => 0,
                        'rc_moved_to_title'     => '',
                        'rc_ip' => $ip,
+                       'rc_patrolled' => 0,
                        'rc_new'        => 0 # obsolete
                );
 
@@ -239,6 +252,7 @@ class RecentChange
                        'rc_moved_to_ns'    => 0,
                        'rc_moved_to_title' => '',
                        'rc_ip'             => $ip,
+                       'rc_patrolled'      => 0,
                        'rc_new'        => 1 # obsolete
                );
 
@@ -341,16 +355,16 @@ class RecentChange
        function loadFromCurRow( $row )
        {
                $this->mAttribs = array(
-                       'rc_timestamp' => $row->cur_timestamp,
-                       'rc_cur_time' => $row->cur_timestamp,
-                       'rc_user' => $row->cur_user,
-                       'rc_user_text' => $row->cur_user_text,
-                       'rc_namespace' => $row->cur_namespace,
-                       'rc_title' => $row->cur_title,
-                       'rc_comment' => $row->cur_comment,
-                       'rc_minor' => !!$row->cur_minor_edit,
-                       'rc_type' => $row->cur_is_new ? RC_NEW : RC_EDIT,
-                       'rc_cur_id' => $row->cur_id,
+                       'rc_timestamp' => $row->rev_timestamp,
+                       'rc_cur_time' => $row->rev_timestamp,
+                       'rc_user' => $row->rev_user,
+                       'rc_user_text' => $row->rev_user_text,
+                       'rc_namespace' => $row->page_namespace,
+                       'rc_title' => $row->page_title,
+                       'rc_comment' => $row->rev_comment,
+                       'rc_minor' => !!$row->rev_minor_edit,
+                       'rc_type' => $row->page_is_new ? RC_NEW : RC_EDIT,
+                       'rc_cur_id' => $row->page_id,
                        'rc_this_oldid' => 0,
                        'rc_last_oldid' => 0,
                        'rc_bot'        => 0,
@@ -359,7 +373,7 @@ class RecentChange
                        'rc_ip' => '',
                        'rc_patrolled' => '1',  # we can't support patrolling on the Watchlist
                                                # currently because it uses cur, not recentchanges
-                       'rc_new' => $row->cur_is_new # obsolete
+                       'rc_new' => $row->page_is_new # obsolete
                );
 
                $this->mExtra = array();