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 );
52 return Html
::rawElement( 'div', array( 'id' => 'mw-credits' ), $s );
56 * Get a list of contributors
58 * @param int $cnt Maximum list of contributors to show
59 * @param bool $showIfMax Whether to contributors if there more than $cnt
62 public function getCredits( $cnt, $showIfMax = true ) {
66 $s = $this->getAuthor( $this->page
);
67 if ( $cnt > 1 ||
$cnt < 0 ) {
68 $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
76 * Get the last author with the last modification time
80 protected function getAuthor( Page
$page ) {
81 $user = User
::newFromName( $page->getUserText(), false );
83 $timestamp = $page->getTimestamp();
85 $lang = $this->getLanguage();
86 $d = $lang->date( $page->getTimestamp(), true );
87 $t = $lang->time( $page->getTimestamp(), true );
93 return $this->msg( 'lastmodifiedatby', $d, $t )->rawParams(
94 $this->userLink( $user ) )->params( $user->getName() )->escaped();
98 * Whether we can display the user's real name (not a hidden pref)
103 protected function canShowRealUserName() {
104 $hiddenPrefs = $this->context
->getConfig()->get( 'HiddenPrefs' );
105 return !in_array( 'realname', $hiddenPrefs );
109 * Get a list of contributors of $article
110 * @param int $cnt Maximum list of contributors to show
111 * @param bool $showIfMax Whether to contributors if there more than $cnt
112 * @return string Html
114 protected function getContributors( $cnt, $showIfMax ) {
115 $contributors = $this->page
->getContributors();
117 $others_link = false;
119 # Hmm... too many to fit!
120 if ( $cnt > 0 && $contributors->count() > $cnt ) {
121 $others_link = $this->othersLink();
123 return $this->msg( 'othercontribs' )->rawParams(
124 $others_link )->params( $contributors->count() )->escaped();
128 $real_names = array();
129 $user_names = array();
132 # Sift for real versus user names
133 /** @var $user User */
134 foreach ( $contributors as $user ) {
136 if ( $user->isLoggedIn() ) {
137 $link = $this->link( $user );
138 if ( $this->canShowRealUserName() && $user->getRealName() ) {
139 $real_names[] = $link;
141 $user_names[] = $link;
144 $anon_ips[] = $this->link( $user );
152 $lang = $this->getLanguage();
154 if ( count( $real_names ) ) {
155 $real = $lang->listToText( $real_names );
160 # "ThisSite user(s) A, B and C"
161 if ( count( $user_names ) ) {
162 $user = $this->msg( 'siteusers' )->rawParams( $lang->listToText( $user_names ) )->params(
163 count( $user_names ) )->escaped();
168 if ( count( $anon_ips ) ) {
169 $anon = $this->msg( 'anonusers' )->rawParams( $lang->listToText( $anon_ips ) )->params(
170 count( $anon_ips ) )->escaped();
175 # This is the big list, all mooshed together. We sift for blank strings
177 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
178 if ( $s !== false ) {
179 array_push( $fulllist, $s );
183 $count = count( $fulllist );
185 # "Based on work by ..."
187 ?
$this->msg( 'othercontribs' )->rawParams(
188 $lang->listToText( $fulllist ) )->params( $count )->escaped()
193 * Get a link to $user's user page
195 * @return string Html
197 protected function link( User
$user ) {
198 if ( $this->canShowRealUserName() && !$user->isAnon() ) {
199 $real = $user->getRealName();
204 $page = $user->isAnon()
205 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
206 : $user->getUserPage();
208 return Linker
::link( $page, htmlspecialchars( $real ?
$real : $user->getName() ) );
212 * Get a link to $user's user page
214 * @return string Html
216 protected function userLink( User
$user ) {
217 $link = $this->link( $user );
218 if ( $user->isAnon() ) {
219 return $this->msg( 'anonuser' )->rawParams( $link )->parse();
221 if ( $this->canShowRealUserName() && $user->getRealName() ) {
224 return $this->msg( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
230 * Get a link to action=credits of $article page
231 * @return string HTML link
233 protected function othersLink() {
234 return Linker
::linkKnown(
236 $this->msg( 'others' )->escaped(),
238 array( 'action' => 'credits' )