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
22 * @author <evan@wikitravel.org>
27 * This is largely cadged from PageHistory::history
28 * @param $article Article object
30 public static function showPage( Article
$article ) {
33 wfProfileIn( __METHOD__
);
35 $wgOut->setPageTitle( $article->mTitle
->getPrefixedText() );
36 $wgOut->setSubtitle( wfMsg( 'creditspage' ) );
37 $wgOut->setArticleFlag( false );
38 $wgOut->setArticleRelated( true );
39 $wgOut->setRobotPolicy( 'noindex,nofollow' );
41 if ( $article->mTitle
->getArticleID() == 0 ) {
42 $s = wfMsg( 'nocredits' );
44 $s = self
::getCredits( $article, -1 );
47 $wgOut->addHTML( $s );
49 wfProfileOut( __METHOD__
);
53 * Get a list of contributors of $article
54 * @param $article Article object
55 * @param $cnt Int: maximum list of contributors to show
56 * @param $showIfMax Bool: whether to contributors if there more than $cnt
57 * @return String: html
59 public static function getCredits( Article
$article, $cnt, $showIfMax = true ) {
60 wfProfileIn( __METHOD__
);
63 if ( isset( $cnt ) && $cnt != 0 ) {
64 $s = self
::getAuthor( $article );
65 if ( $cnt > 1 ||
$cnt < 0 ) {
66 $s .= ' ' . self
::getContributors( $article, $cnt - 1, $showIfMax );
70 wfProfileOut( __METHOD__
);
75 * Get the last author with the last modification time
76 * @param $article Article object
78 protected static function getAuthor( Article
$article ) {
81 $user = User
::newFromId( $article->getUser() );
83 $timestamp = $article->getTimestamp();
85 $d = $wgLang->date( $article->getTimestamp(), true );
86 $t = $wgLang->time( $article->getTimestamp(), true );
91 return wfMsgExt( 'lastmodifiedatby', 'parsemag', $d, $t, self
::userLink( $user ), $user->getName() );
95 * Get a list of contributors of $article
96 * @param $article Article object
97 * @param $cnt Int: maximum list of contributors to show
98 * @param $showIfMax Bool: whether to contributors if there more than $cnt
99 * @return String: html
101 protected static function getContributors( Article
$article, $cnt, $showIfMax ) {
102 global $wgLang, $wgHiddenPrefs;
104 $contributors = $article->getContributors();
106 $others_link = false;
108 # Hmm... too many to fit!
109 if ( $cnt > 0 && $contributors->count() > $cnt ) {
110 $others_link = self
::othersLink( $article );
112 return wfMsgExt( 'othercontribs', 'parsemag', $others_link, $contributors->count() );
115 $real_names = array();
116 $user_names = array();
119 # Sift for real versus user names
120 foreach ( $contributors as $user ) {
122 if ( $user->isLoggedIn() ) {
123 $link = self
::link( $user );
124 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
125 $real_names[] = $link;
127 $user_names[] = $link;
130 $anon_ips[] = self
::link( $user );
138 if ( count( $real_names ) ) {
139 $real = $wgLang->listToText( $real_names );
144 # "ThisSite user(s) A, B and C"
145 if ( count( $user_names ) ) {
149 $wgLang->listToText( $user_names ), count( $user_names )
155 if ( count( $anon_ips ) ) {
159 $wgLang->listToText( $anon_ips ), count( $anon_ips )
165 # This is the big list, all mooshed together. We sift for blank strings
167 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
169 array_push( $fulllist, $s );
173 # Make the list into text...
174 $creds = $wgLang->listToText( $fulllist );
176 # "Based on work by ..."
177 return strlen( $creds )
178 ?
wfMsgExt( 'othercontribs', 'parsemag', $creds, count( $fulllist ) )
183 * Get a link to $user's user page
184 * @param $user User object
185 * @return String: html
187 protected static function link( User
$user ) {
188 global $wgUser, $wgHiddenPrefs;
189 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
190 $real = $user->getRealName();
195 $skin = $wgUser->getSkin();
196 $page = $user->isAnon() ?
197 SpecialPage
::getTitleFor( 'Contributions', $user->getName() ) :
198 $user->getUserPage();
200 return $skin->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 static function othersLink( Article
$article ) {
229 $skin = $wgUser->getSkin();
231 $article->getTitle(),
232 wfMsgHtml( 'others' ),
234 array( 'action' => 'credits' ),