Avoid undefined variable error on null edits
[lhc/web/wiklou.git] / includes / Skin.php
index 43f6c60..a9aeccd 100644 (file)
@@ -79,7 +79,7 @@ class Skin extends Linker {
        }
 
        /** @return string path to the skin stylesheet */
-       function getStylesheet() { return 'common/wikistandard.css'; }
+       function getStylesheet() { return 'common/wikistandard.css?1'; }
 
        /** @return string skin name */
        function getSkinName() {
@@ -102,12 +102,14 @@ class Skin extends Linker {
                $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
 
                $this->addMetadataLinks($out);
+               
+               $this->mRevisionId = $out->mRevisionId;
 
                wfProfileOut( $fname );
        }
 
        function addMetadataLinks( &$out ) {
-               global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
+               global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
                global $wgRightsPage, $wgRightsUrl;
 
                if( $out->isArticleRelated() ) {
@@ -174,7 +176,7 @@ class Skin extends Linker {
        }
 
        function getHeadScripts() {
-               global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs, $wgJsMimeType;
+               global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
                $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
                if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
                        $userpage = $wgUser->getUserPage();
@@ -212,21 +214,16 @@ class Skin extends Linker {
 
        # 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;
+               global $wgOut, $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
                $sheet = $this->getStylesheet();
                $action = $wgRequest->getText('action');
                $s = "@import \"$wgStylePath/$sheet\";\n";
                if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
-               if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
-                       if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
-                               $s .= $wgRequest->getText('wpTextbox1');
-                       } else {
-                               $userpage = $wgUser->getUserPage();
-                               $s.= '@import "'.$this->makeUrl(
-                                       $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
-                                       'action=raw&ctype=text/css').'";'."\n";
-                       }
-               }
+
+               $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
+               $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
+                       '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
+
                $s .= $this->doGetUserStyles();
                return $s."\n";
        }
@@ -240,7 +237,7 @@ class Skin extends Linker {
         * Return html code that include User stylesheets
         */
        function getUserStyles() {
-               global $wgOut, $wgStylePath, $wgLang;
+               global $wgOut, $wgStylePath;
                $s = "<style type='text/css'>\n";
                $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
                $s .= $this->getUserStylesheet();
@@ -253,10 +250,20 @@ class Skin extends Linker {
         * Some styles that are set by user through the user settings interface.
         */
        function doGetUserStyles() {
-               global $wgUser, $wgContLang;
+               global $wgUser, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
 
-               $csspage = $wgContLang->getNsText( NS_MEDIAWIKI ) . ':' . $this->getSkinName() . '.css';
-               $s = '@import "'.$this->makeUrl($csspage, 'action=raw&ctype=text/css')."\";\n";
+               $s = '';
+               
+               if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
+                       if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
+                               $s .= $wgRequest->getText('wpTextbox1');
+                       } else {
+                               $userpage = $wgUser->getUserPage();
+                               $s.= '@import "'.$this->makeUrl(
+                                       $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
+                                       'action=raw&ctype=text/css').'";'."\n";
+                       }
+               }
 
                return $s . $this->reallyDoGetUserStyles();
        }
@@ -302,7 +309,7 @@ END;
        }
 
        function getBodyOptions() {
-               global $wgUser, $wgTitle, $wgNamespaceBackgrounds, $wgOut, $wgRequest;
+               global $wgUser, $wgTitle, $wgOut, $wgRequest;
 
                extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
 
@@ -311,17 +318,10 @@ END;
                }
                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 );
-                       }
-                       $s = $wgTitle->getFullURL( "action=edit{$oid}{$red}" );
-                       $s = 'document.location = "' .$s .'";';
+                       $s = $wgTitle->getFullURL( $this->editUrlOptions() );
+                       $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
                        $a += array ('ondblclick' => $s);
 
                }
@@ -415,18 +415,22 @@ END;
 
 
        function getCategoryLinks () {
-               global $wgOut, $wgTitle, $wgParser;
-               global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
+               global $wgOut, $wgTitle, $wgUseCategoryMagic, $wgUseCategoryBrowser;
+               global $wgContLang;
 
                if( !$wgUseCategoryMagic ) return '' ;
                if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
 
-               # Taken out so that they will be displayed in previews -- TS
-               #if( !$wgOut->isArticle() ) return '';
-
-               $t = implode ( ' | ' , $wgOut->mCategoryLinks ) ;
+               // Use Unicode bidi embedding override characters,
+               // to make sure links don't smash each other up in ugly ways.
+               $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
+               $embed = "<span dir='$dir'>";
+               $pop = '</span>';
+               $t = $embed . implode ( "$pop | $embed" , $wgOut->mCategoryLinks ) . $pop;
+               
+               $msg = count( $wgOut->mCategoryLinks ) === 1 ? 'categories1' : 'categories';
                $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ),
-                       wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
+                       wfMsg( $msg ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
                        . ': ' . $t;
 
                # optional 'dmoz-like' category browser. Will be shown under the list
@@ -436,22 +440,30 @@ END;
 
                        # get a big array of the parents tree
                        $parenttree = $wgTitle->getParentCategoryTree();
-
                        # Skin object passed by reference cause it can not be
-                       # accessed under the method subfunction walkThrough.
-                       $s .= Skin::drawCategoryBrowser($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
-       function drawCategoryBrowser ($tree, &$skin) {
+       /** 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 .= '<br />';
+                               $return .= "\n";
                        } else {
                                # grab the others elements
                                $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
@@ -509,6 +521,10 @@ END;
                if( $disclaimer ) {
                        $s .= ' | ' . $disclaimer;
                }
+               $privacy = $this->privacyLink(); # may be empty too
+               if( $privacy ) {
+                       $s .= ' | ' . $privacy;
+               }
 
                if ( $wgOut->isArticleRelated() ) {
                        if ( $wgTitle->getNamespace() == NS_IMAGE ) {
@@ -549,13 +565,18 @@ END;
 
        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 '';
        }
@@ -633,7 +654,7 @@ END;
        }
 
        function nameAndLogin() {
-               global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
+               global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
 
                $li = $wgContLang->specialPage( 'Userlogin' );
                $lo = $wgContLang->specialPage( 'Userlogout' );
@@ -641,10 +662,10 @@ END;
                $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 {
@@ -663,7 +684,7 @@ END;
                        $n = $wgUser->getName();
                        $rt = $wgTitle->getPrefixedURL();
                        $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
-                         $wgContLang->getNsText( NS_TALK ) );
+                         $wgLang->getNsText( NS_TALK ) );
 
                        $tl = " ({$tl})";
 
@@ -732,7 +753,7 @@ END;
        }
 
        function bottomLinks() {
-               global $wgOut, $wgUser, $wgTitle;
+               global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
                $sep = " |\n";
 
                $s = '';
@@ -746,6 +767,9 @@ END;
                          . $sep . $this->whatLinksHere()
                          . $sep . $this->watchPageLinksLink();
 
+                       if ($wgUseTrackbacks)
+                               $s .= $sep . $this->trackbackLink();
+
                        if ( $wgTitle->getNamespace() == NS_USER
                            || $wgTitle->getNamespace() == NS_USER_TALK )
 
@@ -956,13 +980,21 @@ END;
                return $s;
        }
 
+       function privacyLink() {
+               $privacy = wfMsg( 'privacy' );
+               if ($privacy == '-') {
+                       return '';
+               } else {
+                       return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
+               }
+       }
+
        function aboutLink() {
                $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
                  wfMsg( 'aboutsite' ) );
                return $s;
        }
 
-
        function disclaimerLink() {
                $disclaimers = wfMsg( 'disclaimers' );
                if ($disclaimers == '-') {
@@ -976,10 +1008,6 @@ END;
        function editThisPage() {
                global $wgOut, $wgTitle, $wgRequest;
 
-               $oldid = $wgRequest->getVal( 'oldid' );
-               $diff = $wgRequest->getVal( 'diff' );
-               $redirect = $wgRequest->getVal( 'redirect' );
-
                if ( ! $wgOut->isArticleRelated() ) {
                        $s = wfMsg( 'protectedpage' );
                } else {
@@ -988,16 +1016,28 @@ END;
                        } else {
                                $t = wfMsg( 'viewsource' );
                        }
-                       $oid = $red = '';
 
-                       if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
-                       if ( $oldid && ! isset( $diff ) ) {
-                               $oid = '&oldid='.$oldid;
-                       }
-                       $s = $this->makeKnownLinkObj( $wgTitle, $t, "action=edit{$oid}{$red}" );
+                       $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
                }
                return $s;
        }
+       
+       /**
+        * Return URL options for the 'edit page' link.
+        * This may include an 'oldid' specifier, if the current page view is such.
+        *
+        * @return string
+        * @access private
+        */
+       function editUrlOptions() {
+               global $wgArticle;
+               
+               if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
+                       return "action=edit&oldid=" . intval( $this->mRevisionId );
+               } else {
+                       return "action=edit";
+               }
+       }
 
        function deleteThisPage() {
                global $wgUser, $wgOut, $wgTitle, $wgRequest;
@@ -1113,6 +1153,13 @@ END;
                }
        }
 
+       function trackbackLink() {
+               global $wgTitle;
+
+               return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
+                       . wfMsg('trackbacklink') . "</a>";
+       }
+
        function otherLanguages() {
                global $wgOut, $wgContLang, $wgTitle, $wgHideInterlanguageLinks;
 
@@ -1247,8 +1294,7 @@ END;
        # If url string starts with http, consider as external URL, else
        # internal
        /*static*/ function makeInternalOrExternalUrl( $name ) {
-               global $wgUrlProtcols;
-               if ( preg_match( '/^(?:' . $wgUrlProtcols . ')/', $name ) ) {
+               if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
                        return $name;
                } else {
                        return $this->makeUrl( $name );
@@ -1272,6 +1318,18 @@ END;
                );
        }
 
+       /**
+        * Make URL details where the article exists (or at least it's convenient to think so)
+        */
+       function makeKnownUrlDetails( $name, $urlaction='' ) {
+               $title = Title::newFromText( $name );
+               $this->checkTitle($title, $name);
+               return array(
+                       'href' => $title->getLocalURL( $urlaction ),
+                       'exists' => true
+               );
+       }
+
        # make sure we have some title to operate on
        /*static*/ function checkTitle ( &$title, &$name ) {
                if(!is_object($title)) {
@@ -1289,7 +1347,10 @@ END;
         * @access private
         */
        function buildSidebar() {
+               global $wgTitle, $action;
+
                $fname = 'SkinTemplate::buildSidebar';
+               $pageurl = $wgTitle->getLocalURL();
                wfProfileIn( $fname );
 
                $bar = array();
@@ -1306,10 +1367,16 @@ END;
                                        $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];
+                                       $href = $this->makeInternalOrExternalUrl( $link );
                                        $bar[$heading][] = array(
-                                               'text' => wfMsg( $line[1] ),
-                                               'href' => $this->makeInternalOrExternalUrl( $link ),
+                                               'text' => $text,
+                                               'href' => $href,
                                                'id' => 'n-' . strtr($line[1], ' ', '-'),
+                                               'active' => $pageurl == $href
                                        );
                                } else { continue; }
                        }