DB error log
[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, $showIfMax=true) {
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, $showIfMax);
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, $showIfMax) {
92
93 global $wgLang, $wgAllowRealName;
94
95 $contributors = $article->getContributors();
96
97 $others_link = '';
98
99 # Hmm... too many to fit!
100
101 if ($cnt > 0 && count($contributors) > $cnt) {
102 $others_link = creditOthersLink($article);
103 if (!$showIfMax) {
104 return wfMsg('othercontribs', $others_link);
105 } else {
106 $contributors = array_slice($contributors, 0, $cnt);
107 }
108 }
109
110 $real_names = array();
111 $user_names = array();
112
113 $anon = '';
114
115 # Sift for real versus user names
116
117 foreach ($contributors as $user_parts) {
118 if ($user_parts[0] != 0) {
119 if ($wgAllowRealName && !empty($user_parts[2])) {
120 $real_names[] = creditLink($user_parts[1], $user_parts[2]);
121 } else {
122 $user_names[] = creditLink($user_parts[1]);
123 }
124 } else {
125 $anon = wfMsg('anonymous');
126 }
127 }
128
129 # Two strings: real names, and user names
130
131 $real = $wgLang->listToText($real_names);
132 $user = $wgLang->listToText($user_names);
133
134 # "ThisSite user(s) A, B and C"
135
136 if (!empty($user)) {
137 $user = wfMsg('siteusers', $user);
138 }
139
140 # This is the big list, all mooshed together. We sift for blank strings
141
142 $fulllist = array();
143
144 foreach (array($real, $user, $anon, $others_link) as $s) {
145 if (!empty($s)) {
146 array_push($fulllist, $s);
147 }
148 }
149
150 # Make the list into text...
151
152 $creds = $wgLang->listToText($fulllist);
153
154 # "Based on work by ..."
155
156 return (empty($creds)) ? '' : wfMsg('othercontribs', $creds);
157 }
158
159 function creditLink($user_name, $link_text = '') {
160 global $wgUser, $wgLang;
161 $skin = $wgUser->getSkin();
162 return $skin->makeLink($wgLang->getNsText(NS_USER) . ":" . $user_name,
163 (empty($link_text)) ? $user_name : $link_text);
164 }
165
166 function creditOthersLink($article) {
167 global $wgUser, $wgLang;
168 $skin = $wgUser->getSkin();
169 return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), "action=credits");
170 }
171
172 ?>