MediaWiki
REL1_21
|
00001 <?php 00029 class CreditsAction extends FormlessAction { 00030 00031 public function getName() { 00032 return 'credits'; 00033 } 00034 00035 protected function getDescription() { 00036 return $this->msg( 'creditspage' )->escaped(); 00037 } 00038 00044 public function onView() { 00045 wfProfileIn( __METHOD__ ); 00046 00047 if ( $this->page->getID() == 0 ) { 00048 $s = $this->msg( 'nocredits' )->parse(); 00049 } else { 00050 $s = $this->getCredits( -1 ); 00051 } 00052 00053 wfProfileOut( __METHOD__ ); 00054 00055 return Html::rawElement( 'div', array( 'id' => 'mw-credits' ), $s ); 00056 } 00057 00065 public function getCredits( $cnt, $showIfMax = true ) { 00066 wfProfileIn( __METHOD__ ); 00067 $s = ''; 00068 00069 if ( $cnt != 0 ) { 00070 $s = $this->getAuthor( $this->page ); 00071 if ( $cnt > 1 || $cnt < 0 ) { 00072 $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax ); 00073 } 00074 } 00075 00076 wfProfileOut( __METHOD__ ); 00077 return $s; 00078 } 00079 00085 protected function getAuthor( Page $article ) { 00086 $user = User::newFromName( $article->getUserText(), false ); 00087 00088 $timestamp = $article->getTimestamp(); 00089 if ( $timestamp ) { 00090 $lang = $this->getLanguage(); 00091 $d = $lang->date( $article->getTimestamp(), true ); 00092 $t = $lang->time( $article->getTimestamp(), true ); 00093 } else { 00094 $d = ''; 00095 $t = ''; 00096 } 00097 return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams( 00098 $this->userLink( $user ) )->params( $user->getName() )->escaped(); 00099 } 00100 00107 protected function getContributors( $cnt, $showIfMax ) { 00108 global $wgHiddenPrefs; 00109 00110 $contributors = $this->page->getContributors(); 00111 00112 $others_link = false; 00113 00114 # Hmm... too many to fit! 00115 if ( $cnt > 0 && $contributors->count() > $cnt ) { 00116 $others_link = $this->othersLink(); 00117 if ( !$showIfMax ) 00118 return $this->msg( 'othercontribs' )->rawParams( 00119 $others_link )->params( $contributors->count() )->escaped(); 00120 } 00121 00122 $real_names = array(); 00123 $user_names = array(); 00124 $anon_ips = array(); 00125 00126 # Sift for real versus user names 00127 foreach ( $contributors as $user ) { 00128 $cnt--; 00129 if ( $user->isLoggedIn() ) { 00130 $link = $this->link( $user ); 00131 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) { 00132 $real_names[] = $link; 00133 } else { 00134 $user_names[] = $link; 00135 } 00136 } else { 00137 $anon_ips[] = $this->link( $user ); 00138 } 00139 00140 if ( $cnt == 0 ) { 00141 break; 00142 } 00143 } 00144 00145 $lang = $this->getLanguage(); 00146 00147 if ( count( $real_names ) ) { 00148 $real = $lang->listToText( $real_names ); 00149 } else { 00150 $real = false; 00151 } 00152 00153 # "ThisSite user(s) A, B and C" 00154 if ( count( $user_names ) ) { 00155 $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params( 00156 count( $user_names ) )->escaped(); 00157 } else { 00158 $user = false; 00159 } 00160 00161 if ( count( $anon_ips ) ) { 00162 $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params( 00163 count( $anon_ips ) )->escaped(); 00164 } else { 00165 $anon = false; 00166 } 00167 00168 # This is the big list, all mooshed together. We sift for blank strings 00169 $fulllist = array(); 00170 foreach ( array( $real, $user, $anon, $others_link ) as $s ) { 00171 if ( $s !== false ) { 00172 array_push( $fulllist, $s ); 00173 } 00174 } 00175 00176 $count = count( $fulllist ); 00177 # "Based on work by ..." 00178 return $count 00179 ? $this->msg( 'othercontribs' )->rawParams( 00180 $lang->listToText( $fulllist ) )->params( $count )->escaped() 00181 : ''; 00182 } 00183 00189 protected function link( User $user ) { 00190 global $wgHiddenPrefs; 00191 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) { 00192 $real = $user->getRealName(); 00193 } else { 00194 $real = false; 00195 } 00196 00197 $page = $user->isAnon() 00198 ? SpecialPage::getTitleFor( 'Contributions', $user->getName() ) 00199 : $user->getUserPage(); 00200 00201 return Linker::link( $page, htmlspecialchars( $real ? $real : $user->getName() ) ); 00202 } 00203 00209 protected function userLink( User $user ) { 00210 $link = $this->link( $user ); 00211 if ( $user->isAnon() ) { 00212 return $this->msg( 'anonuser' )->rawParams( $link )->parse(); 00213 } else { 00214 global $wgHiddenPrefs; 00215 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) { 00216 return $link; 00217 } else { 00218 return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped(); 00219 } 00220 } 00221 } 00222 00227 protected function othersLink() { 00228 return Linker::linkKnown( 00229 $this->getTitle(), 00230 $this->msg( 'others' )->escaped(), 00231 array(), 00232 array( 'action' => 'credits' ) 00233 ); 00234 } 00235 }