3 * Credits.php -- formats credits for articles
4 * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * @author <evan@wikitravel.org>
25 * This is largely cadged from PageHistory::history
26 * @param $article Article object
28 public static function showPage( Article
$article ) {
31 wfProfileIn( __METHOD__
);
33 $wgOut->setPageTitle( $article->mTitle
->getPrefixedText() );
34 $wgOut->setSubtitle( wfMsg( 'creditspage' ) );
35 $wgOut->setArticleFlag( false );
36 $wgOut->setArticleRelated( true );
37 $wgOut->setRobotPolicy( 'noindex,nofollow' );
39 if ( $article->mTitle
->getArticleID() == 0 ) {
40 $s = wfMsg( 'nocredits' );
42 $s = self
::getCredits( $article, -1 );
45 $wgOut->addHTML( $s );
47 wfProfileOut( __METHOD__
);
51 * Get a list of contributors of $article
52 * @param $article Article object
53 * @param $cnt Int: maximum list of contributors to show
54 * @param $showIfMax Bool: whether to contributors if there more than $cnt
55 * @return String: html
57 public static function getCredits( Article
$article, $cnt, $showIfMax = true ) {
58 wfProfileIn( __METHOD__
);
61 if ( isset( $cnt ) && $cnt != 0 ) {
62 $s = self
::getAuthor( $article );
63 if ( $cnt > 1 ||
$cnt < 0 ) {
64 $s .= ' ' . self
::getContributors( $article, $cnt - 1, $showIfMax );
68 wfProfileOut( __METHOD__
);
73 * Get the last author with the last modification time
74 * @param $article Article object
76 protected static function getAuthor( Article
$article ) {
79 $user = User
::newFromId( $article->getUser() );
81 $timestamp = $article->getTimestamp();
83 $d = $wgLang->date( $article->getTimestamp(), true );
84 $t = $wgLang->time( $article->getTimestamp(), true );
89 return wfMsgExt( 'lastmodifiedatby', 'parsemag', $d, $t, self
::userLink( $user ), $user->getName() );
93 * Get a list of contributors of $article
94 * @param $article Article object
95 * @param $cnt Int: maximum list of contributors to show
96 * @param $showIfMax Bool: whether to contributors if there more than $cnt
97 * @return String: html
99 protected static function getContributors( Article
$article, $cnt, $showIfMax ) {
100 global $wgLang, $wgHiddenPrefs;
102 $contributors = $article->getContributors();
104 $others_link = false;
106 # Hmm... too many to fit!
107 if ( $cnt > 0 && $contributors->count() > $cnt ) {
108 $others_link = self
::othersLink( $article );
110 return wfMsgExt( 'othercontribs', 'parsemag', $others_link, $contributors->count() );
113 $real_names = array();
114 $user_names = array();
117 # Sift for real versus user names
118 foreach ( $contributors as $user ) {
120 if ( $user->isLoggedIn() ) {
121 $link = self
::link( $user );
122 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
123 $real_names[] = $link;
125 $user_names[] = $link;
128 $anon_ips[] = self
::link( $user );
136 if ( count( $real_names ) ) {
137 $real = $wgLang->listToText( $real_names );
142 # "ThisSite user(s) A, B and C"
143 if ( count( $user_names ) ) {
147 $wgLang->listToText( $user_names ), count( $user_names )
153 if ( count( $anon_ips ) ) {
157 $wgLang->listToText( $anon_ips ), count( $anon_ips )
163 # This is the big list, all mooshed together. We sift for blank strings
165 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
167 array_push( $fulllist, $s );
171 # Make the list into text...
172 $creds = $wgLang->listToText( $fulllist );
174 # "Based on work by ..."
175 return strlen( $creds )
176 ?
wfMsgExt( 'othercontribs', 'parsemag', $creds, count( $fulllist ) )
181 * Get a link to $user's user page
182 * @param $user User object
183 * @return String: html
185 protected static function link( User
$user ) {
186 global $wgUser, $wgHiddenPrefs;
187 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() ) {
188 $real = $user->getRealName();
193 $skin = $wgUser->getSkin();
194 $page = $user->isAnon() ?
195 SpecialPage
::getTitleFor( 'Contributions', $user->getName() ) :
196 $user->getUserPage();
198 return $skin->link( $page, htmlspecialchars( $real ?
$real : $user->getName() ) );
202 * Get a link to $user's user page
203 * @param $user User object
204 * @return String: html
206 protected static function userLink( User
$user ) {
207 $link = self
::link( $user );
208 if ( $user->isAnon() ) {
209 return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
211 global $wgHiddenPrefs;
212 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() ) {
215 return wfMsgExt( 'siteuser', 'parsemag', $link, $user->getName() );
221 * Get a link to action=credits of $article page
222 * @param $article Article object
223 * @return String: html
225 protected static function othersLink( Article
$article ) {
227 $skin = $wgUser->getSkin();
229 $article->getTitle(),
230 wfMsgHtml( 'others' ),
232 array( 'action' => 'credits' ),