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