Merge "Include the backtrace in the log for job exceptions"
[lhc/web/wiklou.git] / includes / RecentChange.php
index faad391..24db569 100644 (file)
@@ -96,10 +96,12 @@ class RecentChange {
        }
 
        /**
+        * @deprecated in 1.22
         * @param $row
         * @return RecentChange
         */
        public static function newFromCurRow( $row ) {
+               wfDeprecated( __METHOD__, '1.22' );
                $rc = new RecentChange;
                $rc->loadFromCurRow( $row );
                $rc->notificationtimestamp = false;
@@ -122,11 +124,12 @@ class RecentChange {
         *
         * @param array $conds of conditions
         * @param $fname Mixed: override the method name in profiling/logs
+        * @param $options Array Query options
         * @return RecentChange
         */
-       public static function newFromConds( $conds, $fname = __METHOD__ ) {
+       public static function newFromConds( $conds, $fname = __METHOD__, $options = array() ) {
                $dbr = wfGetDB( DB_SLAVE );
-               $row = $dbr->selectRow( 'recentchanges', self::selectFields(), $conds, $fname );
+               $row = $dbr->selectRow( 'recentchanges', self::selectFields(), $conds, $fname, $options );
                if ( $row !== false ) {
                        return self::newFromRow( $row );
                } else {
@@ -328,7 +331,7 @@ class RecentChange {
         * @return String
         */
        public static function cleanupForIRC( $text ) {
-               return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( "", "" ), $text ) );
+               return Sanitizer::decodeCharReferences( str_replace( array( "\n", "\r" ), array( " ", "" ), $text ) );
        }
 
        /**
@@ -409,6 +412,9 @@ class RecentChange {
                        ),
                        __METHOD__
                );
+               // Invalidate the page cache after the page has been patrolled
+               // to make sure that the Patrol link isn't visible any longer!
+               $this->getTitle()->invalidateCache();
                return $dbw->affectedRows();
        }
 
@@ -653,9 +659,11 @@ class RecentChange {
        /**
         * Makes a pseudo-RC entry from a cur row
         *
+        * @deprected in 1.22
         * @param $row
         */
        public function loadFromCurRow( $row ) {
+               wfDeprecated( __METHOD__, '1.22' );
                $this->mAttribs = array(
                        'rc_timestamp' => wfTimestamp( TS_MW, $row->rev_timestamp ),
                        'rc_cur_time' => $row->rev_timestamp,
@@ -825,6 +833,29 @@ class RecentChange {
                return ChangesList::showCharacterDifference( $old, $new );
        }
 
+       /**
+        * Purge expired changes from the recentchanges table
+        * @since 1.22
+        */
+       public static function purgeExpiredChanges() {
+               if ( wfReadOnly() ) {
+                       return;
+               }
+
+               $method = __METHOD__;
+               $dbw = wfGetDB( DB_MASTER );
+               $dbw->onTransactionIdle( function() use ( $dbw, $method ) {
+                       global $wgRCMaxAge;
+
+                       $cutoff = $dbw->timestamp( time() - $wgRCMaxAge );
+                       $dbw->delete(
+                               'recentchanges',
+                               array( 'rc_timestamp < ' . $dbw->addQuotes( $cutoff ) ),
+                               $method
+                       );
+               } );
+       }
+
        private static function checkIPAddress( $ip ) {
                global $wgRequest;
                if ( $ip ) {
@@ -839,4 +870,18 @@ class RecentChange {
                }
                return $ip;
        }
+
+       /**
+        * Check whether the given timestamp is new enough to have a RC row with a given tolerance
+        * as the recentchanges table might not be cleared out regularly (so older entries might exist)
+        * or rows which will be deleted soon shouldn't be included.
+        *
+        * @param $timestamp mixed MWTimestamp compatible timestamp
+        * @param $tolerance integer Tolerance in seconds
+        * @return bool
+        */
+       public static function isInRCLifespan( $timestamp, $tolerance = 0 ) {
+               global $wgRCMaxAge;
+               return wfTimestamp( TS_UNIX, $timestamp ) > time() - $tolerance - $wgRCMaxAge;
+       }
 }