00001 <?php 00023 class Credits { 00024 00029 public static function showPage( Article $article ) { 00030 global $wgOut; 00031 00032 wfProfileIn( __METHOD__ ); 00033 00034 $wgOut->setPageTitle( $article->mTitle->getPrefixedText() ); 00035 $wgOut->setSubtitle( wfMsg( 'creditspage' ) ); 00036 $wgOut->setArticleFlag( false ); 00037 $wgOut->setArticleRelated( true ); 00038 $wgOut->setRobotPolicy( 'noindex,nofollow' ); 00039 00040 if( $article->mTitle->getArticleID() == 0 ) { 00041 $s = wfMsg( 'nocredits' ); 00042 } else { 00043 $s = self::getCredits($article, -1 ); 00044 } 00045 00046 $wgOut->addHTML( $s ); 00047 00048 wfProfileOut( __METHOD__ ); 00049 } 00050 00058 public static function getCredits( Article $article, $cnt, $showIfMax = true ) { 00059 wfProfileIn( __METHOD__ ); 00060 $s = ''; 00061 00062 if( isset( $cnt ) && $cnt != 0 ){ 00063 $s = self::getAuthor( $article ); 00064 if ( $cnt > 1 || $cnt < 0 ) { 00065 $s .= ' ' . self::getContributors( $article, $cnt - 1, $showIfMax ); 00066 } 00067 } 00068 00069 wfProfileOut( __METHOD__ ); 00070 return $s; 00071 } 00072 00077 protected static function getAuthor( Article $article ){ 00078 global $wgLang; 00079 00080 $user = User::newFromId( $article->getUser() ); 00081 00082 $timestamp = $article->getTimestamp(); 00083 if( $timestamp ){ 00084 $d = $wgLang->date( $article->getTimestamp(), true ); 00085 $t = $wgLang->time( $article->getTimestamp(), true ); 00086 } else { 00087 $d = ''; 00088 $t = ''; 00089 } 00090 return wfMsgExt( 'lastmodifiedatby', 'parsemag', $d, $t, self::userLink( $user ), $user->getName() ); 00091 } 00092 00100 protected static function getContributors( Article $article, $cnt, $showIfMax ) { 00101 global $wgLang, $wgHiddenPrefs; 00102 00103 $contributors = $article->getContributors(); 00104 00105 $others_link = false; 00106 00107 # Hmm... too many to fit! 00108 if( $cnt > 0 && $contributors->count() > $cnt ){ 00109 $others_link = self::othersLink( $article ); 00110 if( !$showIfMax ) 00111 return wfMsg( 'othercontribs', $others_link ); 00112 } 00113 00114 $real_names = array(); 00115 $user_names = array(); 00116 $anon_ips = array(); 00117 00118 # Sift for real versus user names 00119 foreach( $contributors as $user ) { 00120 $cnt--; 00121 if( $user->isLoggedIn() ){ 00122 $link = self::link( $user ); 00123 if( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) 00124 $real_names[] = $link; 00125 else 00126 $user_names[] = $link; 00127 } else { 00128 $anon_ips[] = self::link( $user ); 00129 } 00130 if( $cnt == 0 ) break; 00131 } 00132 00133 if ( count( $real_names ) ) { 00134 $real = $wgLang->listToText( $real_names ); 00135 } else { 00136 $real = false; 00137 } 00138 00139 # "ThisSite user(s) A, B and C" 00140 if( count( $user_names ) ){ 00141 $user = wfMsgExt( 'siteusers', array( 'parsemag' ), 00142 $wgLang->listToText( $user_names ), count( $user_names ) ); 00143 } else { 00144 $user = false; 00145 } 00146 00147 if( count( $anon_ips ) ){ 00148 $anon = wfMsgExt( 'anonusers', array( 'parsemag' ), 00149 $wgLang->listToText( $anon_ips ), count( $anon_ips ) ); 00150 } else { 00151 $anon = false; 00152 } 00153 00154 # This is the big list, all mooshed together. We sift for blank strings 00155 $fulllist = array(); 00156 foreach( array( $real, $user, $anon, $others_link ) as $s ){ 00157 if( $s ){ 00158 array_push( $fulllist, $s ); 00159 } 00160 } 00161 00162 # Make the list into text... 00163 $creds = $wgLang->listToText( $fulllist ); 00164 00165 # "Based on work by ..." 00166 return strlen( $creds ) ? wfMsg( 'othercontribs', $creds ) : ''; 00167 } 00168 00174 protected static function link( User $user ) { 00175 global $wgUser, $wgHiddenPrefs; 00176 if( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) 00177 $real = $user->getRealName(); 00178 else 00179 $real = false; 00180 00181 $skin = $wgUser->getSkin(); 00182 $page = $user->isAnon() ? 00183 SpecialPage::getTitleFor( 'Contributions', $user->getName() ) : 00184 $user->getUserPage(); 00185 00186 return $skin->link( $page, htmlspecialchars( $real ? $real : $user->getName() ) ); 00187 } 00188 00195 protected static function userLink( User $user ) { 00196 $link = self::link( $user ); 00197 if( $user->isAnon() ){ 00198 return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link ); 00199 } else { 00200 global $wgHiddenPrefs; 00201 if( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) 00202 return $link; 00203 else 00204 return wfMsgExt( 'siteuser', array( 'parseinline', 'replaceafter' ), $link ); 00205 } 00206 } 00207 00213 protected static function othersLink( Article $article ) { 00214 global $wgUser; 00215 $skin = $wgUser->getSkin(); 00216 return $skin->link( $article->getTitle(), wfMsgHtml( 'others' ), array(), array( 'action' => 'credits' ), array( 'known' ) ); 00217 } 00218 }