Make user names (and real names) in credits block link to user pages.
[lhc/web/wiklou.git] / includes / Credits.php
1 <?php
2
3 /* Credits.php -- formats credits for articles
4 * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
5 *
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.
10 *
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.
15 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 /* This is largely cadged from PageHistory::history */
22
23 function showCreditsPage($article)
24 {
25 global $wgOut;
26
27 $fname = "showCreditsPage";
28
29 wfProfileIn( $fname );
30
31 $wgOut->setPageTitle( $article->mTitle->getPrefixedText() );
32 $wgOut->setSubtitle( wfMsg( "creditspage" ) );
33 $wgOut->setArticleFlag( false );
34 $wgOut->setArticleRelated( true );
35 $wgOut->setRobotpolicy( "noindex,nofollow" );
36
37 if( $article->mTitle->getArticleID() == 0 ) {
38 $s = wfMsg( "nocredits" );
39 } else {
40 $s = getCredits($article, -1);
41 }
42
43 $wgOut->addHTML( $s );
44
45 wfProfileOut( $fname );
46 }
47
48 function getCredits($article, $cnt) {
49
50 $s = '';
51
52 if (isset($cnt) && $cnt != 0) {
53 $s = getAuthorCredits($article);
54 if ($cnt > 1 || $cnt < 0) {
55 $s .= ' ' . getContributorCredits($article, $cnt - 1);
56 }
57 }
58
59 return $s;
60 }
61
62 function getAuthorCredits($article) {
63
64 global $wgLang;
65
66 $last_author = $article->getUser();
67
68 if ($last_author == 0) {
69 $author_credit = wfMsg('anonymous');
70 } else {
71
72 $real_name = User::whoIsReal($last_author);
73 $user_name = User::whoIs($last_author);
74
75 if (!empty($real_name)) {
76 $author_credit = creditLink($user_name, $real_name);
77 } else {
78 $author_credit = wfMsg('siteuser', creditLink($user_name));
79 }
80 }
81
82 $timestamp = $article->getTimestamp();
83 if ($timestamp) {
84 $d = $wgLang->timeanddate($article->getTimestamp(), true);
85 } else {
86 $d = '';
87 }
88 return wfMsg('lastmodifiedby', $d, $author_credit);
89 }
90
91 function getContributorCredits($article, $cnt) {
92
93 global $wgLang, $wgAllowRealName;
94
95 $contributors = $article->getContributors($cnt);
96
97 $real_names = array();
98 $user_names = array();
99
100 # Sift for real versus user names
101
102 foreach ($contributors as $user_id => $user_parts) {
103 if ($user_id != 0) {
104 if ($wgAllowRealName && !empty($user_parts[1])) {
105 $real_names[$user_id] = creditLink($user_parts[0], $user_parts[1]);
106 } else {
107 $user_names[$user_id] = creditLink($user_parts[0]);
108 }
109 }
110 }
111
112 $real = $wgLang->listToText(array_values($real_names));
113 $user = $wgLang->listToText(array_values($user_names));
114
115 if (!empty($user)) {
116 $user = wfMsg('siteusers', $user);
117 }
118
119 if ($contributors[0] && $contributors[0][0] > 0) {
120 $anon = wfMsg('anonymous');
121 } else {
122 $anon = '';
123 }
124
125 $creds = $wgLang->listToText(array($real, $user, $anon));
126
127 return wfMsg('othercontribs', $creds);
128 }
129
130 function creditLink($user_name, $link_text = '') {
131 global $wgUser, $wgLang;
132 $skin = $wgUser->getSkin();
133 return $skin->makeKnownLink($wgLang->getNsText(NS_USER) . ":" . $user_name,
134 (empty($link_text)) ? $user_name : $link_text);
135 }
136
137 ?>