r56806 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56805‎ | r56806 | r56807 >
Date:11:31, 23 September 2009
Author:ialex
Status:resolved
Tags:
Comment:
* (bug 16310) Credits page now lists IP addresses rather than saying the number of anonymous users that edited the page
* Some whitespaces fixes
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/Article.php (modified) (history)
  • /trunk/phase3/includes/Credits.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -2350,10 +2350,12 @@
23512351 'attribution' => array(
23522352 'anonymous',
23532353 'siteuser',
 2354+ 'anonuser',
23542355 'lastmodifiedatby',
23552356 'othercontribs',
23562357 'others',
23572358 'siteusers',
 2359+ 'anonusers',
23582360 'creditspage',
23592361 'nocredits',
23602362 ),
Index: trunk/phase3/includes/Article.php
@@ -692,30 +692,37 @@
693693 public function getContributors($limit = 0, $offset = 0) {
694694 # XXX: this is expensive; cache this info somewhere.
695695
696 - $contribs = array();
697696 $dbr = wfGetDB( DB_SLAVE );
698697 $revTable = $dbr->tableName( 'revision' );
699698 $userTable = $dbr->tableName( 'user' );
700 - $user = $this->getUser();
 699+
701700 $pageId = $this->getId();
702701
703 - $deletedBit = $dbr->bitAnd('rev_deleted', Revision::DELETED_USER); // username hidden?
 702+ $user = $this->getUser();
 703+ if ( $user ) {
 704+ $excludeCond = "AND rev_user != $user";
 705+ } else {
 706+ $userText = $dbr->addQuotes( $this->getUserText() );
 707+ $excludeCond = "AND rev_user_text != $userText";
 708+ }
704709
705 - $sql = "SELECT {$userTable}.*, MAX(rev_timestamp) as timestamp
 710+ $deletedBit = $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ); // username hidden?
 711+
 712+ $sql = "SELECT {$userTable}.*, rev_user_text as user_name, MAX(rev_timestamp) as timestamp
706713 FROM $revTable LEFT JOIN $userTable ON rev_user = user_id
707714 WHERE rev_page = $pageId
708 - AND rev_user != $user
 715+ $excludeCond
709716 AND $deletedBit = 0
710 - GROUP BY rev_user, rev_user_text, user_real_name
 717+ GROUP BY rev_user, rev_user_text
711718 ORDER BY timestamp DESC";
712719
713 - if($limit > 0)
714 - $sql = $dbr->limitResult($sql, $limit, $offset);
 720+ if ( $limit > 0 )
 721+ $sql = $dbr->limitResult( $sql, $limit, $offset );
715722
716 - $sql .= ' '. $this->getSelectOptions();
 723+ $sql .= ' ' . $this->getSelectOptions();
 724+ wfVarDump( $sql );
 725+ $res = $dbr->query( $sql, __METHOD__ );
717726
718 - $res = $dbr->query($sql, __METHOD__ );
719 -
720727 return new UserArrayFromResult( $res );
721728 }
722729
Index: trunk/phase3/includes/Credits.php
@@ -55,13 +55,13 @@
5656 * @param $showIfMax Bool: whether to contributors if there more than $cnt
5757 * @return String: html
5858 */
59 - public static function getCredits($article, $cnt, $showIfMax=true) {
 59+ public static function getCredits( Article $article, $cnt, $showIfMax = true ) {
6060 wfProfileIn( __METHOD__ );
6161 $s = '';
6262
6363 if( isset( $cnt ) && $cnt != 0 ){
6464 $s = self::getAuthor( $article );
65 - if ($cnt > 1 || $cnt < 0) {
 65+ if ( $cnt > 1 || $cnt < 0 ) {
6666 $s .= ' ' . self::getContributors( $article, $cnt - 1, $showIfMax );
6767 }
6868 }
@@ -102,7 +102,7 @@
103103
104104 $contributors = $article->getContributors();
105105
106 - $others_link = '';
 106+ $others_link = false;
107107
108108 # Hmm... too many to fit!
109109 if( $cnt > 0 && $contributors->count() > $cnt ){
@@ -113,7 +113,7 @@
114114
115115 $real_names = array();
116116 $user_names = array();
117 - $anon = 0;
 117+ $anon_ips = array();
118118
119119 # Sift for real versus user names
120120 foreach( $contributors as $user ) {
@@ -125,26 +125,36 @@
126126 else
127127 $user_names[] = $link;
128128 } else {
129 - $anon++;
 129+ $anon_ips[] = self::link( $user );
130130 }
131131 if( $cnt == 0 ) break;
132132 }
133133
134 - # Two strings: real names, and user names
135 - $real = $wgLang->listToText( $real_names );
136 - $user = $wgLang->listToText( $user_names );
137 - if( $anon )
138 - $anon = wfMsgExt( 'anonymous', array( 'parseinline' ), $anon );
 134+ if ( count( $real_names ) ) {
 135+ $real = $wgLang->listToText( $real_names );
 136+ } else {
 137+ $real = false;
 138+ }
139139
140140 # "ThisSite user(s) A, B and C"
141 - if( !empty( $user ) ){
142 - $user = wfMsgExt( 'siteusers', array( 'parsemag' ), $user, count( $user_names ) );
 141+ if( count( $user_names ) ){
 142+ $user = wfMsgExt( 'siteusers', array( 'parsemag' ),
 143+ $wgLang->listToText( $user_names ), count( $user_names ) );
 144+ } else {
 145+ $user = false;
143146 }
 147+
 148+ if( count( $anon_ips ) ){
 149+ $anon = wfMsgExt( 'anonusers', array( 'parsemag' ),
 150+ $wgLang->listToText( $anon_ips ), count( $anon_ips ) );
 151+ } else {
 152+ $anon = false;
 153+ }
144154
145155 # This is the big list, all mooshed together. We sift for blank strings
146156 $fulllist = array();
147157 foreach( array( $real, $user, $anon, $others_link ) as $s ){
148 - if( !empty( $s ) ){
 158+ if( $s ){
149159 array_push( $fulllist, $s );
150160 }
151161 }
@@ -153,7 +163,7 @@
154164 $creds = $wgLang->listToText( $fulllist );
155165
156166 # "Based on work by ..."
157 - return empty( $creds ) ? '' : wfMsg( 'othercontribs', $creds );
 167+ return strlen( $creds ) ? wfMsg( 'othercontribs', $creds ) : '';
158168 }
159169
160170 /**
@@ -163,13 +173,15 @@
164174 */
165175 protected static function link( User $user ) {
166176 global $wgUser, $wgHiddenPrefs;
167 - if( !in_array( 'realname', $wgHiddenPrefs ) )
 177+ if( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() )
168178 $real = $user->getRealName();
169179 else
170180 $real = false;
171181
172182 $skin = $wgUser->getSkin();
173 - $page = $user->getUserPage();
 183+ $page = $user->isAnon() ?
 184+ SpecialPage::getTitleFor( 'Contributions', $user->getName() ) :
 185+ $user->getUserPage();
174186
175187 return $skin->link( $page, htmlspecialchars( $real ? $real : $user->getName() ) );
176188 }
@@ -181,11 +193,11 @@
182194 * @return String: html
183195 */
184196 protected static function userLink( User $user ) {
 197+ $link = self::link( $user );
185198 if( $user->isAnon() ){
186 - return wfMsgExt( 'anonymous', array( 'parseinline' ), 1 );
 199+ return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
187200 } else {
188201 global $wgHiddenPrefs;
189 - $link = self::link( $user );
190202 if( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() )
191203 return $link;
192204 else
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -3362,10 +3362,12 @@
33633363 # Attribution
33643364 'anonymous' => 'Anonymous {{PLURAL:$1|user|users}} of {{SITENAME}}',
33653365 'siteuser' => '{{SITENAME}} user $1',
 3366+'anonuser' => '{{SITENAME}} anonymous user $1',
33663367 'lastmodifiedatby' => 'This page was last modified $2, $1 by $3.',
33673368 'othercontribs' => 'Based on work by $1.',
33683369 'others' => 'others',
33693370 'siteusers' => '{{SITENAME}} {{PLURAL:$2|user|users}} $1',
 3371+'anonusers' => '{{SITENAME}} anonymous {{PLURAL:$2|user|users}} $1',
33703372 'creditspage' => 'Page credits',
33713373 'nocredits' => 'There is no credits info available for this page.',
33723374
Index: trunk/phase3/RELEASE-NOTES
@@ -242,6 +242,8 @@
243243 * New configuration variable $wgShowPageOnRedlink that can be set to show the page
244244 instead of an edit interface when visiting a red link. The value can be specified
245245 for specific usergroups and namespaces.
 246+* (bug 16310) Credits page now lists IP addresses rather than saying the number
 247+ of anonymous users that edited the page
246248
247249 === Bug fixes in 1.16 ===
248250

Follow-up revisions

RevisionCommit summaryAuthorDate
r56807*STAB* Fix for r56806: remove debugging codeialex11:35, 23 September 2009

Status & tagging log