* (bug 1970) Don't show move tab for immobile pages
[lhc/web/wiklou.git] / includes / Skin.php
index 7bc8788..be60733 100644 (file)
@@ -11,7 +11,7 @@
  */
 if( defined( "MEDIAWIKI" ) ) {
 
-# See skin.doc
+# See skin.txt
 require_once( 'Linker.php' );
 require_once( 'Image.php' );
 
@@ -81,19 +81,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';
        }
@@ -186,9 +185,11 @@ class Skin extends Linker {
        function getHeadScripts() {
                global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs;
                $r = "<script type=\"text/javascript\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
-               if( $wgAllowUserJs && $wgUser->getID() != 0 ) { # logged in
-                       $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
-                       $userjs = htmlspecialchars($this->makeUrl($userpage.'/'.$this->getSkinName().'.js', 'action=raw&ctype=text/javascript'));
+               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";
                }
                return $r;
@@ -225,12 +226,14 @@ class Skin extends Linker {
                $action = $wgRequest->getText('action');
                $s = "@import \"$wgStylePath/$sheet\";\n";
                if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
-               if( $wgAllowUserCss && $wgUser->getID() != 0 ) { # logged in
+               if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
                        if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
                                $s .= $wgRequest->getText('wpTextbox1');
                        } else {
-                               $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
-                               $s.= '@import "'.$this->makeUrl($userpage.'/'.$this->getSkinName().'.css', 'action=raw&ctype=text/css').'";'."\n";
+                               $userpage = $wgUser->getUserPage();
+                               $s.= '@import "'.$this->makeUrl(
+                                       $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
+                                       'action=raw&ctype=text/css').'";'."\n";
                        }
                }
                $s .= $this->doGetUserStyles();
@@ -264,19 +267,41 @@ 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";
-               }
-               if ( 1 == $this->mOptions['highlightbroken'] ) {
+               return $s . $this->reallyDoGetUserStyles();
+       }
+       
+       function reallyDoGetUserStyles() {
+               global $wgUser;
+               $s = '';
+               $underline = $wgUser->getOption( "underline" ) ? 'underline' : 'none';
+               $s .= "a { text-decoration: $underline; }\n";
+               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 ( 1 == $wgUser->getOption( 'justify' ) ) {
+               if( $wgUser->getOption( 'justify' ) ) {
                        $s .= "#article { text-align: justify; }\n";
                }
+               if( !$wgUser->getOption( 'showtoc' ) ) {
+                       $s .= "#toc { display: none; }\n";
+               }
                return $s;
        }
 
@@ -305,6 +330,12 @@ class Skin extends Linker {
 
                }
                $a['onload'] = $wgOut->getOnloadHandler();
+               if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
+                       if( $a['onload'] != '' ) {
+                               $a['onload'] .= ';';
+                       }
+                       $a['onload'] .= 'setupRightClickEdit()';
+               }
                return $a;
        }
 
@@ -321,13 +352,11 @@ class Skin extends Linker {
         * two functions to make it easier to subclass.
         */
        function beforeContent() {
-               global $wgUser, $wgOut;
-
                return $this->doBeforeContent();
        }
 
        function doBeforeContent() {
-               global $wgUser, $wgOut, $wgTitle, $wgContLang, $wgSiteNotice;
+               global $wgOut, $wgTitle, $wgContLang;
                $fname = 'Skin::doBeforeContent';
                wfProfileIn( $fname );
 
@@ -377,8 +406,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 +419,7 @@ class Skin extends Linker {
 
        
        function getCategoryLinks () {
-               global $wgOut, $wgTitle, $wgUser, $wgParser;
+               global $wgOut, $wgTitle, $wgParser;
                global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
 
                if( !$wgUseCategoryMagic ) return '' ;
@@ -412,9 +442,8 @@ class Skin extends Linker {
                        $parenttree = $wgTitle->getParentCategoryTree();
 
                        # Render the array as a serie of links
-                       function walkThrough ($tree) {
-                               global $wgUser;
-                               $sk = $wgUser->getSkin();
+                       # Need to give skin cause $this is undefined at this level
+                       function walkThrough ($tree, &$skin) {
                                $return = '';
                                foreach($tree as $element => $parent) {
                                        if(empty($parent)) {
@@ -422,17 +451,19 @@ class Skin extends Linker {
                                                $return .= '<br />';
                                        } else {
                                                # grab the others elements
-                                               $return .= walkThrough($parent);
+                                               $return .= walkThrough($parent, $skin);
                                        }
                                        # add our current element to the list
                                        $eltitle = Title::NewFromText($element);
-                                       # FIXME : should be makeLink() [AV]
-                                       $return .= $sk->makeLink($element, $eltitle->getText()).' &gt; ';
+                                       if(!empty($parent)) $return .= ' &gt; ';
+                                       $return .=  $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
                                }
                                return $return;
                        }
 
-                       $s .= walkThrough($parenttree);
+                       # Skin object passed by reference cause it can not be
+                       # accessed under the method subfunction walkThrough.
+                       $s .= walkThrough($parenttree, $this);
                }
 
                return $s;
@@ -449,20 +480,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() {
-               global $wgUser, $wgOut, $wgServer;
-               global $wgTitle, $wgLang;
-
                $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,9 +501,8 @@ 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;
@@ -487,9 +517,9 @@ class Skin extends Linker {
                }
 
                if ( $wgOut->isArticleRelated() ) {
-                       if ( $wgTitle->getNamespace() == Namespace::getImage() ) {
+                       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 );
@@ -516,8 +546,7 @@ class Skin extends Linker {
                # do not show "You have new messages" text when we are viewing our
                # own talk page
 
-                       if(!(strcmp($wgTitle->getText(),$wgUser->getName()) == 0 &&
-                                               $wgTitle->getNamespace()==Namespace::getTalk(Namespace::getUser()))) {
+                       if( $wgTitle->equals( $wgUser->getTalkPage() ) ) {
                                $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
                                                wfMsg('newmessageslink') );
                                $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
@@ -573,7 +602,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;
        }
 
@@ -627,8 +655,8 @@ class Skin extends Linker {
                $lo = $wgContLang->specialPage( 'Userlogout' );
 
                $s = '';
-               if ( 0 == $wgUser->getID() ) {
-                       if( $wgShowIPinHeader && isset(  $_COOKIE[ini_get('session.name')] ) ) {
+               if ( $wgUser->isAnon() ) {
+                       if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
                                $n = $wgIP;
 
                                $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
@@ -716,8 +744,6 @@ class Skin extends Linker {
                        }
                }
 
-
-
                return $s;
        }
 
@@ -728,7 +754,7 @@ class Skin extends Linker {
                $s = '';
                if ( $wgOut->isArticleRelated() ) {
                        $s .= '<strong>' . $this->editThisPage() . '</strong>';
-                       if ( 0 != $wgUser->getID() ) {
+                       if ( $wgUser->isLoggedIn() ) {
                                $s .= $sep . $this->watchThisPage();
                        }
                        $s .= $sep . $this->talkLink()
@@ -736,8 +762,8 @@ class Skin extends Linker {
                          . $sep . $this->whatLinksHere()
                          . $sep . $this->watchPageLinksLink();
 
-                       if ( $wgTitle->getNamespace() == Namespace::getUser()
-                           || $wgTitle->getNamespace() == Namespace::getTalk(Namespace::getUser()) )
+                       if ( $wgTitle->getNamespace() == NS_USER
+                           || $wgTitle->getNamespace() == NS_USER_TALK )
 
                        {
                                $id=User::idFromName($wgTitle->getText());
@@ -779,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();
@@ -857,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 = '';
@@ -956,7 +982,7 @@ class Skin extends Linker {
        function disclaimerLink() {
                $disclaimers = wfMsg( 'disclaimers' );
                if ($disclaimers == '-') {
-                       return "";
+                       return '';
                } else {
                        return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
                                                     $disclaimers );
@@ -1077,7 +1103,7 @@ class Skin extends Linker {
                global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
                return $wgEnableEmail &&
                       $wgEnableUserEmail &&
-                      0 != $wgUser->getID() && # show only to signed in users
+                      $wgUser->isLoggedIn() && # show only to signed in users
                       0 != $id; # we can only email to non-anons ..
 #                     '' != $id->getEmail() && # who must have an email address stored ..
 #                     0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated