typo
[lhc/web/wiklou.git] / includes / Skin.php
index 1bb040c..7b53b6e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
-include_once( "Feed.php" );
-include_once( "Image.php" );
+require_once( "Feed.php" );
+require_once( "Image.php" );
 
 # See skin.doc
 
@@ -22,23 +22,7 @@ if( $wgUsePHPTal ) {
     #$wgValidSkinNames['monobookminimal'] = "MonoBookMinimal";
 }
 
-include_once( "RecentChange.php" );
-
-# For some odd PHP bug, this function can't be part of a class
-function getCategories ()
-{
-  global $wgOut , $wgTitle , $wgUseCategoryMagic , $wgUser , $wgParser ;
-  if ( !isset ( $wgUseCategoryMagic ) || !$wgUseCategoryMagic ) return "" ;
-  if ( count ( $wgOut->mCategoryLinks ) == 0 ) return "" ;
-  if ( !$wgOut->isArticle() ) return "" ;
-  $sk = $wgUser->getSkin() ;
-  $s = "" ;
-  $s .= $sk->makeKnownLink ( "Special:Categories" , "Categories" , "article=".$wgTitle->getDBkey() ) ;
-  $t = implode ( " | " , $wgOut->mCategoryLinks ) ;
-  if ( $t != "" ) $s .= ": " ;
-  $s .= $t ;
-  return "<p class='catlinks'>$s</p>";
-}
+require_once( "RecentChange.php" );
 
 class RCCacheEntry extends RecentChange
 {
@@ -167,18 +151,18 @@ class Skin {
        }
 
        function getHeadScripts() {
-               global $wgStyleSheetPath;
-               $r = "<script type=\"text/javascript\" src=\"{$wgStyleSheetPath}/wikibits.js\"></script>\n";
+               global $wgStylePath;
+               $r = "<script type=\"text/javascript\" src=\"{$wgStylePath}/wikibits.js\"></script>\n";
                return $r;
        }
 
        function getUserStyles()
        {
-               global $wgOut, $wgStyleSheetPath;
+               global $wgOut, $wgStylePath;
                $sheet = $this->getStylesheet();
                $s = "<style type='text/css'>\n";
                $s .= "/*/*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
-               $s .= "@import url(\"$wgStyleSheetPath/$sheet\");\n";
+               $s .= "@import url(\"$wgStylePath/$sheet\");\n";
                $s .= $this->doGetUserStyles();
                $s .= "/* */\n";
                $s .= "</style>\n";
@@ -368,10 +352,24 @@ class Skin {
 
                $s .= $this->pageTitle();
                $s .= $this->pageSubtitle() ;
-               $s .= getCategories(); // For some odd reason, zhis can't be a function of the object
+               $s .= $this->getCategories();
                wfProfileOut( $fname );
                return $s;
        }
+       
+       function getCategories () {
+               global $wgOut, $wgTitle, $wgUser, $wgParser;
+               global $wgUseCategoryMagic;
+               if( !$wgUseCategoryMagic ) return "" ;
+               if( count( $wgOut->mCategoryLinks ) == 0 ) return "";
+               if( !$wgOut->isArticle() ) return "";
+               
+               $t = implode ( " | " , $wgOut->mCategoryLinks ) ;
+               $s = $this->makeKnownLink( "Special:Categories",
+                       wfMsg( "categories" ), "article=" . urlencode( $wgTitle->getPrefixedDBkey() ) )
+                       . ": " . $t;
+               return "<p class='catlinks'>$s</p>";
+       }
 
        function getQuickbarCompensator( $rows = 1 )
        {
@@ -452,7 +450,7 @@ class Skin {
                $action = $wgRequest->getText( 'action' );
 
                $s = $this->printableLink();
-               if ( wfMsg ( "disclaimers" ) != "" ) $s .= " | " . $this->makeKnownLink( wfMsg( "disclaimerpage" ), wfMsg( "disclaimers" ) ) ;
+               if ( wfMsg ( "disclaimers" ) != "-" ) $s .= " | " . $this->makeKnownLink( wfMsg( "disclaimerpage" ), wfMsg( "disclaimers" ) ) ;
 
                if ( $wgOut->isArticleRelated() ) {
                        if ( $wgTitle->getNamespace() == Namespace::getImage() ) {
@@ -535,17 +533,26 @@ class Skin {
 
        function pageSubtitle()
        {
-               global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
+               global $wgOut;
 
                $sub = $wgOut->getSubtitle();
                if ( "" == $sub ) {
                        global $wgExtraSubtitle;
                        $sub = wfMsg( "fromwikipedia" ) . $wgExtraSubtitle;
                }
+               $subpages = $this->subPageSubtitle();
+               $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
+               $s = "<p class='subtitle'>{$sub}</p>\n";
+               return $s;
+       }
+
+       function subPageSubtitle()
+       {
+               global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
+               $subpages = '';
                if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
                        $ptext=$wgTitle->getPrefixedText();
                        if(preg_match("/\//",$ptext)) {
-                               $sub.="</p><p class='subpages'>";
                                $links=explode("/",$ptext);
                                $c=0;
                                $growinglink="";
@@ -556,19 +563,17 @@ class Skin {
                                                $getlink = $this->makeLink( $growinglink, $link );
                                                if(preg_match("/class='new'/i",$getlink)) { break; } # this is a hack, but it saves time
                                                if ($c>1) {
-                                                       $sub .= " | ";
+                                                       $subpages .= " | ";
                                                } else  {
-                                                       $sub .="&lt; ";
+                                                       $subpages .="&lt; ";
                                                }
-                                               $sub .= $getlink;
+                                               $subpages .= $getlink;
                                                $growinglink.="/";
                                        }
-                                       
                                }
                        }
                }
-               $s = "<p class='subtitle'>{$sub}</p>\n";
-               return $s;
+               return $subpages;
        }
 
        function nameAndLogin()
@@ -708,7 +713,7 @@ class Skin {
        {
                global $wgOut, $wgLang, $wgArticle, $wgRequest;
                global $wgDisableCounters;
-               
+
                extract( $wgRequest->getValues( 'oldid', 'diff' ) );
                if ( ! $wgOut->isArticle() ) { return ""; }
                if ( isset( $oldid ) || isset( $diff ) ) { return ""; }
@@ -721,10 +726,95 @@ class Skin {
                                $s = wfMsg( "viewcount", $count );
                        }
                }
-               $s .= $this->lastModified();
+
+               $s .= " " . $this->getCredits();
+           
                return $s . " " .  $this->getCopyright();
        }
-       
+
+        function getCredits() {
+              global $wgMaxCredits;
+              
+              $s = '';
+           
+              if (!isset($wgMaxCredits) || $wgMaxCredits == 0) {
+                       $s = $this->lastModified();
+              } else {
+                       $s = $this->getAuthorCredits();
+                       if ($wgMaxCredits > 1) {
+                           $s .= " " . $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;
+
+                # don't count last editor
+
+               $contributors = $wgArticle->getContributors($wgMaxCredits - 1);
+           
+               $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("othercontribs", $creds);
+       }
+    
        function getCopyright() {
                global $wgRightsPage, $wgRightsUrl, $wgRightsText;
                $out = "";
@@ -759,8 +849,8 @@ class Skin {
        }
        
        function getPoweredBy() {
-               global $wgUploadPath;
-               $url = htmlspecialchars( "$wgUploadPath/poweredby_mediawiki_88x31.png" );
+               global $wgStylePath;
+               $url = htmlspecialchars( "$wgStylePath/images/poweredby_mediawiki_88x31.png" );
                $img = "<a href='http://www.mediawiki.org/'><img src='$url' alt='MediaWiki' /></a>";
                return $img;
        }
@@ -818,7 +908,7 @@ class Skin {
                
                }
                // only show watchlist link if logged in
-               if ( wfMsg ( "currentevents" ) != "" ) $s .= $sep . $this->makeKnownLink( wfMsg( "currentevents" ), "" ) ;
+               if ( wfMsg ( "currentevents" ) != "-" ) $s .= $sep . $this->makeKnownLink( wfMsg( "currentevents" ), "" ) ;
                $s .= "\n<br /><hr class='sep' />";
                $articleExists = $wgTitle->getArticleId();
                if ( $wgOut->isArticle() || $action =="edit" || $action =="history" || $wpPreview) {                            
@@ -1540,6 +1630,45 @@ class Skin {
                return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
        }
 
+       /* these are used extensively in SkinPHPTal, but also some other places */
+       /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
+               $title = Title::makeTitle( NS_SPECIAL, $name );
+               $this->checkTitle(&$title, &$name);     
+               return $title->getLocalURL( $urlaction );
+       }
+       /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
+               $title = Title::newFromText( $name );
+               $title = $title->getTalkPage();
+               $this->checkTitle(&$title, &$name);     
+               return $title->getLocalURL( $urlaction );
+       }
+       /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
+               $title = Title::newFromText( $name );
+               $title= $title->getSubjectPage();
+               $this->checkTitle(&$title, &$name);     
+               return $title->getLocalURL( $urlaction );
+       }
+       /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
+               $title = Title::newFromText( wfMsg($name) );
+               $this->checkTitle(&$title, &$name);     
+               return $title->getLocalURL( $urlaction );
+       }
+       /*static*/ function makeUrl ( $name, $urlaction='' ) {
+               $title = Title::newFromText( $name );
+               $this->checkTitle(&$title, &$name);     
+               return $title->getLocalURL( $urlaction ); 
+       }
+
+       # make sure we have some title to operate on, mind the '&'
+       /*static*/ function &checkTitle ( $title, $name ) { 
+               if(!is_object($title)) {
+                       $title = Title::newFromText( $name );
+                       if(!is_object($title)) {
+                               $title = Title::newFromText( '<error: link target missing>' );
+                       }
+               }
+       }
+
        function fnamePart( $url )
        {
                $basename = strrchr( $url, "/" );
@@ -1592,7 +1721,7 @@ class Skin {
                        $mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
                        $alt = $part[count($part)-1];
 
-                       $framed=$thumb=false;
+                       $height = $framed = $thumb = false;
 
                        foreach( $part as $key => $val ) {
                                if ( ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
@@ -1611,7 +1740,12 @@ class Skin {
                                        $align = "none";
                                } elseif ( ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
                                        # $match is the image width in pixels
-                                       $width = intval($match);
+                                       if ( preg_match( "/^([0-9]*)x([0-9]*)$/", $match, $m ) ) {
+                                               $width = intval( $m[1] );
+                                               $height = intval( $m[2] );
+                                       } else {
+                                               $width = intval($match);
+                                       }
                                } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
                                        $framed=true;
                                }
@@ -1638,12 +1772,19 @@ class Skin {
                                if ( ! isset($width) ) {
                                        $width = 180;
                                }
-                               return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $framed ).$postfix;
+                               return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed ).$postfix;
        
                        } elseif ( isset($width) ) {
                                
                                # Create a resized image, without the additional thumbnail
                                # features
+
+                               if (    ( ! $height === false ) 
+                                    && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
+                                       print "height=$height<br>\nimg->getHeight() = ".$img->getHeight()."<br>\n";
+                                       print "rescaling by factor ". $height / $img->getHeight() . "<br>\n";
+                                       $width = $img->getWidth() * $height / $img->getHeight();
+                               }
                                $url = $img->createThumb( $width );
                        }
                } # endif $wgUseImageResize
@@ -1669,8 +1810,8 @@ class Skin {
        }
 
 
-       function makeThumbLinkObj( $img, $label = "", $align = "right", $boxwidth = 180, $framed=false ) {
-               global $wgUploadPath, $wgLang;
+       function makeThumbLinkObj( $img, $label = "", $align = "right", $boxwidth = 180, $boxheight=false, $framed=false ) {
+               global $wgStylePath, $wgLang;
                # $image = Title::makeTitle( Namespace::getImage(), $name );
                $url  = $img->getURL();
                
@@ -1689,17 +1830,20 @@ class Skin {
                {
                        // Use image dimensions, don't scale
                        $boxwidth  = $width;
+                       $oboxwidth = $boxwidth + 2;
                        $boxheight = $height;
                        $thumbUrl  = $url;
                } else {
-                       $boxheight  = intval( $height/($width/$boxwidth) );
-                       if ( $boxwidth > $width ) {
-                               $boxwidth  = $width;
-                               $boxheight = $height;
+                       $h  = intval( $height/($width/$boxwidth) );
+                       $oboxwidth = $boxwidth + 2;
+                       if ( ( ! $boxheight === false ) &&  ( $h > $boxheight ) )
+                       {
+                               $boxwidth *= $boxheight/$h;
+                       } else {
+                               $boxheight = $h;
                        }
                        $thumbUrl = $img->createThumb( $boxwidth );
                }
-               $oboxwidth = $boxwidth + 2;
 
                $u = $img->getEscapeLocalURL();
 
@@ -1707,7 +1851,7 @@ class Skin {
                $magnifyalign = $wgLang->isRTL() ? "left" : "right";
                $textalign = $wgLang->isRTL() ? ' style="text-align:right"' : "";
 
-               $s = "<div class=\"thumb t{$align}\"\"><div style=\"width:{$oboxwidth}px;\">";
+               $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
                if ( $thumbUrl == "" ) {
                        $s .= str_replace( "$1", $img->getName(), wfMsg("missingimage") );
                        $zoomicon = '';
@@ -1720,7 +1864,7 @@ class Skin {
                        } else {
                                $zoomicon =  '<div class="magnify" style="float:'.$magnifyalign.'">'.
                                        '<a href="'.$u.'" class="internal" title="'.$more.'">'.
-                                       '<img src="'.$wgUploadPath.'/magnify-clip.png" ' .
+                                       '<img src="'.$wgStylePath.'/images/magnify-clip.png" ' .
                                        'width="15" height="11" alt="'.$more.'" /></a></div>';
                        }
                }
@@ -1800,7 +1944,7 @@ class Skin {
        # Enhanced RC ungrouped line
        function recentChangesBlockLine ( $rcObj )
        {
-               global $wgUploadPath, $wgLang ;
+               global $wgStylePath, $wgLang ;
 
                # Get rc_xxxx variables
                extract( $rcObj->mAttribs ) ;
@@ -1809,7 +1953,7 @@ class Skin {
                # Spacer image
                $r = "" ;
 
-               $r .= "<img src='{$wgUploadPath}/Arr_.png' width='12' height='12' border='0' />" ;              $r .= "<tt>" ;
+               $r .= "<img src='{$wgStylePath}/images/Arr_.png' width='12' height='12' border='0' />" ;                $r .= "<tt>" ;
 
                if ( $rc_type == RC_MOVE ) {
                        $r .= "&nbsp;&nbsp;";
@@ -1864,7 +2008,7 @@ class Skin {
        # Enhanced RC group
        function recentChangesBlockGroup ( $block )
        {
-               global $wgUploadPath, $wgLang ;
+               global $wgStylePath, $wgLang ;
 
                $r = "" ;
                $M = wfMsg( "minoreditletter" );
@@ -1898,8 +2042,8 @@ class Skin {
                $rcm = "RCM{$this->rcCacheIndex}" ;
                $toggleLink = "javascript:toggleVisibility(\"{$rci}\",\"{$rcm}\",\"{$rcl}\")" ;
                $arrowdir = $wgLang->isRTL() ? "l" : "r";
-               $tl  = "<span id='{$rcm}'><a href='$toggleLink'><img src='{$wgUploadPath}/Arr_{$arrowdir}.png' width='12' height='12' /></a></span>" ;
-               $tl .= "<span id='{$rcl}' style='display:none'><a href='$toggleLink'><img src='{$wgUploadPath}/Arr_d.png' width='12' height='12' /></a></span>" ;
+               $tl  = "<span id='{$rcm}'><a href='$toggleLink'><img src='{$wgStylePath}/images/Arr_{$arrowdir}.png' width='12' height='12' /></a></span>" ;
+               $tl .= "<span id='{$rcl}' style='display:none'><a href='$toggleLink'><img src='{$wgStylePath}/images/Arr_d.png' width='12' height='12' /></a></span>" ;
                $r .= $tl ;
 
                # Main line
@@ -1941,7 +2085,7 @@ class Skin {
                        # Get rc_xxxx variables
                        extract( $rcObj->mAttribs );
                        
-                       $r .= "<img src='{$wgUploadPath}/Arr_.png' width=12 height=12 />";
+                       $r .= "<img src='{$wgStylePath}/images/Arr_.png' width=12 height=12 />";
                        $r .= "<tt>&nbsp; &nbsp; &nbsp; &nbsp;" ;
                        if ( $rc_new ) $r .= $N ;
                        else $r .= "&nbsp;" ;
@@ -1983,7 +2127,7 @@ class Skin {
        # RC lines, arranges them, and outputs the HTML
        function recentChangesBlock ()
        {
-               global $wgUploadPath ;
+               global $wgStylePath ;
                if ( count ( $this->rc_cache ) == 0 ) return "" ;
                $blockOut = "";
                foreach ( $this->rc_cache AS $secureName => $block ) {
@@ -2272,11 +2416,11 @@ class Skin {
 
        }
 
-       function imageHistoryLine( $iscur, $ts, $img, $u, $ut, $size, $c )
+       function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description )
        {
                global $wgUser, $wgLang, $wgTitle;
 
-               $dt = $wgLang->timeanddate( $ts, true );
+               $datetime = $wgLang->timeanddate( $timestamp, true );
                $del = wfMsg( "deleteimg" );
                $cur = wfMsg( "cur" );
 
@@ -2296,10 +2440,10 @@ class Skin {
                        $url = wfEscapeHTML( wfImageArchiveUrl( $img ) );
                        if( $wgUser->getID() != 0 ) {
                                $rlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
-                                 wfMsg( "revertimg" ), "action=revert&oldimage=" .
-                                 urlencode( $img ) );
+                                          wfMsg( "revertimg" ), "action=revert&oldimage=" .
+                                          urlencode( $img ) );
                                $dlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
-                                 $del, "action=delete&oldimage=" . urlencode( $img ) );
+                                          $del, "action=delete&oldimage=" . urlencode( $img ) );
                        } else {
                                # Having live active links for non-logged in users
                                # means that bots and spiders crawling our site can
@@ -2308,19 +2452,21 @@ class Skin {
                                $dlink = $del;
                        }
                }
-               if ( 0 == $u ) { $ul = $ut; }
-               else { $ul = $this->makeLink( $wgLang->getNsText(
-                 Namespace::getUser() ) . ":{$ut}", $ut ); }
-
-               $nb = wfMsg( "nbytes", $size );
-               $style = $this->getInternalLinkAttributes( $url, $dt );
+               if ( 0 == $user ) {
+                       $userlink = $usertext;
+               } else {
+                       $userlink = $this->makeLink( $wgLang->getNsText( Namespace::getUser() ) .
+                                      ":{$usertext}", $usertext );
+               }
+               $nbytes = wfMsg( "nbytes", $size );
+               $style = $this->getInternalLinkAttributes( $url, $datetime );
 
-               $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$dt}</a>"
-                 . " . . {$ul} ({$nb})";
+               $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
+                 . " . . {$userlink} ({$nbytes})";
 
-               if ( "" != $c && "*" != $c ) {
+               if ( "" != $description && "*" != $description ) {
                        $sk=$wgUser->getSkin();
-                       $s .= $wgLang->emphasize(" (" . $sk->formatComment($c) . ")");
+                       $s .= $wgLang->emphasize(" (" . $sk->formatComment($description) . ")");
                }
                $s .= "</li>\n";
                return $s;
@@ -2396,7 +2542,7 @@ class Skin {
        // toolbar for common editing functions. It can be disabled in the user preferences.
        // The necsesary JavaScript code can be found in style/wikibits.js.
        function getEditToolbar() {
-               global $wgUploadPath, $wgLang, $wgMimeType;
+               global $wgStylePath, $wgLang, $wgMimeType;
 
                // toolarray an array of arrays which each include the filename of
                // the button image (without path), the opening tag, the closing tag,
@@ -2491,7 +2637,7 @@ class Skin {
                $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
                foreach($toolarray as $tool) {
 
-                       $image=$wgUploadPath."/".$tool["image"];
+                       $image=$wgStylePath."/images/".$tool["image"];
                        $open=$tool["open"];
                        $close=$tool["close"];
                        $sample = addslashes( $tool["sample"] );
@@ -2515,12 +2661,12 @@ class Skin {
        }
 }
 
-include_once( "SkinStandard.php" );
-include_once( "SkinNostalgia.php" );
-include_once( "SkinCologneBlue.php" );
+require_once( "SkinStandard.php" );
+require_once( "SkinNostalgia.php" );
+require_once( "SkinCologneBlue.php" );
 
 if( $wgUsePHPTal ) {
-       include_once( "SkinPHPTal.php" );
+       require_once( "SkinPHPTal.php" );
 }