pipe for stderr was troublesome on pages with many errors (buffer filled up), generic...
[lhc/web/wiklou.git] / includes / Skin.php
index 6e80f9a..c4686d1 100644 (file)
@@ -24,22 +24,6 @@ if( $wgUsePHPTal ) {
 
 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>";
-}
-
 class RCCacheEntry extends RecentChange
 {
        var $secureName, $link;
@@ -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()
@@ -707,8 +712,8 @@ class Skin {
        function pageStats()
        {
                global $wgOut, $wgLang, $wgArticle, $wgRequest;
-               global $wgDisableCounters, $wgMaxCredits;
-               
+               global $wgDisableCounters;
+
                extract( $wgRequest->getValues( 'oldid', 'diff' ) );
                if ( ! $wgOut->isArticle() ) { return ""; }
                if ( isset( $oldid ) || isset( $diff ) ) { return ""; }
@@ -721,19 +726,27 @@ class Skin {
                                $s = wfMsg( "viewcount", $count );
                        }
                }
-               if (!isset($wgMaxCredits) || $wgMaxCredits <= 0) {
-                   $s .= $this->lastModified();
-               } else {
-                   $s .= " " . $this->getCredits();
-               }
+
+               $s .= " " . $this->getCredits();
            
                return $s . " " .  $this->getCopyright();
        }
 
         function getCredits() {
-               $s = $this->getAuthorCredits();
-               $s .= "<br />\n " . $this->getContributorCredits();
-               return $s;
+              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() {
@@ -764,8 +777,10 @@ class Skin {
         function getContributorCredits() {
            
                global $wgArticle, $wgMaxCredits, $wgLang;
-           
-               $contributors = $wgArticle->getContributors($wgMaxCredits);
+
+                # don't count last editor
+
+               $contributors = $wgArticle->getContributors($wgMaxCredits - 1);
            
                $real_names = array();
                $user_names = array();
@@ -797,7 +812,7 @@ class Skin {
            
                $creds = $wgLang->listToText(array($real, $user, $anon));
            
-               return wfMsg("contributions", $creds);
+               return wfMsg("othercontribs", $creds);
        }
     
        function getCopyright() {
@@ -893,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) {                            
@@ -1615,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, "/" );
@@ -1768,10 +1822,10 @@ class Skin {
                        $thumbUrl  = $url;
                } else {
                        $boxheight  = intval( $height/($width/$boxwidth) );
-                       if ( $boxwidth > $width ) {
-                               $boxwidth  = $width;
-                               $boxheight = $height;
-                       }
+                       if ( $boxwidth > $width ) {
+                       #       $boxwidth  = $width;
+                       #       $boxheight = $height;
+                       #}
                        $thumbUrl = $img->createThumb( $boxwidth );
                }
                $oboxwidth = $boxwidth + 2;