(bug 34264) Add id="t-print" to the print toolbox link.
[lhc/web/wiklou.git] / includes / User.php
index 51877f8..d2ebabb 100644 (file)
@@ -119,6 +119,7 @@ class User {
                'delete',
                'deletedhistory',
                'deletedtext',
+               'deletelogentry',
                'deleterevision',
                'edit',
                'editinterface',
@@ -1387,11 +1388,11 @@ class User {
                                $ipList = gethostbynamel( $host );
 
                                if( $ipList ) {
-                                       wfDebug( "Hostname $host is {$ipList[0]}, it's a proxy says $base!\n" );
+                                       wfDebugLog( 'dnsblacklist', "Hostname $host is {$ipList[0]}, it's a proxy says $base!\n" );
                                        $found = true;
                                        break;
                                } else {
-                                       wfDebug( "Requested $host, not found in $base.\n" );
+                                       wfDebugLog( 'dnsblacklist', "Requested $host, not found in $base.\n" );
                                }
                        }
                }
@@ -1788,14 +1789,20 @@ class User {
         */
        public function getNewMessageLinks() {
                $talks = array();
-               if( !wfRunHooks( 'UserRetrieveNewTalks', array( &$this, &$talks ) ) )
+               if( !wfRunHooks( 'UserRetrieveNewTalks', array( &$this, &$talks ) ) ) {
                        return $talks;
-
-               if( !$this->getNewtalk() )
+               } elseif( !$this->getNewtalk() ) {
                        return array();
-               $up = $this->getUserPage();
-               $utp = $up->getTalkPage();
-               return array( array( 'wiki' => wfWikiID(), 'link' => $utp->getLocalURL() ) );
+               }
+               $utp = $this->getTalkPage();
+               $dbr = wfGetDB( DB_SLAVE );
+               // Get the "last viewed rev" timestamp from the oldest message notification
+               $timestamp = $dbr->selectField( 'user_newtalk',
+                       'MIN(user_last_timestamp)',
+                       $this->isAnon() ? array( 'user_ip' => $this->getName() ) : array( 'user_id' => $this->getID() ),
+                       __METHOD__ );
+               $rev = $timestamp ? Revision::loadFromTimestamp( $dbr, $utp, $timestamp ) : null;
+               return array( array( 'wiki' => wfWikiID(), 'link' => $utp->getLocalURL(), 'rev' => $rev ) );
        }
 
        /**
@@ -1822,12 +1829,17 @@ class User {
         * Add or update the new messages flag
         * @param $field String 'user_ip' for anonymous users, 'user_id' otherwise
         * @param $id String|Int User's IP address for anonymous users, User ID otherwise
+        * @param $curRev Revision new, as yet unseen revision of the user talk page. Ignored if null.
         * @return Bool True if successful, false otherwise
         */
-       protected function updateNewtalk( $field, $id ) {
+       protected function updateNewtalk( $field, $id, $curRev = null ) {
+               // Get timestamp of the talk page revision prior to the current one
+               $prevRev = $curRev ? $curRev->getPrevious() : false;
+               $ts = $prevRev ? $prevRev->getTimestamp() : null;
+               // Mark the user as having new messages since this revision
                $dbw = wfGetDB( DB_MASTER );
                $dbw->insert( 'user_newtalk',
-                       array( $field => $id ),
+                       array( $field => $id, 'user_last_timestamp' => $dbw->timestampOrNull( $ts ) ),
                        __METHOD__,
                        'IGNORE' );
                if ( $dbw->affectedRows() ) {
@@ -1862,8 +1874,9 @@ class User {
        /**
         * Update the 'You have new messages!' status.
         * @param $val Bool Whether the user has new messages
+        * @param $curRev Revision new, as yet unseen revision of the user talk page. Ignored if null or !$val.
         */
-       public function setNewtalk( $val ) {
+       public function setNewtalk( $val, $curRev = null ) {
                if( wfReadOnly() ) {
                        return;
                }
@@ -1881,7 +1894,7 @@ class User {
                global $wgMemc;
 
                if( $val ) {
-                       $changed = $this->updateNewtalk( $field, $id );
+                       $changed = $this->updateNewtalk( $field, $id, $curRev );
                } else {
                        $changed = $this->deleteNewtalk( $field, $id );
                }
@@ -2288,9 +2301,11 @@ class User {
                $this->loadOptions();
 
                // Explicitly NULL values should refer to defaults
-               global $wgDefaultUserOptions;
-               if( is_null( $val ) && isset( $wgDefaultUserOptions[$oname] ) ) {
-                       $val = $wgDefaultUserOptions[$oname];
+               if( is_null( $val ) ) {
+                       $defaultOption = self::getDefaultOption( $oname );
+                       if( !is_null( $defaultOption ) ) {
+                               $val = $defaultOption;
+                       }
                }
 
                $this->mOptions[$oname] = $val;
@@ -2712,8 +2727,7 @@ class User {
                        $force = 'force';
                }
 
-               $wi = WatchedItem::fromUserTitle( $this, $title );
-               $wi->resetNotificationTimestamp( $force );
+               $this->getWatchedItem( $title )->resetNotificationTimestamp( $force );
        }
 
        /**