Moved credits stuff from Skin.php to a separate module. Added a "credits"
[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 wfDebug("Credits: '$s'\n");
44
45 $wgOut->addHTML( $s );
46
47 wfProfileOut( $fname );
48 }
49
50 function getCredits($article, $cnt) {
51
52 $s = '';
53
54 if (isset($cnt) && $cnt != 0) {
55 $s = getAuthorCredits($article);
56 if ($cnt > 1 || $cnt < 0) {
57 $s .= ' ' . getContributorCredits($article, $cnt - 1);
58 }
59 }
60
61 return $s;
62 }
63
64 function getAuthorCredits($article) {
65
66 global $wgLang;
67
68 $last_author = $article->getUser();
69
70 if ($last_author == 0) {
71 $author_credit = wfMsg('anonymous');
72 } else {
73 $real_name = User::whoIsReal($last_author);
74 if (!empty($real_name)) {
75 $author_credit = $real_name;
76 } else {
77 $author_credit = wfMsg('siteuser', User::whoIs($last_author));
78 }
79 }
80
81 $timestamp = $article->getTimestamp();
82 if ($timestamp) {
83 $d = $wgLang->timeanddate($article->getTimestamp(), true);
84 } else {
85 $d = '';
86 }
87 return wfMsg('lastmodifiedby', $d, $author_credit);
88 }
89
90 function getContributorCredits($article, $cnt) {
91
92 global $wgLang, $wgAllowRealName;
93
94 $contributors = $article->getContributors($cnt);
95
96 $real_names = array();
97 $user_names = array();
98
99 # Sift for real versus user names
100
101 foreach ($contributors as $user_id => $user_parts) {
102 if ($user_id != 0) {
103 if ($wgAllowRealName && !empty($user_parts[1])) {
104 $real_names[$user_id] = $user_parts[1];
105 } else {
106 $user_names[$user_id] = $user_parts[0];
107 }
108 }
109 }
110
111 $real = $wgLang->listToText(array_values($real_names));
112 $user = $wgLang->listToText(array_values($user_names));
113
114 if (!empty($user)) {
115 $user = wfMsg('siteusers', $user);
116 }
117
118 if ($contributors[0] && $contributors[0][0] > 0) {
119 $anon = wfMsg('anonymous');
120 } else {
121 $anon = '';
122 }
123
124 $creds = $wgLang->listToText(array($real, $user, $anon));
125
126 return wfMsg('othercontribs', $creds);
127 }
128
129 ?>