3 * Formats credits for articles
5 * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 * @author <evan@wikitravel.org>
26 class CreditsAction
extends FormlessAction
{
28 public function getName() {
32 public function getRestriction() {
36 protected function getDescription() {
37 return wfMsg( strtolower( 'creditspage' ) );
41 * This is largely cadged from PageHistory::history
45 public function onView() {
46 wfProfileIn( __METHOD__
);
48 if ( $this->page
->getID() == 0 ) {
49 $s = wfMsg( 'nocredits' );
51 $s = $this->getCredits( -1 );
54 wfProfileOut( __METHOD__
);
60 * Get a list of contributors
62 * @param $cnt Int: maximum list of contributors to show
63 * @param $showIfMax Bool: whether to contributors if there more than $cnt
64 * @return String: html
66 public function getCredits( $cnt, $showIfMax = true ) {
67 wfProfileIn( __METHOD__
);
70 if ( isset( $cnt ) && $cnt != 0 ) {
71 $s = self
::getAuthor( $this->page
);
72 if ( $cnt > 1 ||
$cnt < 0 ) {
73 $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
77 wfProfileOut( __METHOD__
);
82 * Get the last author with the last modification time
83 * @param $article Article object
86 protected static function getAuthor( Article
$article ) {
89 $user = User
::newFromId( $article->getUser() );
91 $timestamp = $article->getTimestamp();
93 $d = $wgLang->date( $article->getTimestamp(), true );
94 $t = $wgLang->time( $article->getTimestamp(), true );
99 return wfMessage( 'lastmodifiedatby', $d, $t )->rawParams( self
::userLink( $user ) )->params( $user->getName() )->escaped();
103 * Get a list of contributors of $article
104 * @param $cnt Int: maximum list of contributors to show
105 * @param $showIfMax Bool: whether to contributors if there more than $cnt
106 * @return String: html
108 protected function getContributors( $cnt, $showIfMax ) {
109 global $wgLang, $wgHiddenPrefs;
111 $contributors = $this->page
->getContributors();
113 $others_link = false;
115 # Hmm... too many to fit!
116 if ( $cnt > 0 && $contributors->count() > $cnt ) {
117 $others_link = $this->othersLink();
119 return wfMessage( 'othercontribs' )->rawParams( $others_link )->params( $contributors->count() )->escaped();
122 $real_names = array();
123 $user_names = array();
126 # Sift for real versus user names
127 foreach ( $contributors as $user ) {
129 if ( $user->isLoggedIn() ) {
130 $link = self
::link( $user );
131 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
132 $real_names[] = $link;
134 $user_names[] = $link;
137 $anon_ips[] = self
::link( $user );
145 if ( count( $real_names ) ) {
146 $real = $wgLang->listToText( $real_names );
151 # "ThisSite user(s) A, B and C"
152 if ( count( $user_names ) ) {
153 $user = wfMessage( 'siteusers' )->rawParams( $wgLang->listToText( $user_names ) )->params(
154 count( $user_names ) )->escaped();
159 if ( count( $anon_ips ) ) {
160 $anon = wfMessage( 'anonusers' )->rawParams( $wgLang->listToText( $anon_ips ) )->params(
161 count( $anon_ips ) )->escaped();
166 # This is the big list, all mooshed together. We sift for blank strings
168 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
169 if ( $s !== false ) {
170 array_push( $fulllist, $s );
174 $count = count( $fulllist );
175 # "Based on work by ..."
177 ?
wfMessage( 'othercontribs' )->rawParams(
178 $wgLang->listToText( $fulllist ) )->params( $count )->escaped()
183 * Get a link to $user's user page
184 * @param $user User object
185 * @return String: html
187 protected static function link( User
$user ) {
188 global $wgHiddenPrefs;
189 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
190 $real = $user->getRealName();
195 $page = $user->isAnon()
196 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
197 : $user->getUserPage();
199 return Linker
::link( $page, htmlspecialchars( $real ?
$real : $user->getName() ) );
203 * Get a link to $user's user page
204 * @param $user User object
205 * @return String: html
207 protected static function userLink( User
$user ) {
208 $link = self
::link( $user );
209 if ( $user->isAnon() ) {
210 return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
212 global $wgHiddenPrefs;
213 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
216 return wfMessage( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
222 * Get a link to action=credits of $article page
223 * @param $article Article object
224 * @return String: html
226 protected function othersLink() {
229 wfMsgHtml( 'others' ),
231 array( 'action' => 'credits' ),