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;
127 $anon_ips[] = self
::link( $user );
129 if ( $cnt == 0 ) break;
132 if ( count( $real_names ) ) {
133 $real = $wgLang->listToText( $real_names );
138 # "ThisSite user(s) A, B and C"
139 if ( count( $user_names ) ) {
140 $user = wfMsgExt( 'siteusers', array( 'parsemag' ),
141 $wgLang->listToText( $user_names ), count( $user_names ) );
146 if ( count( $anon_ips ) ) {
147 $anon = wfMsgExt( 'anonusers', array( 'parsemag' ),
148 $wgLang->listToText( $anon_ips ), count( $anon_ips ) );
153 # This is the big list, all mooshed together. We sift for blank strings
155 foreach ( array( $real, $user, $anon, $others_link ) as $s ) {
157 array_push( $fulllist, $s );
161 # Make the list into text...
162 $creds = $wgLang->listToText( $fulllist );
164 # "Based on work by ..."
165 return strlen( $creds )
166 ?
wfMsgExt( 'othercontribs', 'parsemag', $creds, count( $fulllist ) )
171 * Get a link to $user's user page
172 * @param $user User object
173 * @return String: html
175 protected static function link( User
$user ) {
176 global $wgUser, $wgHiddenPrefs;
177 if ( !in_array( 'realname', $wgHiddenPrefs ) && !$user->isAnon() )
178 $real = $user->getRealName();
182 $skin = $wgUser->getSkin();
183 $page = $user->isAnon() ?
184 SpecialPage
::getTitleFor( 'Contributions', $user->getName() ) :
185 $user->getUserPage();
187 return $skin->link( $page, htmlspecialchars( $real ?
$real : $user->getName() ) );
191 * Get a link to $user's user page
192 * @param $user User object
193 * @return String: html
195 protected static function userLink( User
$user ) {
196 $link = self
::link( $user );
197 if ( $user->isAnon() ) {
198 return wfMsgExt( 'anonuser', array( 'parseinline', 'replaceafter' ), $link );
200 global $wgHiddenPrefs;
201 if ( !in_array( 'realname', $wgHiddenPrefs ) && $user->getRealName() )
204 return wfMsgExt( 'siteuser', array( 'parseinline', 'replaceafter' ), $link );
209 * Get a link to action=credits of $article page
210 * @param $article Article object
211 * @return String: html
213 protected static function othersLink( Article
$article ) {
215 $skin = $wgUser->getSkin();
217 $article->getTitle(),
218 wfMsgHtml( 'others' ),
220 array( 'action' => 'credits' ),