wiki.techinc.nl/includes/Credits.php

189 lines
4.5 KiB
PHP
Raw Normal View History

<?php
/**
* Credits.php -- formats credits for articles
* Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
2004-11-11 22:16:54 +00:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
2005-04-05 10:23:23 +00:00
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* @author <evan@wikitravel.org>
* @package MediaWiki
*/
/**
* This is largely cadged from PageHistory::history
*/
class Credits {
function showCreditsPage($article) {
global $wgOut;
$fname = 'Credits::showCreditsPage';
2004-11-11 22:16:54 +00:00
wfProfileIn( $fname );
$wgOut->setPageTitle( $article->mTitle->getPrefixedText() );
$wgOut->setSubtitle( wfMsg( 'creditspage' ) );
$wgOut->setArticleFlag( false );
$wgOut->setArticleRelated( true );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
if( $article->mTitle->getArticleID() == 0 ) {
$s = wfMsg( 'nocredits' );
} else {
$s = Credits::getCredits($article, -1);
}
$wgOut->addHTML( $s );
2004-11-11 22:16:54 +00:00
wfProfileOut( $fname );
}
function getCredits($article, $cnt, $showIfMax=true) {
$fname = 'Credits::getCredits';
wfProfileIn( $fname );
$s = '';
2004-11-11 22:16:54 +00:00
if (isset($cnt) && $cnt != 0) {
$s = Credits::getAuthorCredits($article);
if ($cnt > 1 || $cnt < 0) {
$s .= ' ' . Credits::getContributorCredits($article, $cnt - 1, $showIfMax);
}
2004-11-11 22:16:54 +00:00
}
wfProfileOut( $fname );
return $s;
}
2004-11-11 22:16:54 +00:00
/**
*
*/
function getAuthorCredits($article) {
global $wgLang, $wgAllowRealName;
$last_author = $article->getUser();
2004-11-11 22:16:54 +00:00
if ($last_author == 0) {
$author_credit = wfMsg('anonymous');
} else {
if($wgAllowRealName) { $real_name = User::whoIsReal($last_author); }
$user_name = User::whoIs($last_author);
2004-11-11 22:16:54 +00:00
if (!empty($real_name)) {
$author_credit = Credits::creditLink($user_name, $real_name);
} else {
$author_credit = wfMsg('siteuser', Credits::creditLink($user_name));
}
}
2004-11-11 22:16:54 +00:00
$timestamp = $article->getTimestamp();
if ($timestamp) {
$d = $wgLang->timeanddate($article->getTimestamp(), true);
2004-11-11 22:16:54 +00:00
} else {
$d = '';
2004-11-11 22:16:54 +00:00
}
return wfMsg('lastmodifiedby', $d, $author_credit);
}
/**
*
*/
function getContributorCredits($article, $cnt, $showIfMax) {
global $wgLang, $wgAllowRealName;
2004-11-11 22:16:54 +00:00
$contributors = $article->getContributors();
2004-11-11 22:16:54 +00:00
$others_link = '';
# Hmm... too many to fit!
2004-11-11 22:16:54 +00:00
if ($cnt > 0 && count($contributors) > $cnt) {
$others_link = Credits::creditOthersLink($article);
if (!$showIfMax) {
return wfMsg('othercontribs', $others_link);
} else {
$contributors = array_slice($contributors, 0, $cnt);
}
2004-11-11 22:16:54 +00:00
}
$real_names = array();
$user_names = array();
$anon = '';
2004-11-11 22:16:54 +00:00
# Sift for real versus user names
2004-11-11 22:16:54 +00:00
foreach ($contributors as $user_parts) {
if ($user_parts[0] != 0) {
if ($wgAllowRealName && !empty($user_parts[2])) {
$real_names[] = Credits::creditLink($user_parts[1], $user_parts[2]);
} else {
$user_names[] = Credits::creditLink($user_parts[1]);
}
2004-11-11 22:16:54 +00:00
} else {
$anon = wfMsg('anonymous');
2004-11-11 22:16:54 +00:00
}
}
# Two strings: real names, and user names
2004-11-11 22:16:54 +00:00
$real = $wgLang->listToText($real_names);
$user = $wgLang->listToText($user_names);
# "ThisSite user(s) A, B and C"
2004-11-11 22:16:54 +00:00
if (!empty($user)) {
$user = wfMsg('siteusers', $user);
}
# This is the big list, all mooshed together. We sift for blank strings
2004-11-11 22:16:54 +00:00
$fulllist = array();
2004-11-11 22:16:54 +00:00
foreach (array($real, $user, $anon, $others_link) as $s) {
if (!empty($s)) {
array_push($fulllist, $s);
}
2004-11-11 22:16:54 +00:00
}
# Make the list into text...
2004-11-11 22:16:54 +00:00
$creds = $wgLang->listToText($fulllist);
# "Based on work by ..."
2004-11-11 22:16:54 +00:00
return (empty($creds)) ? '' : wfMsg('othercontribs', $creds);
}
/**
*
*/
function creditLink($user_name, $link_text = '') {
global $wgUser, $wgContLang;
$skin = $wgUser->getSkin();
return $skin->makeLink($wgContLang->getNsText(NS_USER) . ':' . $user_name,
htmlspecialchars( (empty($link_text)) ? $user_name : $link_text ));
}
/**
*
*/
function creditOthersLink($article) {
global $wgUser;
$skin = $wgUser->getSkin();
return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), 'action=credits');
}
}
?>