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, $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, $wgAllowRealName; 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 wfMsg( 'lastmodifiedatby', $d, $t, self::userLink( $user ) ); 00091 } 00092 00100 protected static function getContributors( Article $article, $cnt, $showIfMax ) { 00101 global $wgLang, $wgAllowRealName; 00102 00103 $contributors = $article->getContributors(); 00104 00105 $others_link = ''; 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 = 0; 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( $wgAllowRealName && $user->getRealName() ) 00124 $real_names[] = $link; 00125 else 00126 $user_names[] = $link; 00127 } else { 00128 $anon++; 00129 } 00130 if( $cnt == 0 ) break; 00131 } 00132 00133 # Two strings: real names, and user names 00134 $real = $wgLang->listToText( $real_names ); 00135 $user = $wgLang->listToText( $user_names ); 00136 if( $anon ) 00137 $anon = wfMsgExt( 'anonymous', array( 'parseinline' ), $anon ); 00138 00139 # "ThisSite user(s) A, B and C" 00140 if( !empty( $user ) ){ 00141 $user = wfMsgExt( 'siteusers', array( 'parsemag' ), $user, count( $user_names ) ); 00142 } 00143 00144 # This is the big list, all mooshed together. We sift for blank strings 00145 $fulllist = array(); 00146 foreach( array( $real, $user, $anon, $others_link ) as $s ){ 00147 if( !empty( $s ) ){ 00148 array_push( $fulllist, $s ); 00149 } 00150 } 00151 00152 # Make the list into text... 00153 $creds = $wgLang->listToText( $fulllist ); 00154 00155 # "Based on work by ..." 00156 return empty( $creds ) ? '' : wfMsg( 'othercontribs', $creds ); 00157 } 00158 00164 protected static function link( User $user ) { 00165 global $wgUser, $wgAllowRealName; 00166 if( $wgAllowRealName ) 00167 $real = $user->getRealName(); 00168 else 00169 $real = false; 00170 00171 $skin = $wgUser->getSkin(); 00172 $page = $user->getUserPage(); 00173 00174 return $skin->link( $page, htmlspecialchars( $real ? $real : $user->getName() ) ); 00175 } 00176 00183 protected static function userLink( User $user ) { 00184 global $wgUser, $wgAllowRealName; 00185 if( $user->isAnon() ){ 00186 return wfMsgExt( 'anonymous', array( 'parseinline' ), 1 ); 00187 } else { 00188 $link = self::link( $user ); 00189 if( $wgAllowRealName && $user->getRealName() ) 00190 return $link; 00191 else 00192 return wfMsgExt( 'siteuser', array( 'parseinline', 'replaceafter' ), $link ); 00193 } 00194 } 00195 00201 protected static function othersLink( Article $article ) { 00202 global $wgUser; 00203 $skin = $wgUser->getSkin(); 00204 return $skin->link( $article->getTitle(), wfMsgHtml( 'others' ), array(), array( 'action' => 'credits' ), array( 'known' ) ); 00205 } 00206 }