r54628 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54627‎ | r54628 | r54629 >
Date:10:37, 8 August 2009
Author:jan
Status:reverted (Comments)
Tags:
Comment:
(fixes for r54590 & bug 20103) Use now only one query and add number to messages "youhavenewmessages" and "mytalk"
Modified paths:
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/User.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/User.php
@@ -216,6 +216,8 @@
217217 //@}
218218
219219 static $idCacheByName = array();
 220+
 221+ var $mNewtalknumber;
220222
221223 /**
222224 * Lightweight constructor for an anonymous user.
@@ -1546,9 +1548,10 @@
15471549 } else {
15481550 $db = wfGetDB( DB_SLAVE );
15491551 }
1550 - $ok = $db->selectField( 'user_newtalk', $field,
 1552+ $query = $db->select( 'user_newtalk', $field,
15511553 array( $field => $id ), __METHOD__ );
1552 - return $ok !== false;
 1554+ $this->mNewtalknumber = $ok = $db->numRows( $query );
 1555+ return $ok !== 0;
15531556 }
15541557
15551558 /**
@@ -1631,6 +1634,15 @@
16321635 $this->invalidateCache();
16331636 }
16341637 }
 1638+
 1639+ /**
 1640+ * Return the number of new messages
 1641+ * @return \int The number of new messages
 1642+ */
 1643+ public function getNewtalkNumber() {
 1644+ global $wgLang;
 1645+ return $wgLang->formatNum( $this->mNewtalknumber );
 1646+ }
16351647
16361648 /**
16371649 * Generate a current or new-future timestamp to be stored in the
Index: trunk/phase3/includes/SkinTemplate.php
@@ -319,11 +319,14 @@
320320 array( 'diff' => 'cur' ),
321321 array( 'known', 'noclasses' )
322322 );
 323+
 324+ $newmessagesnumber = $wgUser->getNewtalkNumber();
323325
324326 $ntl = wfMsg(
325327 'youhavenewmessages',
326328 $newmessageslink,
327 - $newmessagesdifflink
 329+ $newmessagesdifflink,
 330+ $newmessagesnumber
328331 );
329332 # Disable Cache
330333 $out->setSquidMaxage( 0 );
@@ -532,31 +535,24 @@
533536 );
534537 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
535538 if ( $wgUser->getNewtalk() ) {
536 - # do not show "(!)" text when we are viewing our
 539+ # do not show text when we are viewing our
537540 # own talk page
538 - if( !$title->equals( $wgUser->getTalkPage() ) ) {
539 - $field = ( $wgUser->getID() == 0 )? 'user_ip' : 'user_id';
540 - $id = ( $wgUser->getID() == 0 )? $wgUser->getName() : $wgUser->getID();
 541+ if( !$title->equals( $wgUser->getTalkPage() ) ) {
 542+ $newtalk = $wgUser->getNewtalkNumber();
541543
542 - $db = wfGetDB( DB_SLAVE );
543 - $query = $db->select( 'user_newtalk', $field, array( $field => $id ) );
544 - $num = $db->numRows( $query );
545 -
546 - $text = '('.$wgLang->formatNum( $num ).')';
547 -
548544 # disable caching
549545 $wgOut->setSquidMaxage( 0 );
550546 $wgOut->enableClientCache( false );
551547 }
552548 else {
553 - $text = '';
 549+ $newtalk = 0;
554550 }
555551 }
556552 else {
557 - $text = '';
 553+ $newtalk = 0;
558554 }
559555 $personal_urls['mytalk'] = array(
560 - 'text' => wfMsg( 'mytalk' ).$text,
 556+ 'text' => wfMsg( 'mytalk', $newtalk ),
561557 'href' => &$usertalkUrlDetails['href'],
562558 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
563559 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -751,7 +751,7 @@
752752 'cancel' => 'Cancel',
753753 'moredotdotdot' => 'More...',
754754 'mypage' => 'My page',
755 -'mytalk' => 'My talk',
 755+'mytalk' => 'My talk ($1)',
756756 'anontalk' => 'Talk for this IP',
757757 'navigation' => 'Navigation',
758758 'and' => ' and',
@@ -894,7 +894,7 @@
895895 'pagetitle' => '$1 - {{SITENAME}}', # only translate this message to other languages if you have to change it
896896 'pagetitle-view-mainpage' => '{{SITENAME}}', # only translate this message to other languages if you have to change it
897897 'retrievedfrom' => 'Retrieved from "$1"',
898 -'youhavenewmessages' => 'You have $1 ($2).',
 898+'youhavenewmessages' => 'You have $3 $1 ($2).',
899899 'newmessageslink' => 'new messages',
900900 'newmessagesdifflink' => 'last change',
901901 'youhavenewmessagesmulti' => 'You have new messages on $1',

Follow-up revisions

RevisionCommit summaryAuthorDate
r54633(fixes for r54628) Add PLURAL to "last change" messagejan16:02, 8 August 2009
r54714(r54628 + r54633) Display (...) only if there new messagesjan11:29, 10 August 2009
r54733Pull back r54590, r54591, r54628, r54633, r54636, r54714 "Add after the link ...brion19:03, 10 August 2009
r54740Localisation updates for core messages from translatewiki.net...siebrand20:45, 10 August 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r54590Add after the link for "My Talk" "<number of new messages(edits)>" if there a...jan16:39, 7 August 2009

Comments

#Comment by Nikerabbit (talk | contribs)   11:43, 8 August 2009
+'youhavenewmessages'           => 'You have $3 $1 ($2).',
  • Too much lego for translators. Now that there is the number $3, this message and $1 both would need to provide proper support for plural magic word, but neither do.
  • Can you rename newtalknumber to something more descriptive, like perhaps newMessagesCount?
  • var is php4, use public/private/protected instead.
#Comment by OverlordQ (talk | contribs)   15:18, 8 August 2009

^demon brought this up but it also equates messages to edits. If one user makes an edit, then goes back to correct anything, it'll say you have two messages.

#Comment by Shinjiman (talk | contribs)   15:51, 8 August 2009

I think it is suggested to make the message like this:

  • 'youhavenewmessages' => 'You have $1 ($2).', where $1 is link to the talk page (same behaviour) and $2 is link to the diff on the changed revisions (different behaviour than currently implemented).
  • 'newmessagesdifflink' => '$1 changes', where $1 is the number of the talk page changes by other user.

But the main point is, how to get the old diff number since the user visited.

#Comment by Shinjiman (talk | contribs)   15:54, 8 August 2009
  • 'newmessagesdifflink' => '{{PLURAL:$1|last change|$1 changes}}', where $1 is the number of the talk page changes by other user.

(forgotten to put <nowiki> onto the comment) :)

#Comment by Siebrand (talk | contribs)   10:57, 10 August 2009

I'd suggest to change 'My talk ($1)' to 'My talk$1', and have the new message count only added (using "wfMsg( 'word-separator' ) . wfMsg( 'parentheses', $var )") if there actually are new messages. IMO there is no point in adding "(0)" on ever page view; unneeded clutter.

#Comment by Siebrand (talk | contribs)   11:39, 10 August 2009

That was quick. Thanks :) (r54714)

#Comment by Siebrand (talk | contribs)   11:40, 10 August 2009

Only little issue, though. The parentheses have to be added only *if* there are new messages. Now it shows up as " ()" if there are no new message.

#Comment by Jan Luca (talk | contribs)   12:47, 10 August 2009

if ( $wgUser->getNewtalk() ) {

...

$newtalk = wfMsg( 'word-separator' ) . wfMsg( 'parentheses', $newmessagescount );

...

} else { $newtalk = ''; }

#Comment by Siebrand (talk | contribs)   12:51, 10 August 2009

I think I had been looking at an old page, or had a caching issue. In any case, r54714 indeed fixed this.

Status & tagging log