Index: maintenance/language/messages.inc =================================================================== --- maintenance/language/messages.inc (revision 50707) +++ maintenance/language/messages.inc (working copy) @@ -261,7 +261,9 @@ 'pagetitle', 'pagetitle-view-mainpage', 'retrievedfrom', + 'youhavenewmessage', 'youhavenewmessages', + 'newmessagelink', 'newmessageslink', 'newmessagesdifflink', 'youhavenewmessagesmulti', Index: includes/User.php =================================================================== --- includes/User.php (revision 50707) +++ includes/User.php (working copy) @@ -1472,7 +1472,7 @@ /** * Check if the user has new messages. - * @return \bool True if the user has new messages + * @return \int Number of new messages */ function getNewtalk() { $this->load(); @@ -1500,7 +1500,7 @@ } } - return (bool)$this->mNewtalk; + return $this->mNewtalk; } /** @@ -1509,14 +1509,15 @@ */ function getNewMessageLinks() { $talks = array(); - if (!wfRunHooks('UserRetrieveNewTalks', array(&$this, &$talks))) + if ( !wfRunHooks( 'UserRetrieveNewTalks', array( &$this, &$talks ) ) ) return $talks; - if (!$this->getNewtalk()) + $count = $this->getNewtalk(); + if ( !$count ) return array(); $up = $this->getUserPage(); $utp = $up->getTalkPage(); - return array(array("wiki" => wfWikiID(), "link" => $utp->getLocalURL())); + return array( array( 'wiki' => wfWikiID(), 'link' => $utp->getLocalURL(), 'count' => $count ) ); } @@ -1527,7 +1528,7 @@ * @param $field \string 'user_ip' for anonymous users, 'user_id' otherwise * @param $id \types{\string,\int} User's IP address for anonymous users, User ID otherwise * @param $fromMaster \bool true to fetch from the master, false for a slave - * @return \bool True if the user has new messages + * @return \int Number of new messages * @private */ function checkNewtalk( $field, $id, $fromMaster = false ) { @@ -1536,9 +1537,11 @@ } else { $db = wfGetDB( DB_SLAVE ); } - $ok = $db->selectField( 'user_newtalk', $field, + $res = $db->select( 'user_newtalk', $field, array( $field => $id ), __METHOD__ ); - return $ok !== false; + $rowNum = $db->numRows( $res ); + $db->freeResult( $res ); + return $rowNum; } /** Index: includes/Title.php =================================================================== --- includes/Title.php (revision 50707) +++ includes/Title.php (working copy) @@ -3225,6 +3225,26 @@ } /** + * Get the revision ID of the previous revision at certain offset + * + * @param $revId \type{\int} Revision ID + * @param $offset \type{\int} How many revisions before $revId + * @param $flags \type{\int} GAID_FOR_UPDATE + * @return \twotypes{\int,\bool} Old revision ID, or FALSE if none exists + */ + public function getPreviousRevisionIDAtOffset( $revId, $offset, $flags=0 ) { + $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB( DB_MASTER ) : wfGetDB( DB_SLAVE ); + return $db->selectField( 'revision', 'rev_id', + array( + 'rev_page' => $this->getArticleId($flags), + 'rev_id < ' . intval( $revId ) + ), + __METHOD__, + array( 'ORDER BY' => 'rev_id DESC', 'LIMIT' => 1, 'OFFSET' => intval( $offset ) - 1 ) + ); + } + + /** * Get the revision ID of the next revision * * @param $revId \type{\int} Revision ID. Get the revision that was after this one. Index: includes/SkinTemplate.php =================================================================== --- includes/SkinTemplate.php (revision 50707) +++ includes/SkinTemplate.php (working copy) @@ -295,18 +295,35 @@ $usertitle = $this->mUser->getUserPage(); $usertalktitle = $usertitle->getTalkPage(); if( !$usertalktitle->equals( $this->mTitle ) ) { - $ntl = wfMsg( 'youhavenewmessages', - $this->makeKnownLinkObj( - $usertalktitle, - wfMsgHtml( 'newmessageslink' ), - 'redirect=no' - ), - $this->makeKnownLinkObj( - $usertalktitle, - wfMsgHtml( 'newmessagesdifflink' ), - 'diff=cur' - ) - ); + if ( $newtalks[0]['count'] == 1 ) { + $ntl = wfMsg( 'youhavenewmessage', + $this->makeKnownLinkObj( + $usertalktitle, + wfMsgHtml( 'newmessagelink' ), + 'redirect=no' + ), + $this->makeKnownLinkObj( + $usertalktitle, + wfMsgHtml( 'newmessagesdifflink' ), + 'diff=cur' + ) + ); + } else { + $talkoldid = $usertalktitle->getPreviousRevisionIDAtOffset( $usertalktitle->getLatestRevID(), $newtalks[0]['count'] ); + $ntl = wfMsg( 'youhavenewmessages', + $newtalks[0]['count'], + $this->makeKnownLinkObj( + $usertalktitle, + wfMsgHtml( 'newmessageslink' ), + 'redirect=no' + ), + $this->makeKnownLinkObj( + $usertalktitle, + wfMsgHtml( 'newmessagesdifflink' ), + 'diff=' . $usertalktitle->getLatestRevID() . '&oldid=' . $talkoldid + ) + ); + } # Disable Cache $out->setSquidMaxage( 0 ); } @@ -1111,4 +1128,4 @@ $msg = $this->translator->translate( $str ); return ( $msg != '-' ) && ( $msg != '' ); # ???? } -} \ No newline at end of file +} Index: includes/Skin.php =================================================================== --- includes/Skin.php (revision 50707) +++ includes/Skin.php (working copy) @@ -992,13 +992,22 @@ wfMsg( 'currentrev' ) ); } - if ( $wgUser->getNewtalk() ) { + $count = $wgUser->getNewtalk(); + $usertalktitle = $wgUser->getTalkPage(); + if ( $count ) { # do not show "You have new messages" text when we are viewing our # own talk page - if( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) { - $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' ); - $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' ); - $s[] = ''. wfMsg( 'youhavenewmessages', $tl, $dl ) . ''; + if( !$this->mTitle->equals( $usertalktitle ) ) { + if ( $count == 1 ) { + $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagelink' ), 'redirect=no' ); + $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' ); + $s[] = ''. wfMsg( 'youhavenewmessage', $tl, $dl ) . ''; + } else { + $talkoldid = $usertalktitle->getPreviousRevisionIDAtOffset( $usertalktitle->getLatestRevID(), $count ); + $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' ); + $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=' . $usertalktitle->getLatestRevID() . '&oldid=' . $talkoldid ); + $s[] = ''. wfMsg( 'youhavenewmessages', $count, $tl, $dl ) . ''; + } # disable caching $wgOut->setSquidMaxage( 0 ); $wgOut->enableClientCache( false ); Index: languages/messages/MessagesEn.php =================================================================== --- languages/messages/MessagesEn.php (revision 50707) +++ languages/messages/MessagesEn.php (working copy) @@ -742,7 +742,9 @@ 'pagetitle' => '$1 - {{SITENAME}}', # only translate this message to other languages if you have to change it 'pagetitle-view-mainpage' => '{{SITENAME}}', # only translate this message to other languages if you have to change it 'retrievedfrom' => 'Retrieved from "$1"', -'youhavenewmessages' => 'You have $1 ($2).', +'youhavenewmessage' => 'You have $1 ($2).', +'youhavenewmessages' => 'You have $1 $2 ($3).', +'newmessagelink' => 'a new message', 'newmessageslink' => 'new messages', 'newmessagesdifflink' => 'last change', 'youhavenewmessagesmulti' => 'You have new messages on $1',