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