* Select the content language in prefs when bogus interface language is set
[mediawiki.git] / includes / Credits.php
blob259c70fdab154712707f8cdadb1a4ed24c673afd
1 <?php
2 /**
3 * Credits.php -- formats credits for articles
4 * Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
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.
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.
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
20 * @author <evan@wikitravel.org>
21 * @package MediaWiki
24 /**
25 * This is largely cadged from PageHistory::history
27 function showCreditsPage($article) {
28 global $wgOut;
30 $fname = 'showCreditsPage';
32 wfProfileIn( $fname );
34 $wgOut->setPageTitle( $article->mTitle->getPrefixedText() );
35 $wgOut->setSubtitle( wfMsg( 'creditspage' ) );
36 $wgOut->setArticleFlag( false );
37 $wgOut->setArticleRelated( true );
38 $wgOut->setRobotpolicy( 'noindex,nofollow' );
40 if( $article->mTitle->getArticleID() == 0 ) {
41 $s = wfMsg( 'nocredits' );
42 } else {
43 $s = getCredits($article, -1);
46 $wgOut->addHTML( $s );
48 wfProfileOut( $fname );
51 function getCredits($article, $cnt, $showIfMax=true) {
53 $s = '';
55 if (isset($cnt) && $cnt != 0) {
56 $s = getAuthorCredits($article);
57 if ($cnt > 1 || $cnt < 0) {
58 $s .= ' ' . getContributorCredits($article, $cnt - 1, $showIfMax);
62 return $s;
65 /**
68 function getAuthorCredits($article) {
69 global $wgLang;
71 $last_author = $article->getUser();
73 if ($last_author == 0) {
74 $author_credit = wfMsg('anonymous');
75 } else {
77 $real_name = User::whoIsReal($last_author);
78 $user_name = User::whoIs($last_author);
80 if (!empty($real_name)) {
81 $author_credit = creditLink($user_name, $real_name);
82 } else {
83 $author_credit = wfMsg('siteuser', creditLink($user_name));
87 $timestamp = $article->getTimestamp();
88 if ($timestamp) {
89 $d = $wgLang->timeanddate($article->getTimestamp(), true);
90 } else {
91 $d = '';
93 return wfMsg('lastmodifiedby', $d, $author_credit);
96 /**
99 function getContributorCredits($article, $cnt, $showIfMax) {
101 global $wgLang, $wgAllowRealName;
103 $contributors = $article->getContributors();
105 $others_link = '';
107 # Hmm... too many to fit!
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);
118 $real_names = array();
119 $user_names = array();
121 $anon = '';
123 # Sift for real versus user names
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]);
132 } else {
133 $anon = wfMsg('anonymous');
137 # Two strings: real names, and user names
139 $real = $wgLang->listToText($real_names);
140 $user = $wgLang->listToText($user_names);
142 # "ThisSite user(s) A, B and C"
144 if (!empty($user)) {
145 $user = wfMsg('siteusers', $user);
148 # This is the big list, all mooshed together. We sift for blank strings
150 $fulllist = array();
152 foreach (array($real, $user, $anon, $others_link) as $s) {
153 if (!empty($s)) {
154 array_push($fulllist, $s);
158 # Make the list into text...
160 $creds = $wgLang->listToText($fulllist);
162 # "Based on work by ..."
164 return (empty($creds)) ? '' : wfMsg('othercontribs', $creds);
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 ));
180 function creditOthersLink($article) {
181 global $wgUser, $wgLang;
182 $skin = $wgUser->getSkin();
183 return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), 'action=credits');