62f0b2566a797b750323179ad0bbbdd1f7bcde7f
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 $fname = 'getCredits';
53 wfProfileIn( $fname );
54 $s = '';
55
56 if (isset($cnt) && $cnt != 0) {
57 $s = getAuthorCredits($article);
58 if ($cnt > 1 || $cnt < 0) {
59 $s .= ' ' . getContributorCredits($article, $cnt - 1, $showIfMax);
60 }
61 }
62
63 wfProfileOut( $fname );
64 return $s;
65 }
66
67 /**
68 *
69 */
70 function getAuthorCredits($article) {
71 global $wgLang, $wgAllowRealName;
72
73 $last_author = $article->getUser();
74
75 if ($last_author == 0) {
76 $author_credit = wfMsg('anonymous');
77 } else {
78 if($wgAllowRealName) { $real_name = User::whoIsReal($last_author); }
79 $user_name = User::whoIs($last_author);
80
81 if (!empty($real_name)) {
82 $author_credit = creditLink($user_name, $real_name);
83 } else {
84 $author_credit = wfMsg('siteuser', creditLink($user_name));
85 }
86 }
87
88 $timestamp = $article->getTimestamp();
89 if ($timestamp) {
90 $d = $wgLang->date($article->getTimestamp(), true);
91 $t = $wgLang->time($article->getTimestamp(), true);
92 } else {
93 $d = '';
94 $t = '';
95 }
96 return wfMsg('lastmodifiedatby', $d, $t, $author_credit);
97 }
98
99 /**
100 *
101 */
102 function getContributorCredits($article, $cnt, $showIfMax) {
103
104 global $wgLang, $wgAllowRealName;
105
106 $contributors = $article->getContributors();
107
108 $others_link = '';
109
110 # Hmm... too many to fit!
111
112 if ($cnt > 0 && count($contributors) > $cnt) {
113 $others_link = creditOthersLink($article);
114 if (!$showIfMax) {
115 return wfMsg('othercontribs', $others_link);
116 } else {
117 $contributors = array_slice($contributors, 0, $cnt);
118 }
119 }
120
121 $real_names = array();
122 $user_names = array();
123
124 $anon = '';
125
126 # Sift for real versus user names
127
128 foreach ($contributors as $user_parts) {
129 if ($user_parts[0] != 0) {
130 if ($wgAllowRealName && !empty($user_parts[2])) {
131 $real_names[] = creditLink($user_parts[1], $user_parts[2]);
132 } else {
133 $user_names[] = creditLink($user_parts[1]);
134 }
135 } else {
136 $anon = wfMsg('anonymous');
137 }
138 }
139
140 # Two strings: real names, and user names
141
142 $real = $wgLang->listToText($real_names);
143 $user = $wgLang->listToText($user_names);
144
145 # "ThisSite user(s) A, B and C"
146
147 if (!empty($user)) {
148 $user = wfMsg('siteusers', $user);
149 }
150
151 # This is the big list, all mooshed together. We sift for blank strings
152
153 $fulllist = array();
154
155 foreach (array($real, $user, $anon, $others_link) as $s) {
156 if (!empty($s)) {
157 array_push($fulllist, $s);
158 }
159 }
160
161 # Make the list into text...
162
163 $creds = $wgLang->listToText($fulllist);
164
165 # "Based on work by ..."
166
167 return (empty($creds)) ? '' : wfMsg('othercontribs', $creds);
168 }
169
170 /**
171 *
172 */
173 function creditLink($user_name, $link_text = '') {
174 global $wgUser, $wgContLang;
175 $skin = $wgUser->getSkin();
176 return $skin->makeLink($wgContLang->getNsText(NS_USER) . ':' . $user_name,
177 htmlspecialchars( (empty($link_text)) ? $user_name : $link_text ));
178 }
179
180 /**
181 *
182 */
183 function creditOthersLink($article) {
184 global $wgUser;
185 $skin = $wgUser->getSkin();
186 return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), 'action=credits');
187 }
188
189 ?>