From d07fefb39f08e33436313038f73acb491c654a27 Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Wed, 23 Sep 2009 11:31:52 +0000 Subject: [PATCH] * (bug 16310) Credits page now lists IP addresses rather than saying the number of anonymous users that edited the page * Some whitespaces fixes --- RELEASE-NOTES | 2 ++ includes/Article.php | 29 ++++++++++++------- includes/Credits.php | 48 +++++++++++++++++++------------ languages/messages/MessagesEn.php | 2 ++ maintenance/language/messages.inc | 2 ++ 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 303e19420f..644dc3db07 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -242,6 +242,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * New configuration variable $wgShowPageOnRedlink that can be set to show the page instead of an edit interface when visiting a red link. The value can be specified for specific usergroups and namespaces. +* (bug 16310) Credits page now lists IP addresses rather than saying the number + of anonymous users that edited the page === Bug fixes in 1.16 === diff --git a/includes/Article.php b/includes/Article.php index 67cb5a6988..900ffab3ec 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -692,29 +692,36 @@ class Article { public function getContributors($limit = 0, $offset = 0) { # XXX: this is expensive; cache this info somewhere. - $contribs = array(); $dbr = wfGetDB( DB_SLAVE ); $revTable = $dbr->tableName( 'revision' ); $userTable = $dbr->tableName( 'user' ); - $user = $this->getUser(); + $pageId = $this->getId(); - $deletedBit = $dbr->bitAnd('rev_deleted', Revision::DELETED_USER); // username hidden? + $user = $this->getUser(); + if ( $user ) { + $excludeCond = "AND rev_user != $user"; + } else { + $userText = $dbr->addQuotes( $this->getUserText() ); + $excludeCond = "AND rev_user_text != $userText"; + } + + $deletedBit = $dbr->bitAnd( 'rev_deleted', Revision::DELETED_USER ); // username hidden? - $sql = "SELECT {$userTable}.*, MAX(rev_timestamp) as timestamp + $sql = "SELECT {$userTable}.*, rev_user_text as user_name, MAX(rev_timestamp) as timestamp FROM $revTable LEFT JOIN $userTable ON rev_user = user_id WHERE rev_page = $pageId - AND rev_user != $user + $excludeCond AND $deletedBit = 0 - GROUP BY rev_user, rev_user_text, user_real_name + GROUP BY rev_user, rev_user_text ORDER BY timestamp DESC"; - if($limit > 0) - $sql = $dbr->limitResult($sql, $limit, $offset); - - $sql .= ' '. $this->getSelectOptions(); + if ( $limit > 0 ) + $sql = $dbr->limitResult( $sql, $limit, $offset ); - $res = $dbr->query($sql, __METHOD__ ); + $sql .= ' ' . $this->getSelectOptions(); + wfVarDump( $sql ); + $res = $dbr->query( $sql, __METHOD__ ); return new UserArrayFromResult( $res ); } diff --git a/includes/Credits.php b/includes/Credits.php index ad7e029072..35d4197f60 100644 --- a/includes/Credits.php +++ b/includes/Credits.php @@ -55,13 +55,13 @@ class Credits { * @param $showIfMax Bool: whether to contributors if there more than $cnt * @return String: html */ - public static function getCredits($article, $cnt, $showIfMax=true) { + public static function getCredits( Article $article, $cnt, $showIfMax = true ) { wfProfileIn( __METHOD__ ); $s = ''; if( isset( $cnt ) && $cnt != 0 ){ $s = self::getAuthor( $article ); - if ($cnt > 1 || $cnt < 0) { + if ( $cnt > 1 || $cnt < 0 ) { $s .= ' ' . self::getContributors( $article, $cnt - 1, $showIfMax ); } } @@ -102,7 +102,7 @@ class Credits { $contributors = $article->getContributors(); - $others_link = ''; + $others_link = false; # Hmm... too many to fit! if( $cnt > 0 && $contributors->count() > $cnt ){ @@ -113,7 +113,7 @@ class Credits { $real_names = array(); $user_names = array(); - $anon = 0; + $anon_ips = array(); # Sift for real versus user names foreach( $contributors as $user ) { @@ -125,26 +125,36 @@ class Credits { else $user_names[] = $link; } else { - $anon++; + $anon_ips[] = self::link( $user ); } if( $cnt == 0 ) break; } - # Two strings: real names, and user names - $real = $wgLang->listToText( $real_names ); - $user = $wgLang->listToText( $user_names ); - if( $anon ) - $anon = wfMsgExt( 'anonymous', array( 'parseinline' ), $anon ); + if ( count( $real_names ) ) { + $real = $wgLang->listToText( $real_names ); + } else { + $real = false; + } # "ThisSite user(s) A, B and C" - if( !empty( $user ) ){ - $user = wfMsgExt( 'siteusers', array( 'parsemag' ), $user, count( $user_names ) ); + if( count( $user_names ) ){ + $user = wfMsgExt( 'siteusers', array( 'parsemag' ), + $wgLang->listToText( $user_names ), count( $user_names ) ); + } else { + $user = false; + } + + if( count( $anon_ips ) ){ + $anon = wfMsgExt( 'anonusers', array( 'parsemag' ), + $wgLang->listToText( $anon_ips ), count( $anon_ips ) ); + } else { + $anon = false; } # This is the big list, all mooshed together. We sift for blank strings $fulllist = array(); foreach( array( $real, $user, $anon, $others_link ) as $s ){ - if( !empty( $s ) ){ + if( $s ){ array_push( $fulllist, $s ); } } @@ -153,7 +163,7 @@ class Credits { $creds = $wgLang->listToText( $fulllist ); # "Based on work by ..." - return empty( $creds ) ? '' : wfMsg( 'othercontribs', $creds ); + return strlen( $creds ) ? wfMsg( 'othercontribs', $creds ) : ''; } /** @@ -163,13 +173,15 @@ class Credits { */ protected static function link( User $user ) { global $wgUser, $wgHiddenPrefs; - if( !in_array( 'realname', $wgHiddenPrefs ) ) + if( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) $real = $user->getRealName(); else $real = false; $skin = $wgUser->getSkin(); - $page = $user->getUserPage(); + $page = $user->isAnon() ? + SpecialPage::getTitleFor( 'Contributions', $user->getName() ) : + $user->getUserPage(); return $skin->link( $page, htmlspecialchars( $real ? $real : $user->getName() ) ); } @@ -181,11 +193,11 @@ class Credits { * @return String: html */ protected static function userLink( User $user ) { + $link = self::link( $user ); if( $user->isAnon() ){ - return wfMsgExt( 'anonymous', array( 'parseinline' ), 1 ); + return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link ); } else { global $wgHiddenPrefs; - $link = self::link( $user ); if( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) return $link; else diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index 7ca405e72b..9141469759 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -3362,10 +3362,12 @@ It allows adding a reason in the summary.', # Attribution 'anonymous' => 'Anonymous {{PLURAL:$1|user|users}} of {{SITENAME}}', 'siteuser' => '{{SITENAME}} user $1', +'anonuser' => '{{SITENAME}} anonymous user $1', 'lastmodifiedatby' => 'This page was last modified $2, $1 by $3.', 'othercontribs' => 'Based on work by $1.', 'others' => 'others', 'siteusers' => '{{SITENAME}} {{PLURAL:$2|user|users}} $1', +'anonusers' => '{{SITENAME}} anonymous {{PLURAL:$2|user|users}} $1', 'creditspage' => 'Page credits', 'nocredits' => 'There is no credits info available for this page.', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index c046769701..13aca82bd7 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -2350,10 +2350,12 @@ $wgMessageStructure = array( 'attribution' => array( 'anonymous', 'siteuser', + 'anonuser', 'lastmodifiedatby', 'othercontribs', 'others', 'siteusers', + 'anonusers', 'creditspage', 'nocredits', ), -- 2.20.1