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() {
37 * This is largely cadged from PageHistory::history
39 public function onView() {
40 wfProfileIn( __METHOD__
);
42 if ( $this->page
->getID() == 0 ) {
43 $s = wfMsg( 'nocredits' );
45 $s = $this->getCredits( -1 );
48 wfProfileOut( __METHOD__
);
54 * Get a list of contributors of $article
55 * @param $article Article object
56 * @param $cnt Int: maximum list of contributors to show
57 * @param $showIfMax Bool: whether to contributors if there more than $cnt
58 * @return String: html
60 public function getCredits( $cnt, $showIfMax = true ) {
61 wfProfileIn( __METHOD__
);
64 if ( isset( $cnt ) && $cnt != 0 ) {
65 $s = self
::getAuthor( $this->page
);
66 if ( $cnt > 1 ||
$cnt < 0 ) {
67 $s .= ' ' . $this->getContributors( $cnt - 1, $showIfMax );
71 wfProfileOut( __METHOD__
);
76 * Get the last author with the last modification time
77 * @param $article Article object
79 protected static function getAuthor( Article
$article ) {
82 $user = User
::newFromId( $article->getUser() );
84 $timestamp = $article->getTimestamp();
86 $d = $wgLang->date( $article->getTimestamp(), true );
87 $t = $wgLang->time( $article->getTimestamp(), true );
92 return wfMessage( 'lastmodifiedatby', $d, $t )->rawParams( self
::userLink( $user ) )->params( $user->getName() )->escaped();
96 * Get a list of contributors of $article
97 * @param $article Article object
98 * @param $cnt Int: maximum list of contributors to show
99 * @param $showIfMax Bool: whether to contributors if there more than $cnt
100 * @return String: html
102 protected function getContributors( $cnt, $showIfMax ) {
103 global $wgLang, $wgHiddenPrefs;
105 $contributors = $this->page
->getContributors();
107 $others_link = false;
109 # Hmm... too many to fit!
110 if ( $cnt > 0 && $contributors->count() > $cnt ) {
111 $others_link = $this->othersLink();
113 return wfMessage( 'othercontribs' )->rawParams( $others_link )->params( $contributors->count() )->escaped();
116 $real_names = array();
117 $user_names = array();
120 # Sift for real versus user names
121 foreach ( $contributors as $user ) {
123 if ( $user->isLoggedIn() ) {
124 $link = self
::link( $user );
125 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
126 $real_names[] = $link;
128 $user_names[] = $link;
131 $anon_ips[] = self
::link( $user );
139 if ( count( $real_names ) ) {
140 $real = $wgLang->listToText( $real_names );
145 # "ThisSite user(s) A, B and C"
146 if ( count( $user_names ) ) {
147 $user = wfMessage( 'siteusers' )->rawParams( $wgLang->listToText( $user_names ) )->params(
148 count( $user_names ) )->escaped();
153 if ( count( $anon_ips ) ) {
154 $anon = wfMessage( 'anonusers' )->rawParams( $wgLang->listToText( $anon_ips ) )->params(
155 count( $anon_ips ) )->escaped();
160 # This is the big list, all mooshed together. We sift for blank strings
162 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
163 if ( $s !== false ) {
164 array_push( $fulllist, $s );
168 $count = count( $fulllist );
169 # "Based on work by ..."
171 ?
wfMessage( 'othercontribs' )->rawParams(
172 $wgLang->listToText( $fulllist ) )->params( $count )->escaped()
177 * Get a link to $user's user page
178 * @param $user User object
179 * @return String: html
181 protected static function link( User
$user ) {
182 global $wgHiddenPrefs;
183 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
184 $real = $user->getRealName();
189 $page = $user->isAnon()
190 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
191 : $user->getUserPage();
193 return Linker
::link( $page, htmlspecialchars( $real ?
$real : $user->getName() ) );
197 * Get a link to $user's user page
198 * @param $user User object
199 * @return String: html
201 protected static function userLink( User
$user ) {
202 $link = self
::link( $user );
203 if ( $user->isAnon() ) {
204 return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
206 global $wgHiddenPrefs;
207 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
210 return wfMessage( 'siteuser' )->rawParams( $link )->params( $user->getName() )->escaped();
216 * Get a link to action=credits of $article page
217 * @param $article Article object
218 * @return String: html
220 protected function othersLink() {
223 wfMsgHtml( 'others' ),
225 array( 'action' => 'credits' ),