Beginnings of on-page author credits. Added code to Skin to add credits,
authorEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 26 Apr 2004 05:14:42 +0000 (05:14 +0000)
committerEvan Prodromou <evanprodromou@users.mediawiki.org>
Mon, 26 Apr 2004 05:14:42 +0000 (05:14 +0000)
although it's not everywhere it should be. $wgMaxCredits ignored, except to
set max/min credits.

includes/DefaultSettings.php
includes/Skin.php
languages/Language.php

index 3532b6e..59fb115 100644 (file)
@@ -343,4 +343,7 @@ $wgCapitalLinks = true;
 # can be imported, these should be 'trusted'.
 $wgImportSources = array();
 
+# For credit to authors. Set to zero to hide attribution block.
+$wgMaxCredits = 0;
+
 ?>
index 1bb040c..97997f5 100644 (file)
@@ -707,7 +707,7 @@ class Skin {
        function pageStats()
        {
                global $wgOut, $wgLang, $wgArticle, $wgRequest;
-               global $wgDisableCounters;
+               global $wgDisableCounters, $wgMaxCredits;
                
                extract( $wgRequest->getValues( 'oldid', 'diff' ) );
                if ( ! $wgOut->isArticle() ) { return ""; }
@@ -721,10 +721,85 @@ class Skin {
                                $s = wfMsg( "viewcount", $count );
                        }
                }
-               $s .= $this->lastModified();
+               if (!isset($wgMaxCredits) || $wgMaxCredits <= 0) {
+                   $s .= $this->lastModified();
+               } else {
+                   $s .= " " . $this->getCredits();
+               }
+           
                return $s . " " .  $this->getCopyright();
        }
-       
+
+        function getCredits() {
+               $s = $this->getAuthorCredits();
+               $s .= "<br />\n " . $this->getContributorCredits();
+               return $s;
+       }
+
+        function getAuthorCredits() {
+               global $wgLang, $wgArticle;
+
+               $last_author = $wgArticle->getUser();
+           
+               if ($last_author == 0) {
+                   $author_credit = wfMsg("anonymous");
+               } else {
+                   $real_name = User::whoIsReal($last_author);
+                   if (!empty($real_name)) {
+                       $author_credit = $real_name;
+                   } else {
+                       $author_credit = wfMsg("siteuser", User::whoIs($last_author));
+                   }
+               }
+           
+               $timestamp = $wgArticle->getTimestamp();
+               if ( $timestamp ) {
+                       $d = $wgLang->timeanddate( $wgArticle->getTimestamp(), true );
+               } else {
+                       $d = "";
+               }
+               return wfMsg("lastmodifiedby", $d, $author_credit);
+       }
+
+        function getContributorCredits() {
+           
+               global $wgArticle, $wgMaxCredits, $wgLang;
+           
+               $contributors = $wgArticle->getContributors($wgMaxCredits);
+           
+               $real_names = array();
+               $user_names = array();
+
+               # Sift for real versus user names
+               
+               foreach ($contributors as $user_id => $user_parts) {
+                   if ($user_id != 0) {
+                       if (!empty($user_parts[1])) {
+                           $real_names[$user_id] = $user_parts[1];
+                       } else {
+                           $user_names[$user_id] = $user_parts[0];
+                       }
+                   }
+               }
+           
+                $real = $wgLang->listToText(array_values($real_names));
+               $user = $wgLang->listToText(array_values($user_names));
+
+               if (!empty($user)) {
+                   $user = wfMsg("siteusers", $user);
+               }
+           
+               if ($contributors[0] && $contributors[0][0] > 0) {
+                   $anon = wfMsg("anonymous");
+               } else {
+                   $anon = '';
+               }
+           
+               $creds = $wgLang->listToText(array($real, $user, $anon));
+           
+               return wfMsg("contributions", $creds);
+       }
+    
        function getCopyright() {
                global $wgRightsPage, $wgRightsUrl, $wgRightsText;
                $out = "";
index b0e8cd1..3c787b1 100644 (file)
@@ -1564,7 +1564,11 @@ amusement.",
 # Attribution
 
 "anonymous" => "Anonymous user(s) of $wgSitename",
-"siteuser" => "$wgSitename user $1"                                   
+"siteuser" => "$wgSitename user $1",
+"lastmodifiedby" => "This page was last modified $1 by $2.",
+"and" => "and",
+"contributions" => "Based on work by $1.",
+"siteusers" => "$wgSitename user(s) $1",
 );
 
 #--------------------------------------------------------------------------
@@ -1924,6 +1928,20 @@ class Language {
                return $number;
        }
 
+        function listToText( $l ) {
+               $s = "";
+               $m = count($l) - 1;
+               for ($i = $m; $i >= 0; $i--) {
+                   if ($i == $m) {
+                       $s = $l[$i];
+                   } else if ($i == $m - 1) {
+                       $s = $l[$i] . " " . $this->getMessage("and") . " " . $s;
+                   } else {
+                       $s = $l[$i] . ", " . $s;
+                   }
+               }
+               return $s;
+       }
 }
 
 @include_once( "Language" . ucfirst( $wgLanguageCode ) . ".php" );