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