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>
29 class CreditsAction
extends FormlessAction
{
31 public function getName() {
35 protected function getDescription() {
36 return $this->msg( 'creditspage' )->escaped();
40 * This is largely cadged from PageHistory::history
44 public function onView() {
45 wfProfileIn( __METHOD__
);
47 if ( $this->page
->getID() == 0 ) {
48 $s = $this->msg( 'nocredits' )->parse();
50 $s = $this->getCredits( -1 );
53 wfProfileOut( __METHOD__
);
55 return Html
::rawElement( 'div', array( 'id' => 'mw-credits' ), $s );
59 * Get a list of contributors
61 * @param int $cnt maximum list of contributors to show
62 * @param bool $showIfMax whether to contributors if there more than $cnt
63 * @return String: html
65 public function getCredits( $cnt, $showIfMax = true ) {
66 wfProfileIn( __METHOD__
);
70 $s = $this->getAuthor( $this->page
);
71 if ( $cnt > 1 ||
$cnt < 0 ) {
72 $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
76 wfProfileOut( __METHOD__
);
81 * Get the last author with the last modification time
85 protected function getAuthor( Page
$page ) {
86 $user = User
::newFromName( $page->getUserText(), false );
88 $timestamp = $page->getTimestamp();
90 $lang = $this->getLanguage();
91 $d = $lang->date( $page->getTimestamp(), true );
92 $t = $lang->time( $page->getTimestamp(), true );
97 return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams(
98 $this->userLink( $user ) )->params( $user->getName() )->escaped();
102 * Get a list of contributors of $article
103 * @param int $cnt maximum list of contributors to show
104 * @param bool $showIfMax whether to contributors if there more than $cnt
105 * @return String: html
107 protected function getContributors( $cnt, $showIfMax ) {
108 global $wgHiddenPrefs;
110 $contributors = $this->page
->getContributors();
112 $others_link = false;
114 # Hmm... too many to fit!
115 if ( $cnt > 0 && $contributors->count() > $cnt ) {
116 $others_link = $this->othersLink();
118 return $this->msg( 'othercontribs' )->rawParams(
119 $others_link )->params( $contributors->count() )->escaped();
123 $real_names = array();
124 $user_names = array();
127 # Sift for real versus user names
128 foreach ( $contributors as $user ) {
130 if ( $user->isLoggedIn() ) {
131 $link = $this->link( $user );
132 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
133 $real_names[] = $link;
135 $user_names[] = $link;
138 $anon_ips[] = $this->link( $user );
146 $lang = $this->getLanguage();
148 if ( count( $real_names ) ) {
149 $real = $lang->listToText( $real_names );
154 # "ThisSite user(s) A, B and C"
155 if ( count( $user_names ) ) {
156 $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
157 count( $user_names ) )->escaped();
162 if ( count( $anon_ips ) ) {
163 $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
164 count( $anon_ips ) )->escaped();
169 # This is the big list, all mooshed together. We sift for blank strings
171 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
172 if ( $s !== false ) {
173 array_push( $fulllist, $s );
177 $count = count( $fulllist );
178 # "Based on work by ..."
180 ?
$this->msg( 'othercontribs' )->rawParams(
181 $lang->listToText( $fulllist ) )->params( $count )->escaped()
186 * Get a link to $user's user page
187 * @param $user User object
188 * @return String: html
190 protected function link( User
$user ) {
191 global $wgHiddenPrefs;
192 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
193 $real = $user->getRealName();
198 $page = $user->isAnon()
199 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
200 : $user->getUserPage();
202 return Linker
::link( $page, htmlspecialchars( $real ?
$real : $user->getName() ) );
206 * Get a link to $user's user page
207 * @param $user User object
208 * @return String: html
210 protected function userLink( User
$user ) {
211 $link = $this->link( $user );
212 if ( $user->isAnon() ) {
213 return $this->msg( 'anonuser' )->rawParams( $link )->parse();
215 global $wgHiddenPrefs;
216 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
219 return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
225 * Get a link to action=credits of $article page
226 * @return String: HTML link
228 protected function othersLink() {
229 return Linker
::linkKnown(
231 $this->msg( 'others' )->escaped(),
233 array( 'action' => 'credits' )