Allow raw HTML blocks in data['sidebar'] array. This provides a simple ways for exten...
[mediawiki.git] / includes / Credits.php
blob6326e3a2842f07d106ba6398b984300d00d1969d
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * @author <evan@wikitravel.org>
23 /**
24 * This is largely cadged from PageHistory::history
26 function showCreditsPage($article) {
27 global $wgOut;
29 $fname = 'showCreditsPage';
31 wfProfileIn( $fname );
33 $wgOut->setPageTitle( $article->mTitle->getPrefixedText() );
34 $wgOut->setSubtitle( wfMsg( 'creditspage' ) );
35 $wgOut->setArticleFlag( false );
36 $wgOut->setArticleRelated( true );
37 $wgOut->setRobotpolicy( 'noindex,nofollow' );
39 if( $article->mTitle->getArticleID() == 0 ) {
40 $s = wfMsg( 'nocredits' );
41 } else {
42 $s = getCredits($article, -1);
45 $wgOut->addHTML( $s );
47 wfProfileOut( $fname );
50 function getCredits($article, $cnt, $showIfMax=true) {
51 $fname = 'getCredits';
52 wfProfileIn( $fname );
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 wfProfileOut( $fname );
63 return $s;
66 /**
69 function getAuthorCredits($article) {
70 global $wgLang, $wgAllowRealName;
72 $last_author = $article->getUser();
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);
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->date($article->getTimestamp(), true);
90 $t = $wgLang->time($article->getTimestamp(), true);
91 } else {
92 $d = '';
93 $t = '';
95 return wfMsg('lastmodifiedatby', $d, $t, $author_credit);
98 /**
101 function getContributorCredits($article, $cnt, $showIfMax) {
103 global $wgLang, $wgAllowRealName;
105 $contributors = $article->getContributors();
107 $others_link = '';
109 # Hmm... too many to fit!
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);
120 $real_names = array();
121 $user_names = array();
123 $anon = '';
125 # Sift for real versus user names
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]);
134 } else {
135 $anon = wfMsg('anonymous');
139 # Two strings: real names, and user names
141 $real = $wgLang->listToText($real_names);
142 $user = $wgLang->listToText($user_names);
144 # "ThisSite user(s) A, B and C"
146 if (!empty($user)) {
147 $user = wfMsg('siteusers', $user);
150 # This is the big list, all mooshed together. We sift for blank strings
152 $fulllist = array();
154 foreach (array($real, $user, $anon, $others_link) as $s) {
155 if (!empty($s)) {
156 array_push($fulllist, $s);
160 # Make the list into text...
162 $creds = $wgLang->listToText($fulllist);
164 # "Based on work by ..."
166 return (empty($creds)) ? '' : wfMsg('othercontribs', $creds);
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 ));
182 function creditOthersLink($article) {
183 global $wgUser;
184 $skin = $wgUser->getSkin();
185 return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), 'action=credits');