diff options
Diffstat (limited to 'includes/Credits.php')
-rw-r--r-- | includes/Credits.php | 70 |
1 files changed, 41 insertions, 29 deletions
diff --git a/includes/Credits.php b/includes/Credits.php index ae9377f2..91ba3f16 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 ); } } @@ -75,7 +75,7 @@ class Credits { * @param $article Article object */ protected static function getAuthor( Article $article ){ - global $wgLang, $wgAllowRealName; + global $wgLang; $user = User::newFromId( $article->getUser() ); @@ -87,7 +87,7 @@ class Credits { $d = ''; $t = ''; } - return wfMsg( 'lastmodifiedatby', $d, $t, self::userLink( $user ) ); + return wfMsgExt( 'lastmodifiedatby', 'parsemag', $d, $t, self::userLink( $user ), $user->getName() ); } /** @@ -98,11 +98,11 @@ class Credits { * @return String: html */ protected static function getContributors( Article $article, $cnt, $showIfMax ) { - global $wgLang, $wgAllowRealName; + global $wgLang, $wgHiddenPrefs; $contributors = $article->getContributors(); - $others_link = ''; + $others_link = false; # Hmm... too many to fit! if( $cnt > 0 && $contributors->count() > $cnt ){ @@ -113,38 +113,48 @@ class Credits { $real_names = array(); $user_names = array(); - $anon = 0; + $anon_ips = array(); # Sift for real versus user names foreach( $contributors as $user ) { $cnt--; if( $user->isLoggedIn() ){ $link = self::link( $user ); - if( $wgAllowRealName && $user->getRealName() ) + if( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) $real_names[] = $link; 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,40 +163,42 @@ class Credits { $creds = $wgLang->listToText( $fulllist ); # "Based on work by ..." - return empty( $creds ) ? '' : wfMsg( 'othercontribs', $creds ); + return strlen( $creds ) ? wfMsg( 'othercontribs', $creds ) : ''; } /** - * Get a link to $user_name page + * Get a link to $user's user page * @param $user User object * @return String: html */ protected static function link( User $user ) { - global $wgUser, $wgAllowRealName; - if( $wgAllowRealName ) + global $wgUser, $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() ) ); } /** - * Get a link to $user_name page + * Get a link to $user's user page * @param $user_name String: user name * @param $linkText String: optional display * @return String: html */ protected static function userLink( User $user ) { - global $wgUser, $wgAllowRealName; + $link = self::link( $user ); if( $user->isAnon() ){ - return wfMsgExt( 'anonymous', array( 'parseinline' ), 1 ); + return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link ); } else { - $link = self::link( $user ); - if( $wgAllowRealName && $user->getRealName() ) + global $wgHiddenPrefs; + if( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) return $link; else return wfMsgExt( 'siteuser', array( 'parseinline', 'replaceafter' ), $link ); @@ -203,4 +215,4 @@ class Credits { $skin = $wgUser->getSkin(); return $skin->link( $article->getTitle(), wfMsgHtml( 'others' ), array(), array( 'action' => 'credits' ), array( 'known' ) ); } -}
\ No newline at end of file +} |