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 );
}
* @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 );
}
}
$contributors = $article->getContributors();
- $others_link = '';
+ $others_link = false;
# Hmm... too many to fit!
if( $cnt > 0 && $contributors->count() > $cnt ){
$real_names = array();
$user_names = array();
- $anon = 0;
+ $anon_ips = array();
# Sift for real versus user names
foreach( $contributors as $user ) {
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 );
}
}
$creds = $wgLang->listToText( $fulllist );
# "Based on work by ..."
- return empty( $creds ) ? '' : wfMsg( 'othercontribs', $creds );
+ return strlen( $creds ) ? wfMsg( 'othercontribs', $creds ) : '';
}
/**
*/
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() ) );
}
* @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
# 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.',