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() {
46 if ( $this->page
->getID() == 0 ) {
47 $s = $this->msg( 'nocredits' )->parse();
49 $s = $this->getCredits( -1 );
53 return Html
::rawElement( 'div', array( 'id' => 'mw-credits' ), $s );
57 * Get a list of contributors
59 * @param int $cnt Maximum list of contributors to show
60 * @param bool $showIfMax Whether to contributors if there more than $cnt
63 public function getCredits( $cnt, $showIfMax = true ) {
67 $s = $this->getAuthor( $this->page
);
68 if ( $cnt > 1 ||
$cnt < 0 ) {
69 $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
78 * Get the last author with the last modification time
82 protected function getAuthor( Page
$page ) {
83 $user = User
::newFromName( $page->getUserText(), false );
85 $timestamp = $page->getTimestamp();
87 $lang = $this->getLanguage();
88 $d = $lang->date( $page->getTimestamp(), true );
89 $t = $lang->time( $page->getTimestamp(), true );
95 return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams(
96 $this->userLink( $user ) )->params( $user->getName() )->escaped();
100 * Whether we can display the user's real name (not a hidden pref)
105 protected function canShowRealUserName() {
106 $hiddenPrefs = $this->context
->getConfig()->get( 'HiddenPrefs' );
107 return !in_array( 'realname', $hiddenPrefs );
111 * Get a list of contributors of $article
112 * @param int $cnt Maximum list of contributors to show
113 * @param bool $showIfMax Whether to contributors if there more than $cnt
114 * @return string Html
116 protected function getContributors( $cnt, $showIfMax ) {
117 $contributors = $this->page
->getContributors();
119 $others_link = false;
121 # Hmm... too many to fit!
122 if ( $cnt > 0 && $contributors->count() > $cnt ) {
123 $others_link = $this->othersLink();
125 return $this->msg( 'othercontribs' )->rawParams(
126 $others_link )->params( $contributors->count() )->escaped();
130 $real_names = array();
131 $user_names = array();
134 # Sift for real versus user names
135 /** @var $user User */
136 foreach ( $contributors as $user ) {
138 if ( $user->isLoggedIn() ) {
139 $link = $this->link( $user );
140 if ( $this->canShowRealUserName() && $user->getRealName() ) {
141 $real_names[] = $link;
143 $user_names[] = $link;
146 $anon_ips[] = $this->link( $user );
154 $lang = $this->getLanguage();
156 if ( count( $real_names ) ) {
157 $real = $lang->listToText( $real_names );
162 # "ThisSite user(s) A, B and C"
163 if ( count( $user_names ) ) {
164 $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
165 count( $user_names ) )->escaped();
170 if ( count( $anon_ips ) ) {
171 $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
172 count( $anon_ips ) )->escaped();
177 # This is the big list, all mooshed together. We sift for blank strings
179 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
180 if ( $s !== false ) {
181 array_push( $fulllist, $s );
185 $count = count( $fulllist );
187 # "Based on work by ..."
189 ?
$this->msg( 'othercontribs' )->rawParams(
190 $lang->listToText( $fulllist ) )->params( $count )->escaped()
195 * Get a link to $user's user page
197 * @return string Html
199 protected function link( User
$user ) {
200 if ( $this->canShowRealUserName() && !$user->isAnon() ) {
201 $real = $user->getRealName();
206 $page = $user->isAnon()
207 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
208 : $user->getUserPage();
210 return Linker
::link( $page, htmlspecialchars( $real ?
$real : $user->getName() ) );
214 * Get a link to $user's user page
216 * @return string Html
218 protected function userLink( User
$user ) {
219 $link = $this->link( $user );
220 if ( $user->isAnon() ) {
221 return $this->msg( 'anonuser' )->rawParams( $link )->parse();
223 if ( $this->canShowRealUserName() && $user->getRealName() ) {
226 return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
232 * Get a link to action=credits of $article page
233 * @return string HTML link
235 protected function othersLink() {
236 return Linker
::linkKnown(
238 $this->msg( 'others' )->escaped(),
240 array( 'action' => 'credits' )