2004-06-28 17:46:54 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Credits.php -- formats credits for articles
|
2004-06-28 17:46:54 +00:00
|
|
|
* Copyright 2004, Evan Prodromou <evan@wikitravel.org>.
|
2004-11-11 22:16:54 +00:00
|
|
|
*
|
2004-06-28 17:46: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,
|
2004-06-28 17:46:54 +00:00
|
|
|
* 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
|
2006-04-05 07:43:17 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-09-02 23:28:24 +00:00
|
|
|
*
|
|
|
|
|
* @author <evan@wikitravel.org>
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-06-28 17:46:54 +00:00
|
|
|
*/
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* This is largely cadged from PageHistory::history
|
|
|
|
|
*/
|
2006-06-01 07:22:49 +00:00
|
|
|
class Credits {
|
|
|
|
|
function showCreditsPage($article) {
|
|
|
|
|
global $wgOut;
|
2004-06-28 17:46:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$fname = 'Credits::showCreditsPage';
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
wfProfileIn( $fname );
|
2006-03-07 01:10:39 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$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);
|
|
|
|
|
}
|
2004-06-28 17:46:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$wgOut->addHTML( $s );
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
}
|
2004-06-28 17:46:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
function getCredits($article, $cnt, $showIfMax=true) {
|
|
|
|
|
$fname = 'Credits::getCredits';
|
|
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
$s = '';
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +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
|
|
|
}
|
2006-06-01 07:22:49 +00:00
|
|
|
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
return $s;
|
2006-03-07 01:10:39 +00:00
|
|
|
}
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function getAuthorCredits($article) {
|
|
|
|
|
global $wgLang, $wgAllowRealName;
|
2004-06-28 17:46:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$last_author = $article->getUser();
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +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
|
|
|
|
2006-06-01 07:22:49 +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
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$timestamp = $article->getTimestamp();
|
|
|
|
|
if ($timestamp) {
|
|
|
|
|
$d = $wgLang->timeanddate($article->getTimestamp(), true);
|
2004-11-11 22:16:54 +00:00
|
|
|
} else {
|
2006-06-01 07:22:49 +00:00
|
|
|
$d = '';
|
2004-11-11 22:16:54 +00:00
|
|
|
}
|
2006-06-01 07:22:49 +00:00
|
|
|
return wfMsg('lastmodifiedby', $d, $author_credit);
|
2006-03-07 01:10:39 +00:00
|
|
|
}
|
2004-06-28 18:35:03 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function getContributorCredits($article, $cnt, $showIfMax) {
|
2004-06-28 17:46:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
global $wgLang, $wgAllowRealName;
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$contributors = $article->getContributors();
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$others_link = '';
|
2004-06-28 20:24:23 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
# Hmm... too many to fit!
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +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
|
|
|
}
|
|
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$real_names = array();
|
|
|
|
|
$user_names = array();
|
2004-06-28 17:46:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$anon = '';
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
# Sift for real versus user names
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +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 {
|
2006-06-01 07:22:49 +00:00
|
|
|
$anon = wfMsg('anonymous');
|
2004-11-11 22:16:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
# Two strings: real names, and user names
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$real = $wgLang->listToText($real_names);
|
|
|
|
|
$user = $wgLang->listToText($user_names);
|
2004-06-28 20:24:23 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
# "ThisSite user(s) A, B and C"
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
if (!empty($user)) {
|
|
|
|
|
$user = wfMsg('siteusers', $user);
|
|
|
|
|
}
|
2004-06-28 20:24:23 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
# This is the big list, all mooshed together. We sift for blank strings
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$fulllist = array();
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +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
|
|
|
}
|
2004-06-28 20:24:23 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
# Make the list into text...
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
$creds = $wgLang->listToText($fulllist);
|
2004-06-28 20:24:23 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
# "Based on work by ..."
|
2004-11-11 22:16:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
return (empty($creds)) ? '' : wfMsg('othercontribs', $creds);
|
|
|
|
|
}
|
2004-06-28 17:46:54 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
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 ));
|
|
|
|
|
}
|
2004-06-28 18:35:03 +00:00
|
|
|
|
2006-06-01 07:22:49 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
function creditOthersLink($article) {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$skin = $wgUser->getSkin();
|
|
|
|
|
return $skin->makeKnownLink($article->mTitle->getPrefixedText(), wfMsg('others'), 'action=credits');
|
|
|
|
|
}
|
2004-06-28 20:24:23 +00:00
|
|
|
}
|
2004-06-28 17:46:54 +00:00
|
|
|
?>
|