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
21 /* This is largely cadged from PageHistory::history */
23 function showCreditsPage($article)
27 $fname = "showCreditsPage";
29 wfProfileIn( $fname );
31 $wgOut->setPageTitle( $article->mTitle
->getPrefixedText() );
32 $wgOut->setSubtitle( wfMsg( "creditspage" ) );
33 $wgOut->setArticleFlag( false );
34 $wgOut->setArticleRelated( true );
35 $wgOut->setRobotpolicy( "noindex,nofollow" );
37 if( $article->mTitle
->getArticleID() == 0 ) {
38 $s = wfMsg( "nocredits" );
40 $s = getCredits($article, -1);
43 $wgOut->addHTML( $s );
45 wfProfileOut( $fname );
48 function getCredits($article, $cnt, $showIfMax=true) {
52 if (isset($cnt) && $cnt != 0) {
53 $s = getAuthorCredits($article);
54 if ($cnt > 1 ||
$cnt < 0) {
55 $s .= ' ' . getContributorCredits($article, $cnt - 1, $showIfMax);
62 function getAuthorCredits($article) {
66 $last_author = $article->getUser();
68 if ($last_author == 0) {
69 $author_credit = wfMsg('anonymous');
72 $real_name = User
::whoIsReal($last_author);
73 $user_name = User
::whoIs($last_author);
75 if (!empty($real_name)) {
76 $author_credit = creditLink($user_name, $real_name);
78 $author_credit = wfMsg('siteuser', creditLink($user_name));
82 $timestamp = $article->getTimestamp();
84 $d = $wgLang->timeanddate($article->getTimestamp(), true);
88 return wfMsg('lastmodifiedby', $d, $author_credit);
91 function getContributorCredits($article, $cnt, $showIfMax) {
93 global $wgLang, $wgAllowRealName;
95 $contributors = $article->getContributors();
99 # Hmm... too many to fit!
101 if ($cnt > 0 && count($contributors) > $cnt) {
102 $others_link = creditOthersLink($article);
104 return wfMsg('othercontribs', $others_link);
106 $contributors = array_slice($contributors, 0, $cnt);
110 $real_names = array();
111 $user_names = array();
115 # Sift for real versus user names
117 foreach ($contributors as $user_parts) {
118 if ($user_parts[0] != 0) {
119 if ($wgAllowRealName && !empty($user_parts[2])) {
120 $real_names[] = creditLink($user_parts[1], $user_parts[2]);
122 $user_names[] = creditLink($user_parts[1]);
125 $anon = wfMsg('anonymous');
129 # Two strings: real names, and user names
131 $real = $wgLang->listToText($real_names);
132 $user = $wgLang->listToText($user_names);
134 # "ThisSite user(s) A, B and C"
137 $user = wfMsg('siteusers', $user);
140 # This is the big list, all mooshed together. We sift for blank strings
144 foreach (array($real, $user, $anon, $others_link) as $s) {
146 array_push($fulllist, $s);
150 # Make the list into text...
152 $creds = $wgLang->listToText($fulllist);
154 # "Based on work by ..."
156 return (empty($creds)) ?
'' : wfMsg('othercontribs', $creds);
159 function creditLink($user_name, $link_text = '') {
160 global $wgUser, $wgLang;
161 $skin = $wgUser->getSkin();
162 return $skin->makeLink($wgLang->getNsText(NS_USER
) . ":" . $user_name,
163 (empty($link_text)) ?
$user_name : $link_text);
166 function creditOthersLink($article) {
167 global $wgUser, $wgLang;
168 $skin = $wgUser->getSkin();
169 return $skin->makeKnownLink($article->mTitle
->getPrefixedText(), wfMsg('others'), "action=credits");