576834faaae9c9d03f9bb5065017a7d0f793551a
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 protected 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 wfMsgExt( 'lastmodifiedatby', 'parsemag', $d, $t, self
::userLink( $user ), $user->getName() );
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 wfMsgExt( 'othercontribs', 'parsemag', $others_link, $contributors->count() );
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 ) ) {
150 $wgLang->listToText( $user_names ), count( $user_names )
156 if ( count( $anon_ips ) ) {
160 $wgLang->listToText( $anon_ips ), count( $anon_ips )
166 # This is the big list, all mooshed together. We sift for blank strings
168 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
170 array_push( $fulllist, $s );
174 # Make the list into text...
175 $creds = $wgLang->listToText( $fulllist );
177 # "Based on work by ..."
178 return strlen( $creds )
179 ?
wfMsgExt( 'othercontribs', 'parsemag', $creds, count( $fulllist ) )
184 * Get a link to $user's user page
185 * @param $user User object
186 * @return String: html
188 protected static function link( User
$user ) {
189 global $wgUser, $wgHiddenPrefs;
190 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
191 $real = $user->getRealName();
196 $page = $user->isAnon()
197 ? SpecialPage
::getTitleFor( 'Contributions', $user->getName() )
198 : $user->getUserPage();
200 return Linker
::link( $page, htmlspecialchars( $real ?
$real : $user->getName() ) );
204 * Get a link to $user's user page
205 * @param $user User object
206 * @return String: html
208 protected static function userLink( User
$user ) {
209 $link = self
::link( $user );
210 if ( $user->isAnon() ) {
211 return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
213 global $wgHiddenPrefs;
214 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
217 return wfMsgExt( 'siteuser', 'parsemag', $link, $user->getName() );
223 * Get a link to action=credits of $article page
224 * @param $article Article object
225 * @return String: html
227 protected function othersLink() {
231 wfMsgHtml( 'others' ),
233 array( 'action' => 'credits' ),