Category namespaces
[lhc/web/wiklou.git] / includes / Skin.php
index 9c59dd7..f078b36 100644 (file)
@@ -13,10 +13,6 @@ include_once( "Feed.php" );
        'nostalgia' => "Nostalgia",
        'cologneblue' => "CologneBlue"
 );
-if( $wgUseSmarty ) {
-       $wgValidSkinNames['smarty'] = "Smarty";
-       $wgValidSkinNames['montparnasse'] = "Montparnasse";
-}
 if( $wgUsePHPTal ) {
     #$wgValidSkinNames[] = "PHPTal";
     #$wgValidSkinNames['davinci'] = "DaVinci";
@@ -97,25 +93,47 @@ class Skin {
                $fname = "Skin::initPage";
                wfProfileIn( $fname );
                
-               $out->addLink( "shortcut icon", "", "/favicon.ico" );
-
-               $this->addMetadataLinks($out);
+               $out->addLink( array( "rel" => "shortcut icon", "href" => "/favicon.ico" ) );
+               
+               $this->addMetadataLinks($out);
            
                wfProfileOut( $fname );
        }
        
-        function addMetadataLinks( &$out ) {
-           global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
-
-           if ($action == 'view') {
-               # note: buggy CC software only reads first "meta" link
-               if ($wgEnableCreativeCommonsRdf) {
-                   $out->addMetadataLink('application/rdf+xml', wfLocalUrl($wgTitle->getPrefixedURL(), "action=creativecommons"));
+       function addMetadataLinks( &$out ) {
+               global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
+               global $wgRightsPage, $wgRightsUrl;
+
+               if( $out->isArticleRelated() ) {
+                       # note: buggy CC software only reads first "meta" link
+                       if( $wgEnableCreativeCommonsRdf ) {
+                               $out->addMetadataLink( array(
+                                       'title' => 'Creative Commons',
+                                       'type' => 'application/rdf+xml',
+                                       'href' => $wgTitle->getLocalURL( "action=creativecommons") ) );
+                       }
+                       if( $wgEnableDublinCoreRdf ) {
+                               $out->addMetadataLink( array(
+                                       'title' => 'Dublin Core',
+                                       'type' => 'application/rdf+xml',
+                                       'href' => $wgTitle->getLocalURL( "action=dublincore" ) ) );
+                       }
+               }
+               $copyright = "";
+               if( $wgRightsPage ) {
+                       $copy = Title::newFromText( $wgRightsPage );
+                       if( $copy ) {
+                               $copyright = $copy->getLocalURL();
+                       }
                }
-               if ($wgEnableDublinCoreRdf) {
-                   $out->addMetadataLink('application/rdf+xml', wfLocalUrl($wgTitle->getPrefixedURL(), "action=dublincore"));
+               if( !$copyright && $wgRightsUrl ) {
+                       $copyright = $wgRightsUrl;
+               }
+               if( $copyright ) {
+                       $out->addLink( array(
+                               "rel" => "copyright",
+                               "href" => $copyright ) );
                }
-           }
        }
     
        function outputPage( &$out ) {
@@ -202,7 +220,7 @@ class Skin {
                  (!$wgTitle->isProtected() || $wgUser->isSysop()) ) {
                        $t = wfMsg( "editthispage" );
                        $oid = $red = "";
-                       if ( $redirect ) { 
+                       if ( !empty($redirect) ) { 
                                $red = "&redirect={$redirect}"; 
                        }
                        if ( !empty($oldid) && ! isset( $diff ) ) {
@@ -321,7 +339,7 @@ class Skin {
                if($wgLang->isRTL()) $left = !$left;
                
                if ( !$shove ) {
-                       $s .= "<td class='top' align=left valign=top rowspan='{$rows}'>\n" .
+                       $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
                          $this->logoText() . "</td>";
                } elseif( $left ) {
                        $s .= $this->getQuickbarCompensator( $rows );
@@ -509,7 +527,7 @@ class Skin {
        {
                global $wgOut, $wgTitle, $wgUser;
 
-               $s = "<h1 class='pagetitle'>" . $wgOut->getPageTitle() . "</h1>";
+               $s = "<h1 class='pagetitle'>" . htmlspecialchars( $wgOut->getPageTitle() ) . "</h1>";
                if($wgUser->getOption("editsectiononrightclick") && $wgTitle->userCanEdit()) { $s=$this->editSectionScript(0,$s);}
                return $s;
        }
@@ -523,7 +541,7 @@ class Skin {
                        global $wgExtraSubtitle;
                        $sub = wfMsg( "fromwikipedia" ) . $wgExtraSubtitle;
                }
-               if($wgOut->isArticle() && $wgNamespacesWithSubpages[$wgTitle->getNamespace()]) {
+               if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
                        $ptext=$wgTitle->getPrefixedText();
                        if(preg_match("/\//",$ptext)) {
                                $sub.="</p><p class='subpages'>";
@@ -695,8 +713,47 @@ class Skin {
                        }
                }
                $s .= $this->lastModified();
-               $s .= " " . wfMsg( "gnunote" );
-               return $s;
+               return $s . " " .  $this->getCopyright();
+       }
+       
+       function getCopyright() {
+               global $wgRightsPage, $wgRightsUrl, $wgRightsText;
+               $out = "";
+               if( $wgRightsPage ) {
+                       $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
+               } elseif( $wgRightsUrl ) {
+                       $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
+               } else {
+                       # Give up now
+                       return $out;
+               }
+               $out .= wfMsg( "copyright", $link );
+               return $out;
+       }
+       
+       function getCopyrightIcon() {
+               global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon;
+               $out = "";
+               if( $wgRightsIcon ) {
+                       $icon = htmlspecialchars( $wgRightsIcon );
+                       if( $wgRightsUrl ) {
+                               $url = htmlspecialchars( $wgRightsUrl );
+                               $out .= "<a href=\"$url\">";
+                       }
+                       $text = htmlspecialchars( $wgRightsText );
+                       $out .= "<img src=\"$icon\" alt='$text' />";
+                       if( $wgRightsUrl ) {
+                               $out .= "</a>";
+                       }
+               }
+               return $out;
+       }
+       
+       function getPoweredBy() {
+               global $wgUploadPath;
+               $url = htmlspecialchars( "$wgUploadPath/poweredby_mediawiki_88x31.png" );
+               $img = "<a href='http://www.mediawiki.org/'><img src='$url' alt='MediaWiki' /></a>";
+               return $img;
        }
 
        function lastModified()
@@ -906,7 +963,7 @@ class Skin {
                $spp = $wgLang->specialPage( "Specialpages" );
 
                $s = "<form id=\"specialpages\" method=\"get\" class=\"inline\" " .
-                 "action=\"{$wgServer}{$wgRedirectScript}\">\n";
+                 "action=\"" . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
                $s .= "<select name=\"wpDropdown\">\n";
                $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
 
@@ -915,7 +972,7 @@ class Skin {
                        $s .= "<option value=\"{$p}\">{$desc}</option>\n";
                }
                $s .= "</select>\n";
-               $s .= "<input type=submit value=\"{$go}\" name=redirect>\n";
+               $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
                $s .= "</form>\n";
                return $s;
        }
@@ -1269,10 +1326,10 @@ class Skin {
                return $result;
        }
 
-       function makeKnownLink( $title, $text = "", $query = "", $trail = "" ) {
+       function makeKnownLink( $title, $text = "", $query = "", $trail = "", $prefix = '',$aprops = '') {
                $nt = Title::newFromText( $title );
                if ($nt) {
-                       return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail );
+                       return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
                } else {
                        wfDebug( "Invalid title passed to Skin::makeKnownLink(): \"$title\"\n" );
                        return $text == "" ? $title : $text;
@@ -1355,7 +1412,7 @@ class Skin {
        }
 
        # Pass a title object, not a title string
-       function makeKnownLinkObj( &$nt, $text = "", $query = "", $trail = "", $prefix = "" )
+       function makeKnownLinkObj( &$nt, $text = "", $query = "", $trail = "", $prefix = "" , $aprops = '')
        {
                global $wgOut, $wgTitle;
 
@@ -1366,14 +1423,18 @@ class Skin {
 
                if ( "" == $link ) {
                        $u = "";
-                       if ( "" == $text ) { $text = $nt->getFragment(); }
+                       if ( "" == $text ) {
+                               $text = htmlspecialchars( $nt->getFragment() );
+                       }
                } else {
                        $u = $nt->escapeLocalURL( $query );
                }
                if ( "" != $nt->getFragment() ) {
-                       $u .= "#" . wfEscapeHTML( $nt->getFragment() );
+                       $u .= "#" . htmlspecialchars( $nt->getFragment() );
+               }
+               if ( "" == $text ) {
+                       $text = htmlspecialchars( $nt->getPrefixedText() );
                }
-               if ( "" == $text ) { $text = $nt->getPrefixedText(); }
                $style = $this->getInternalLinkAttributesObj( $nt, $text );
 
                $inside = "";
@@ -1383,7 +1444,7 @@ class Skin {
                                $trail = $m[2];
                        }
                }
-               $r = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
+               $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
                wfProfileOut( $fname );
                return $r;
        }
@@ -1403,7 +1464,9 @@ class Skin {
                }
                $u = $nt->escapeLocalURL( $q );
 
-               if ( "" == $text ) { $text = $nt->getPrefixedText(); }
+               if ( "" == $text ) {
+                       $text = htmlspecialchars( $nt->getPrefixedText() );
+               }
                $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
 
                $inside = "";
@@ -1432,7 +1495,9 @@ class Skin {
 
                $u = $nt->escapeLocalURL( $query );
 
-               if ( "" == $text ) { $text = $nt->getPrefixedText(); }
+               if ( "" == $text ) {
+                       $text = htmlspecialchars( $nt->getPrefixedText() );
+               }
                $style = $this->getInternalLinkAttributesObj( $nt, $text, "stub" );
 
                $inside = "";
@@ -1562,11 +1627,11 @@ class Skin {
                {
                        $s = str_replace( "$1", $name, wfMsg("missingimage") );
                } else {
-                       $s = "\n  <a href=\"{$u}\" class='image' title=\"{$alt}\">\n" .
-                               "  <img src=\"{$url}\" alt=\"{$alt}\" />\n  </a>";
+                       $s = "<a href=\"{$u}\" class='image' title=\"{$alt}\">" .
+                               "<img src=\"{$url}\" alt=\"{$alt}\" /></a>";
                }
                if ( "" != $align ) {
-                       $s = "<div class=\"float{$align}\"><span>{$s}\n</span></div>";
+                       $s = "<div class=\"float{$align}\"><span>{$s}</span>\n</div>";
                }
                return $prefix.$s.$postfix;
        }
@@ -1577,7 +1642,7 @@ class Skin {
                global $wgUseImageMagick;
                global $wgUseSquid, $wgInternalServer;
                $imgPath   = wfImagePath( $name );
-               $thumbName = $width."px-".$icon.$name;
+               $thumbName = $width."px-".$name;
                $thumbPath = wfImageThumbDir( $thumbName )."/".$thumbName;
                $thumbUrl  = wfImageThumbUrl( $thumbName );
 
@@ -1708,14 +1773,14 @@ class Skin {
                if ( $thumbUrl == "" ) {
                        $s .= str_replace( "$1", $name, wfMsg("missingimage") );
                } else {
-                       $s .= "\n".'  <a href="'.$u.'" class="internal" title="'.$alt.'">'."\n".
-                               '  <img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
-                               '  width="'.$boxwidth.'" height="'.$boxheight.'" /></a>' ."\n".
-                               '  <a href="'.$u.'" class="internal" title="'.$more.'"> ' ."\n".
-                               '  <img src="'.$wgUploadPath.'/magnify-clip.png" ' .
-                               'width="26" height="24" align="'.$magnifyalign.'" alt="'.$more.'" /> </a>'."\n";
-               }
-               $s .= '  <p'.$textalign.'>'.$label."</p>\n</div></div>";
+                       $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
+                               '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
+                               'width="'.$boxwidth.'" height="'.$boxheight.'" /></a>'.
+                               '<a href="'.$u.'" class="internal" title="'.$more.'"> '.
+                               '<img src="'.$wgUploadPath.'/magnify-clip.png" ' .
+                               'width="26" height="24" align="'.$magnifyalign.'" alt="'.$more.'" /> </a>';
+               }
+               $s .= '  <div'.$textalign.'>'.$label."</div></div>\n</div>";
                return $s;
        }
 
@@ -1746,6 +1811,15 @@ class Skin {
                return $this->makeKnownLink( $wgLang->specialPage( $pn ),
                  wfMsg( $key ) );
        }
+       
+       function makeExternalLink( $url, $text, $escape = true ) {
+               $style = $this->getExternalLinkAttributes( $url, $text );
+               $url = htmlspecialchars( $url );
+               if( $escape ) {
+                       $text = htmlspecialchars( $text );
+               }
+               return "<a href=\"$url\"$style>$text</a>";
+       }
 
        # Called by history lists and recent changes
        #
@@ -1757,13 +1831,14 @@ class Skin {
                $this->rcMoveIndex = 0;
                $this->rcCacheIndex = 0 ;
                $this->lastdate = "";
+               $this->rclistOpen = false;
                return "";
        }
 
        function beginImageHistoryList()
        {
                $s = "\n<h2>" . wfMsg( "imghistory" ) . "</h2>\n" .
-                 "<p>" . wfMsg( "imghistlegend" ) . "\n<ul class='special'>";
+                 "<p>" . wfMsg( "imghistlegend" ) . "</p>\n<ul class='special'>";
                return $s;
        }
 
@@ -1772,7 +1847,9 @@ class Skin {
        function endRecentChangesList()
        {
                $s = $this->recentChangesBlock() ;
-               $s .= "</ul>\n";
+               if( $this->rclistOpen ) {
+                       $s .= "</ul>\n";
+               }
                return $s;
        }
 
@@ -2004,6 +2081,7 @@ class Skin {
                        if ( "" != $this->lastdate ) { $s .= "</ul>\n"; }
                        $s .= "<h4>{$date}</h4>\n<ul class='special'>";
                        $this->lastdate = $date;
+                       $this->rclistOpen = true;
                }
                $s .= "<li> ";
 
@@ -2025,7 +2103,7 @@ class Skin {
                                $diffLink = wfMsg( "diff" );
                        } else {
                                $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( "diff" ),
-                                 "{$curIdEq}&diff={$rc_this_oldid}&oldid={$rc_last_oldid}" );
+                                 "{$curIdEq}&diff={$rc_this_oldid}&oldid={$rc_last_oldid}"  ,'' ,'' , ' tabindex="'.$rc->counter.'"');
                        }
                        $s .= "($diffLink) (";
 
@@ -2135,7 +2213,7 @@ class Skin {
                        $curLink = wfMsg( "cur" );
                } else {
                        $curLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( "cur" ),
-                         "{$curIdEq}&diff=0&oldid={$rc_this_oldid}" );
+                         "{$curIdEq}&diff=0&oldid={$rc_this_oldid}" ,'' ,'' , ' tabindex="'.$baseRC->counter.'"' );
                }
 
                # Make "last" link
@@ -2204,7 +2282,7 @@ class Skin {
           and by the user contributions list. It is responsible for formatting edit
           comments. It escapes any HTML in the comment, but adds some CSS to format
           auto-generated comments (from section editing) and formats [[wikilinks]].
-          Main author: Erik Möller (moeller@scireview.de)
+          Main author: Erik Möller (moeller@scireview.de)
        */
        function formatComment($comment)
        {
@@ -2235,7 +2313,7 @@ class Skin {
                        if(preg_match("/^".$medians."/i",$match[1])) {
                                $func="makeMediaLink";
                        }
-                       if($match[3]) {
+                       if(isset($match[3]) ) {
                                $comment=
                                preg_replace("/\[\[(.*?)\]\]/",
                                $this->$func($match[1],$match[3]),$comment,1);
@@ -2464,14 +2542,9 @@ class Skin {
                                "key"=>"R"
                                )
                );
-               $toolbar ="<script type='text/javascript'>\n";
-
-               $xml = ($wgMimeType == "text/xml");
-               if( $xml ) {
-                       $toolbar .= "<![CDATA[";
-               }
-
-               $toolbar.="document.writeln(\"<div id='toolbar' tabindex='4000000'>\");\n";
+               $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
+               
+               $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
                foreach($toolarray as $tool) {
 
                        $image=$wgUploadPath."/".$tool["image"];
@@ -2492,11 +2565,8 @@ class Skin {
 
                $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
                $toolbar.="document.writeln(\"</div>\");\n";
-
-               if( $xml ) {
-                       $toolbar .= "]]>";
-               }
-               $toolbar.="</script>";
+               
+               $toolbar.="/*]]>*/\n</script>";
                return $toolbar;
        }
 }
@@ -2505,9 +2575,6 @@ include_once( "SkinStandard.php" );
 include_once( "SkinNostalgia.php" );
 include_once( "SkinCologneBlue.php" );
 
-if( $wgUseSmarty ) {
-       include_once( "SkinSmarty.php" );
-}
 if( $wgUsePHPTal ) {
        include_once( "SkinPHPTal.php" );
 }