* using htmlspecialchars() for safe XHTML output
[lhc/web/wiklou.git] / includes / Skin.php
index 9baec63..27a8d22 100644 (file)
@@ -11,7 +11,7 @@
  */
 if( defined( "MEDIAWIKI" ) ) {
 
-# See skin.doc
+# See skin.txt
 require_once( 'Linker.php' );
 require_once( 'Image.php' );
 
@@ -34,17 +34,6 @@ unset($matches);
 
 require_once( 'RecentChange.php' );
 
-global $wgLinkHolders;
-$wgLinkHolders = array(
-       'namespaces' => array(),
-       'dbkeys' => array(),
-       'queries' => array(),
-       'texts' => array(),
-       'titles' => array()
-);
-global $wgInterwikiLinkHolders;
-$wgInterwikiLinkHolders = array();
-
 /**
  * @todo document
  * @package MediaWiki
@@ -81,19 +70,18 @@ class Skin extends Linker {
        var $rcMoveIndex;
        /**#@-*/
 
-       function Skin() {
-               parent::Linker();
-       }
+       /** Constructor, call parent constructor */
+       function Skin() { parent::Linker(); }
 
        function getSkinNames() {
                global $wgValidSkinNames;
                return $wgValidSkinNames;
        }
 
-       function getStylesheet() {
-               return 'common/wikistandard.css';
-       }
+       /** @return string path to the skin stylesheet */
+       function getStylesheet() { return 'common/wikistandard.css'; }
 
+       /** @return string skin name */
        function getSkinName() {
                return 'standard';
        }
@@ -120,7 +108,7 @@ class Skin extends Linker {
 
        function addMetadataLinks( &$out ) {
                global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
-               global $wgRightsPage, $wgRightsUrl;
+               global $wgRightsPage, $wgRightsUrl, $wgUseTrackbacks;
 
                if( $out->isArticleRelated() ) {
                        # note: buggy CC software only reads first "meta" link
@@ -159,6 +147,7 @@ class Skin extends Linker {
 
                wfProfileIn( 'Skin::outputPage' );
                $this->initPage( $out );
+
                $out->out( $out->headElement() );
 
                $out->out( "\n<body" );
@@ -171,6 +160,7 @@ class Skin extends Linker {
                        $out->out( "<!-- Wiki debugging output:\n" .
                          $out->mDebugtext . "-->\n" );
                }
+
                $out->out( $this->beforeContent() );
 
                $out->out( $out->mBodytext . "\n" );
@@ -184,14 +174,14 @@ class Skin extends Linker {
        }
 
        function getHeadScripts() {
-               global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs;
-               $r = "<script type=\"text/javascript\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
+               global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs, $wgJsMimeType;
+               $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
                if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
                        $userpage = $wgUser->getUserPage();
                        $userjs = htmlspecialchars( $this->makeUrl(
                                $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
-                               'action=raw&ctype=text/javascript'));
-                       $r .= '<script type="text/javascript" src="'.$userjs."\"></script>\n";
+                               'action=raw&ctype='.$wgJsMimeType));
+                       $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
                }
                return $r;
        }
@@ -209,17 +199,17 @@ class Skin extends Linker {
         */
        function userCanPreview( $action ) {
                global $wgTitle, $wgRequest, $wgUser;
-               
+
                if( $action != 'submit' )
                        return false;
                if( !$wgRequest->wasPosted() )
                        return false;
-               if( !$wgTitle->userCanEditCssJsSubpage() ) 
+               if( !$wgTitle->userCanEditCssJsSubpage() )
                        return false;
                return $wgUser->matchEditToken(
                        $wgRequest->getVal( 'wpEditToken' ) );
        }
-       
+
        # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
        function getUserStylesheet() {
                global $wgOut, $wgStylePath, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
@@ -268,18 +258,45 @@ class Skin extends Linker {
                $csspage = $wgContLang->getNsText( NS_MEDIAWIKI ) . ':' . $this->getSkinName() . '.css';
                $s = '@import "'.$this->makeUrl($csspage, 'action=raw&ctype=text/css')."\";\n";
 
-               if ( 1 == $wgUser->getOption( 'underline' ) ) {
-                       # Don't override browser settings
-               } else {
-                       # CHECK MERGE @@@
-                       # Force no underline
-                       $s .= "a { text-decoration: none; }\n";
+               return $s . $this->reallyDoGetUserStyles();
+       }
+
+       function reallyDoGetUserStyles() {
+               global $wgUser;
+               $s = '';
+               if (($undopt = $wgUser->getOption("underline")) != 2) {
+                       $underline = $undopt ? 'underline' : 'none';
+                       $s .= "a { text-decoration: $underline; }\n";
                }
-               if ( 1 == $this->mOptions['highlightbroken'] ) {
+               if( $wgUser->getOption( 'highlightbroken' ) ) {
                        $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
+               } else {
+                       $s .= <<<END
+a.new, #quickbar a.new,
+a.stub, #quickbar a.stub {
+       color: inherit;
+       text-decoration: inherit;
+}
+a.new:after, #quickbar a.new:after {
+       content: "?";
+       color: #CC2200;
+       text-decoration: $underline;
+}
+a.stub:after, #quickbar a.stub:after {
+       content: "!";
+       color: #772233;
+       text-decoration: $underline;
+}
+END;
+               }
+               if( $wgUser->getOption( 'justify' ) ) {
+                       $s .= "#article, #bodyContent { text-align: justify; }\n";
+               }
+               if( !$wgUser->getOption( 'showtoc' ) ) {
+                       $s .= "#toc { display: none; }\n";
                }
-               if ( 1 == $wgUser->getOption( 'justify' ) ) {
-                       $s .= "#article { text-align: justify; }\n";
+               if( !$wgUser->getOption( 'editsection' ) ) {
+                       $s .= ".editsection { display: none; }\n";
                }
                return $s;
        }
@@ -294,14 +311,14 @@ class Skin extends Linker {
                }
                else $a = array( 'bgcolor' => '#FFFFFF' );
                if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
-                 (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) {
+                 $wgTitle->userCanEdit() ) {
                        $t = wfMsg( 'editthispage' );
                        $oid = $red = '';
                        if ( !empty($redirect) && $redirect == 'no' ) {
                                $red = "&redirect={$redirect}";
                        }
                        if ( !empty($oldid) && ! isset( $diff ) ) {
-                               $oid = "&oldid=" . IntVal( $oldid );
+                               $oid = "&oldid=" . intval( $oldid );
                        }
                        $s = $wgTitle->getFullURL( "action=edit{$oid}{$red}" );
                        $s = 'document.location = "' .$s .'";';
@@ -309,6 +326,12 @@ class Skin extends Linker {
 
                }
                $a['onload'] = $wgOut->getOnloadHandler();
+               if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
+                       if( $a['onload'] != '' ) {
+                               $a['onload'] .= ';';
+                       }
+                       $a['onload'] .= 'setupRightClickEdit()';
+               }
                return $a;
        }
 
@@ -329,7 +352,7 @@ class Skin extends Linker {
        }
 
        function doBeforeContent() {
-               global $wgOut, $wgTitle, $wgContLang, $wgSiteNotice;
+               global $wgOut, $wgTitle, $wgContLang;
                $fname = 'Skin::doBeforeContent';
                wfProfileIn( $fname );
 
@@ -379,8 +402,9 @@ class Skin extends Linker {
                $s .= "</tr>\n</table>\n</div>\n";
                $s .= "\n<div id='article'>\n";
 
-               if( $wgSiteNotice ) {
-                       $s .= "\n<div id='siteNotice'>$wgSiteNotice</div>\n";
+               $notice = wfGetSiteNotice();
+               if( $notice ) {
+                       $s .= "\n<div id='siteNotice'>$notice</div>\n";
                }
                $s .= $this->pageTitle();
                $s .= $this->pageSubtitle() ;
@@ -389,7 +413,7 @@ class Skin extends Linker {
                return $s;
        }
 
-       
+
        function getCategoryLinks () {
                global $wgOut, $wgTitle, $wgParser;
                global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
@@ -412,35 +436,41 @@ class Skin extends Linker {
 
                        # get a big array of the parents tree
                        $parenttree = $wgTitle->getParentCategoryTree();
-
-                       # Render the array as a serie of links
-                       # Need to give skin cause $this is undefined at this level
-                       function walkThrough ($tree, &$skin) {
-                               $return = '';
-                               foreach($tree as $element => $parent) {
-                                       if(empty($parent)) {
-                                               # element start a new list
-                                               $return .= '<br />';
-                                       } else {
-                                               # grab the others elements
-                                               $return .= walkThrough($parent, $skin);
-                                       }
-                                       # add our current element to the list
-                                       $eltitle = Title::NewFromText($element);
-                                       # FIXME : should be makeLink() [AV]
-                                       $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) . ' &gt; ';
-                               }
-                               return $return;
-                       }
-
                        # Skin object passed by reference cause it can not be
-                       # accessed under the method subfunction walkThrough.
-                       $s .= walkThrough($parenttree, $this);
+                       # accessed under the method subfunction drawCategoryBrowser
+                       $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
+                       # Clean out bogus first entry and sort them
+                       unset($tempout[0]);
+                       asort($tempout);
+                       # Output one per line
+                       $s .= implode("<br />\n", $tempout);
                }
 
                return $s;
        }
 
+       /** Render the array as a serie of links.
+        * @param array $tree Categories tree returned by Title::getParentCategoryTree
+        * @param object &skin Skin passed by reference
+        * @return string separated by &gt;, terminate with "\n"
+        */
+       function drawCategoryBrowser($tree, &$skin) {
+               $return = '';
+               foreach ($tree as $element => $parent) {
+                       if (empty($parent)) {
+                               # element start a new list
+                               $return .= "\n";
+                       } else {
+                               # grab the others elements
+                               $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
+                       }
+                       # add our current element to the list
+                       $eltitle = Title::NewFromText($element);
+                       $return .=  $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
+               }
+               return $return;
+       }
+
        function getCategories() {
                $catlinks=$this->getCategoryLinks();
                if(!empty($catlinks)) {
@@ -452,17 +482,20 @@ class Skin extends Linker {
                return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
        }
 
-       # This gets called immediately before the </body> tag.
-       #
+       /**
+        * This gets called immediately before the </body> tag.
+        * @return string HTML to be put after </body> ???
+        */
        function afterContent() {
                $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
                return $printfooter . $this->doAfterContent();
        }
 
+       /** @return string Retrievied from HTML text */
        function printSource() {
                global $wgTitle;
                $url = htmlspecialchars( $wgTitle->getFullURL() );
-               return wfMsg( "retrievedfrom", "<a href=\"$url\">$url</a>" );
+               return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
        }
 
        function printFooter() {
@@ -470,12 +503,11 @@ class Skin extends Linker {
                        "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
        }
 
-       function doAfterContent() {
-       # overloaded by derived classes
-       }
+       /** overloaded by derived classes */
+       function doAfterContent() { }
 
        function pageTitleLinks() {
-               global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgUseApproval, $wgRequest;
+               global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgRequest;
 
                extract( $wgRequest->getValues( 'oldid', 'diff' ) );
                $action = $wgRequest->getText( 'action' );
@@ -489,23 +521,13 @@ class Skin extends Linker {
                if ( $wgOut->isArticleRelated() ) {
                        if ( $wgTitle->getNamespace() == NS_IMAGE ) {
                                $name = $wgTitle->getDBkey();
-                               $image = new Image( $wgTitle->getDBkey() );
+                               $image = new Image( $wgTitle );
                                if( $image->exists() ) {
                                        $link = htmlspecialchars( $image->getURL() );
                                        $style = $this->getInternalLinkAttributes( $link, $name );
                                        $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
                                }
                        }
-                       # This will show the "Approve" link if $wgUseApproval=true;
-                       if ( isset ( $wgUseApproval ) && $wgUseApproval )
-                       {
-                               $t = $wgTitle->getDBkey();
-                               $name = 'Approve this article' ;
-                               $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
-                               #htmlspecialchars( wfImageUrl( $name ) );
-                               $style = $this->getExternalLinkAttributes( $link, $name );
-                               $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
-                       }
                }
                if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
                        $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
@@ -516,7 +538,7 @@ class Skin extends Linker {
                # do not show "You have new messages" text when we are viewing our
                # own talk page
 
-                       if( $wgTitle->equals( $wgUser->getTalkPage() ) ) {
+                       if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
                                $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
                                                wfMsg('newmessageslink') );
                                $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
@@ -535,13 +557,18 @@ class Skin extends Linker {
 
        function getUndeleteLink() {
                global $wgUser, $wgTitle, $wgContLang, $action;
-               if( $wgUser->isAllowed('rollback') &&
-                       (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
-                       ($n = $wgTitle->isDeleted() ) ) {
-                       return wfMsg( 'thisisdeleted',
+               if(     (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
+                       ($n = $wgTitle->isDeleted() ) ) 
+               {
+                       if ( $wgUser->isAllowed( 'delete' ) ) {
+                               $msg = 'thisisdeleted';
+                       } else {
+                               $msg = 'viewdeleted';
+                       }
+                       return wfMsg( $msg,
                                $this->makeKnownLink(
                                        $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
-                                       wfMsg( 'restorelink', $n ) ) );
+                                       wfMsg( 'restorelink' . ($n == 1 ? '1' : ''), $n ) ) );
                }
                return '';
        }
@@ -572,7 +599,6 @@ class Skin extends Linker {
                global $wgOut, $wgTitle, $wgUser;
 
                $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
-               if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
                return $s;
        }
 
@@ -620,7 +646,7 @@ class Skin extends Linker {
        }
 
        function nameAndLogin() {
-               global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
+               global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
 
                $li = $wgContLang->specialPage( 'Userlogin' );
                $lo = $wgContLang->specialPage( 'Userlogout' );
@@ -628,10 +654,10 @@ class Skin extends Linker {
                $s = '';
                if ( $wgUser->isAnon() ) {
                        if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
-                               $n = $wgIP;
+                               $n = wfGetIP();
 
                                $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
-                                 $wgContLang->getNsText( NS_TALK ) );
+                                 $wgLang->getNsText( NS_TALK ) );
 
                                $s .= $n . ' ('.$tl.')';
                        } else {
@@ -650,7 +676,7 @@ class Skin extends Linker {
                        $n = $wgUser->getName();
                        $rt = $wgTitle->getPrefixedURL();
                        $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
-                         $wgContLang->getNsText( NS_TALK ) );
+                         $wgLang->getNsText( NS_TALK ) );
 
                        $tl = " ({$tl})";
 
@@ -715,13 +741,11 @@ class Skin extends Linker {
                        }
                }
 
-
-
                return $s;
        }
 
        function bottomLinks() {
-               global $wgOut, $wgUser, $wgTitle;
+               global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
                $sep = " |\n";
 
                $s = '';
@@ -735,6 +759,9 @@ class Skin extends Linker {
                          . $sep . $this->whatLinksHere()
                          . $sep . $this->watchPageLinksLink();
 
+                       if ($wgUseTrackbacks)
+                               $s .= $sep . $this->trackbackLink();
+
                        if ( $wgTitle->getNamespace() == NS_USER
                            || $wgTitle->getNamespace() == NS_USER_TALK )
 
@@ -778,7 +805,7 @@ class Skin extends Linker {
                }
 
                if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
-                   require_once("Credits.php");
+                   require_once('Credits.php');
                    $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
                } else {
                    $s .= $this->lastModified();
@@ -856,7 +883,7 @@ class Skin extends Linker {
 
                $timestamp = $wgArticle->getTimestamp();
                if ( $timestamp ) {
-                       $d = $wgLang->timeanddate( $wgArticle->getTimestamp(), true );
+                       $d = $wgLang->timeanddate( $timestamp, true );
                        $s = ' ' . wfMsg( 'lastmodified', $d );
                } else {
                        $s = '';
@@ -911,7 +938,7 @@ class Skin extends Linker {
                                }
                        }
                }
-               
+
                $go = wfMsg( 'go' );
                $sp = wfMsg( 'specialpages' );
                $spp = $wgContLang->specialPage( 'Specialpages' );
@@ -921,7 +948,7 @@ class Skin extends Linker {
                $s .= "<select name=\"wpDropdown\">\n";
                $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
 
-               
+
                foreach ( $a as $name => $desc ) {
                        $p = $wgContLang->specialPage( $name );
                        $s .= "<option value=\"{$p}\">{$desc}</option>\n";
@@ -955,7 +982,7 @@ class Skin extends Linker {
        function disclaimerLink() {
                $disclaimers = wfMsg( 'disclaimers' );
                if ($disclaimers == '-') {
-                       return "";
+                       return '';
                } else {
                        return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
                                                     $disclaimers );
@@ -1082,7 +1109,7 @@ class Skin extends Linker {
 #                     0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
 #                     1 != $wgUser->getOption('disablemail'); # and not disabled
        }
-       
+
        function emailUserLink() {
                global $wgTitle;
 
@@ -1102,8 +1129,19 @@ class Skin extends Linker {
                }
        }
 
+       function trackbackLink() {
+               global $wgTitle;
+
+               return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
+                       . wfMsg('trackbacklink') . "</a>";
+       }
+
        function otherLanguages() {
-               global $wgOut, $wgContLang, $wgTitle;
+               global $wgOut, $wgContLang, $wgTitle, $wgHideInterlanguageLinks;
+
+               if ( $wgHideInterlanguageLinks ) {
+                       return '';
+               }
 
                $a = $wgOut->getLanguageLinks();
                if ( 0 == count( $a ) ) {
@@ -1216,13 +1254,13 @@ class Skin extends Linker {
                $title = Title::makeTitle( NS_SPECIAL, $name );
                return $title->getLocalURL( $urlaction );
        }
-       
+
        /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
                $title = Title::newFromText( wfMsgForContent($name) );
                $this->checkTitle($title, $name);
                return $title->getLocalURL( $urlaction );
        }
-       
+
        /*static*/ function makeUrl ( $name, $urlaction='' ) {
                $title = Title::newFromText( $name );
                $this->checkTitle($title, $name);
@@ -1232,7 +1270,8 @@ class Skin extends Linker {
        # If url string starts with http, consider as external URL, else
        # internal
        /*static*/ function makeInternalOrExternalUrl( $name ) {
-               if ( strncmp( $name, 'http', 4 ) == 0 ) {
+               global $wgUrlProtocols;
+               if ( preg_match( '/^(?:' . $wgUrlProtocols . ')/', $name ) ) {
                        return $name;
                } else {
                        return $this->makeUrl( $name );
@@ -1266,6 +1305,46 @@ class Skin extends Linker {
                }
        }
 
+       /**
+        * Build an array that represents the sidebar(s), the navigation bar among them
+        *
+        * @return array
+        * @access private
+        */
+       function buildSidebar() {
+               $fname = 'SkinTemplate::buildSidebar';
+               wfProfileIn( $fname );
+
+               $bar = array();
+               $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
+               foreach ($lines as $line) {
+                       if (strpos($line, '*') !== 0)
+                               continue;
+                       if (strpos($line, '**') !== 0) {
+                               $line = trim($line, '* ');
+                               $heading = $line;
+                       } else {
+                               if (strpos($line, '|') !== false) { // sanity check
+                                       $line = explode( '|' , trim($line, '* '), 2 );
+                                       $link = wfMsgForContent( $line[0] );
+                                       if ($link == '-')
+                                               continue;
+                                       if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
+                                               $text = $line[1];
+                                       if (wfEmptyMsg($line[0], $link))
+                                               $link = $line[0];
+                                       $bar[$heading][] = array(
+                                               'text' => $text,
+                                               'href' => $this->makeInternalOrExternalUrl( $link ),
+                                               'id' => 'n-' . strtr($line[1], ' ', '-'),
+                                       );
+                               } else { continue; }
+                       }
+               }
+
+               wfProfileOut( $fname );
+               return $bar;
+       }
 }
 
 }