* Rewrote showEXIFdata() to use addWikiText() instead of addHTML()
[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 * @author <evan@wikitravel.org>
21 * @package MediaWiki
22 */
23
24 /**
25 * This is largely cadged from PageHistory::history
26 */
27 function showCreditsPage($article) {
28 global $wgOut;
29
30 $fname = 'showCreditsPage';
31
32 wfProfileIn( $fname );
33
34 $wgOut->setPageTitle( $article->mTitle->getPrefixedText() );
35 $wgOut->setSubtitle( wfMsg( 'creditspage' ) );
36 $wgOut->setArticleFlag( false );
37 $wgOut->setArticleRelated( true );
38 $wgOut->setRobotpolicy( 'noindex,nofollow' );
39
40 if( $article->mTitle->getArticleID() == 0 ) {
41 $s = wfMsg( 'nocredits' );
42 } else {
43 $s = getCredits($article, -1);
44 }
45
46 $wgOut->addHTML( $s );
47
48 wfProfileOut( $fname );
49 }
50
51 function getCredits($article, $cnt, $showIfMax=true) {
52
53 $s = '';
54
55 if (isset($cnt) && $cnt != 0) {
56 $s = getAuthorCredits($article);
57 if ($cnt > 1 || $cnt < 0) {
58 $s .= ' ' . getContributorCredits($article, $cnt - 1, $showIfMax);
59 }
60 }
61
62 return $s;
63 }
64
65 /**
66 *
67 */
68 function getAuthorCredits($article) {
69 global $wgLang;
70
71 $last_author = $article->getUser();
72
73 if ($last_author == 0) {
74 $author_credit = wfMsg('anonymous');
75 } else {
76
77 $real_name = User::whoIsReal($last_author);
78 $user_name = User::whoIs($last_author);
79
80 if (!empty($real_name)) {
81 $author_credit = creditLink($user_name, $real_name);
82 } else {
83 $author_credit = wfMsg('siteuser', creditLink($user_name));
84 }
85 }
86
87 $timestamp = $article->getTimestamp();
88 if ($timestamp) {
89 $d = $wgLang->timeanddate($article->getTimestamp(), true);
90 } else {
91 $d = '';
92 }
93 return wfMsg('lastmodifiedby', $d, $author_credit);
94 }
95
96 /**
97 *
98 */
99 function getContributorCredits($article, $cnt, $showIfMax) {
100
101 global $wgLang, $wgAllowRealName;
102
103 $contributors = $article->getContributors();
104
105 $others_link = '';
106
107 # Hmm... too many to fit!
108
109 if ($cnt > 0 && count($contributors) > $cnt) {
110 $others_link = creditOthersLink($article);
111 if (!$showIfMax) {
112 return wfMsg('othercontribs', $others_link);
113 } else {
114 $contributors = array_slice($contributors, 0, $cnt);
115 }
116 }
117
118 $real_names = array();
119 $user_names = array();
120
121 $anon = '';
122
123 # Sift for real versus user names
124
125 foreach ($contributors as $user_parts) {
126 if ($user_parts[0] != 0) {
127 if ($wgAllowRealName && !empty($user_parts[2])) {
128 $real_names[] = creditLink($user_parts[1], $user_parts[2]);
129 } else {
130 $user_names[] = creditLink($user_parts[1]);
131 }
132 } else {
133 $anon = wfMsg('anonymous');
134 }
135 }
136
137 # Two strings: real names, and user names
138
139 $real = $wgLang->listToText($real_names);
140 $user = $wgLang->listToText($user_names);
141
142 # "ThisSite user(s) A, B and C"
143
144 if (!empty($user)) {
145 $user = wfMsg('siteusers', $user);
146 }
147
148 # This is the big list, all mooshed together. We sift for blank strings
149
150 $fulllist = array();
151
152 foreach (array($real, $user, $anon, $others_link) as $s) {
153 if (!empty($s)) {
154 array_push($fulllist, $s);
155 }
156 }
157
158 # Make the list into text...
159
160 $creds = $wgLang->listToText($fulllist);
161
162 # "Based on work by ..."
163
164 return (empty($creds)) ? '' : wfMsg('othercontribs', $creds);
165 }
166
167 /**
168 *
169 */
170 function creditLink($user_name, $link_text = '') {
171 global $wgUser, $wgContLang;
172 $skin = $wgUser->getSkin();
173 return $skin->makeLink($wgContLang->getNsText(NS_USER) . ':' . $user_name,
174 htmlspecialchars( (empty($link_text)) ? $user_name : $link_text ));
175 }
176
177 /**
178 *
179 */
180 function creditOthersLink($article) {
181 global $wgUser, $wgLang;
182 $skin = $wgUser->getSkin();
183 return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), 'action=credits');
184 }
185
186 ?>