Fixing bug 30973. Strip off subpages when determining the username who the current...
[lhc/web/wiklou.git] / includes / Skin.php
index b0858c6..76a913b 100644 (file)
@@ -156,15 +156,10 @@ abstract class Skin extends ContextSource {
                                }
                        }
                }
-               $skin = new $className;
+               $skin = new $className( $key );
                return $skin;
        }
 
-       /** @return string path to the skin stylesheet */
-       function getStylesheet() {
-               return 'common/wikistandard.css';
-       }
-
        /** @return string skin name */
        public function getSkinName() {
                return $this->skinname;
@@ -174,7 +169,6 @@ abstract class Skin extends ContextSource {
                wfProfileIn( __METHOD__ );
 
                $this->preloadExistence();
-               $this->setMembers();
 
                wfProfileOut( __METHOD__ );
        }
@@ -202,13 +196,6 @@ abstract class Skin extends ContextSource {
                $lb->execute();
        }
 
-       /**
-        * Set some local variables
-        */
-       protected function setMembers() {
-               $this->userpage = $this->getUser()->getUserPage()->getPrefixedText();
-       }
-
        /**
         * Get the current revision ID
         *
@@ -295,7 +282,7 @@ abstract class Skin extends ContextSource {
         * Outputs the HTML generated by other functions.
         * @param $out OutputPage
         */
-       abstract function outputPage( OutputPage $out );
+       abstract function outputPage( OutputPage $out = null );
 
        static function makeVariablesScript( $data ) {
                if ( $data ) {
@@ -307,30 +294,6 @@ abstract class Skin extends ContextSource {
                }
        }
 
-       /**
-        * To make it harder for someone to slip a user a fake
-        * user-JavaScript or user-CSS preview, a random token
-        * is associated with the login session. If it's not
-        * passed back with the preview request, we won't render
-        * the code.
-        *
-        * @return bool
-        */
-       public function userCanPreview() {
-               if ( $this->getRequest()->getVal( 'action' ) != 'submit'
-                       || !$this->getRequest()->wasPosted()
-                       || !$this->getUser()->matchEditToken(
-                               $this->getRequest()->getVal( 'wpEditToken' ) )
-               ) {
-                       return false;
-               }
-               if ( !$this->getTitle()->isJsSubpage() && !$this->getTitle()->isCssSubpage() ) {
-                       return false;
-               }
-
-               return !count( $this->getTitle()->getUserPermissionsErrors( 'edit', $this->getUser() ) );
-       }
-
        /**
         * Generated JavaScript action=raw&gen=js
         * This used to load MediaWiki:Common.js and the skin-specific style
@@ -356,48 +319,6 @@ abstract class Skin extends ContextSource {
                return '';
        }
 
-       /**
-        * @private
-        * @todo document
-        * @param $out OutputPage
-        */
-       function setupUserCss( OutputPage $out ) {
-               global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
-
-               wfProfileIn( __METHOD__ );
-
-               $this->setupSkinUserCss( $out );
-               // Add any extension CSS
-               foreach ( $out->getExtStyle() as $url ) {
-                       $out->addStyle( $url );
-               }
-
-               // Per-site custom styles
-               if ( $wgUseSiteCss ) {
-                       $out->addModuleStyles( array( 'site', 'noscript' ) );
-                       if( $this->getUser()->isLoggedIn() ){
-                               $out->addModuleStyles( 'user.groups' );
-                       }
-               }
-
-               // Per-user custom styles
-               if ( $wgAllowUserCss ) {
-                       if ( $this->getTitle()->isCssSubpage() && $this->userCanPreview() ) {
-                               // @todo FIXME: Properly escape the cdata!
-                               $out->addInlineStyle( $this->getRequest()->getText( 'wpTextbox1' ) );
-                       } else {
-                               $out->addModuleStyles( 'user' );
-                       }
-               }
-
-               // Per-user preference styles
-               if ( $wgAllowUserCssPrefs ) {
-                       $out->addModuleStyles( 'user.options' );
-               }
-
-               wfProfileOut( __METHOD__ );
-       }
-
        /**
         * Get the query to generate a dynamic stylesheet
         *
@@ -431,7 +352,6 @@ abstract class Skin extends ContextSource {
         * @return String
         */
        function getPageClasses( $title ) {
-               global $wgRequest;
                $numeric = 'ns-' . $title->getNamespace();
 
                if ( $title->getNamespace() == NS_SPECIAL ) {
@@ -450,13 +370,8 @@ abstract class Skin extends ContextSource {
                }
 
                $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
-               
-               if ( $wgRequest->getVal('action') ) {
-                       $action = 'action-' . $wgRequest->getVal('action');
-               } else {
-                       $action = 'action-view';
-               }
-               return "$numeric $type $name $action";
+
+               return "$numeric $type $name";
        }
 
        /**
@@ -483,15 +398,15 @@ abstract class Skin extends ContextSource {
                global $wgUseCategoryBrowser;
 
                $out = $this->getOutput();
+               $allCats = $out->getCategoryLinks();
 
-               if ( count( $out->mCategoryLinks ) == 0 ) {
+               if ( !count( $allCats ) ) {
                        return '';
                }
 
                $embed = "<li>";
                $pop = "</li>";
 
-               $allCats = $out->getCategoryLinks();
                $s = '';
                $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
 
@@ -499,7 +414,7 @@ abstract class Skin extends ContextSource {
                        $t = $embed . implode( "{$pop}{$embed}" , $allCats['normal'] ) . $pop;
 
                        $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
-                       $s .= '<div id="mw-normal-catlinks">' .
+                       $s .= '<div id="mw-normal-catlinks" class="mw-normal-catlinks">' .
                                Linker::link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
                                . $colon . '<ul>' . $t . '</ul>' . '</div>';
                }
@@ -507,14 +422,14 @@ abstract class Skin extends ContextSource {
                # Hidden categories
                if ( isset( $allCats['hidden'] ) ) {
                        if ( $this->getUser()->getBoolOption( 'showhiddencats' ) ) {
-                               $class = 'mw-hidden-cats-user-shown';
+                               $class = ' mw-hidden-cats-user-shown';
                        } elseif ( $this->getTitle()->getNamespace() == NS_CATEGORY ) {
-                               $class = 'mw-hidden-cats-ns-shown';
+                               $class = ' mw-hidden-cats-ns-shown';
                        } else {
-                               $class = 'mw-hidden-cats-hidden';
+                               $class = ' mw-hidden-cats-hidden';
                        }
 
-                       $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
+                       $s .= "<div id=\"mw-hidden-catlinks\" class=\"mw-hidden-catlinks$class\">" .
                                wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
                                $colon . '<ul>' . $embed . implode( "{$pop}{$embed}" , $allCats['hidden'] ) . $pop . '</ul>' .
                                '</div>';
@@ -559,7 +474,7 @@ abstract class Skin extends ContextSource {
 
                        # add our current element to the list
                        $eltitle = Title::newFromText( $element );
-                       $return .=  Linker::link( $eltitle, $eltitle->getText() );
+                       $return .=  Linker::link( $eltitle, htmlspecialchars( $eltitle->getText() ) );
                }
 
                return $return;
@@ -688,33 +603,43 @@ abstract class Skin extends ContextSource {
 
        /**
         * This gets called shortly before the </body> tag.
-        * @param $out OutputPage object
+        *
         * @return String HTML-wrapped JS code to be put before </body>
         */
-       function bottomScripts( $out ) {
+       function bottomScripts() {
                // TODO and the suckage continues. This function is really just a wrapper around
                // OutputPage::getBottomScripts() which takes a Skin param. This should be cleaned
                // up at some point
-               $bottomScriptText = $out->getBottomScripts( $this );
+               $bottomScriptText = $this->getOutput()->getBottomScripts();
                wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
 
                return $bottomScriptText;
        }
 
-       /** @return string Retrievied from HTML text */
+       /**
+        * Text with the permalink to the source page,
+        * usually shown on the footer of a printed page
+        *
+        * @return string HTML text with an URL
+        */
        function printSource() {
-               $url = htmlspecialchars( $this->getTitle()->getFullURL() );
+               $oldid = $this->getRevisionId();
+               if ( $oldid ) {
+                       $url = htmlspecialchars( $this->getTitle()->getCanonicalURL( 'oldid=' . $oldid ) );
+               } else {
+                       // oldid not available for non existing pages
+                       $url = htmlspecialchars( $this->getTitle()->getCanonicalURL() );
+               }
                return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
        }
 
        function getUndeleteLink() {
                $action = $this->getRequest()->getVal( 'action', 'view' );
 
-               if ( $this->getUser()->isAllowed( 'deletedhistory' ) &&
+               if ( $this->getUser()->isAllowed( 'deletedhistory' ) && !$this->getUser()->isBlocked() &&
                        ( $this->getTitle()->getArticleId() == 0 || $action == 'history' ) ) {
+                       $n = $this->getTitle()->isDeleted();
 
-                       $includeSuppressed = $this->getUser()->isAllowed( 'suppressrevision' );
-                       $n = $this->getTitle()->isDeleted( $includeSuppressed );
 
                        if ( $n ) {
                                if ( $this->getUser()->isAllowed( 'undelete' ) ) {
@@ -725,12 +650,9 @@ abstract class Skin extends ContextSource {
 
                                return wfMsg(
                                        $msg,
-                                       Linker::link(
+                                       Linker::linkKnown(
                                                SpecialPage::getTitleFor( 'Undelete', $this->getTitle()->getPrefixedDBkey() ),
-                                               wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) ),
-                                               array(),
-                                               array(),
-                                               array( 'known', 'noclasses' )
+                                               wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $this->getLang()->formatNum( $n ) )
                                        )
                                );
                        }
@@ -762,12 +684,9 @@ abstract class Skin extends ContextSource {
                                        $linkObj = Title::newFromText( $growinglink );
 
                                        if ( is_object( $linkObj ) && $linkObj->exists() ) {
-                                               $getlink = $this->link(
+                                               $getlink = Linker::linkKnown(
                                                        $linkObj,
-                                                       htmlspecialchars( $display ),
-                                                       array(),
-                                                       array(),
-                                                       array( 'known', 'noclasses' )
+                                                       htmlspecialchars( $display )
                                                );
 
                                                $c++;
@@ -813,9 +732,7 @@ abstract class Skin extends ContextSource {
                global $wgRightsPage, $wgRightsUrl, $wgRightsText;
 
                if ( $type == 'detect' ) {
-                       $diff = $this->getRequest()->getVal( 'diff' );
-
-                       if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
+                       if ( !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
                                $type = 'history';
                        } else {
                                $type = 'normal';
@@ -828,8 +745,6 @@ abstract class Skin extends ContextSource {
                        $msg = 'copyright';
                }
 
-               $out = '';
-
                if ( $wgRightsPage ) {
                        $title = Title::newFromText( $wgRightsPage );
                        $link = Linker::linkKnown( $title, $wgRightsText );
@@ -839,7 +754,7 @@ abstract class Skin extends ContextSource {
                        $link = $wgRightsText;
                } else {
                        # Give up now
-                       return $out;
+                       return '';
                }
 
                // Allow for site and per-namespace customization of copyright notice.
@@ -848,12 +763,10 @@ abstract class Skin extends ContextSource {
                wfRunHooks( 'SkinCopyrightFooter', array( $this->getTitle(), $type, &$msg, &$link, &$forContent ) );
 
                if ( $forContent ) {
-                       $out .= wfMsgForContent( $msg, $link );
+                       return wfMsgForContent( $msg, $link );
                } else {
-                       $out .= wfMsg( $msg, $link );
+                       return wfMsg( $msg, $link );
                }
-
-               return $out;
        }
 
        function getCopyrightIcon() {
@@ -930,7 +843,7 @@ abstract class Skin extends ContextSource {
                        $a = '';
                }
 
-               $mp = wfMsg( 'mainpage' );
+               $mp = wfMsgHtml( 'mainpage' );
                $mptitle = Title::newMainPage();
                $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
 
@@ -969,12 +882,9 @@ abstract class Skin extends ContextSource {
         * @return string
         */
        function mainPageLink() {
-               $s = Linker::link(
+               $s = Linker::linkKnown(
                        Title::newMainPage(),
-                       wfMsg( 'mainpage' ),
-                       array(),
-                       array(),
-                       array( 'known', 'noclasses' )
+                       wfMsgHtml( 'mainpage' )
                );
 
                return $s;
@@ -1211,7 +1121,6 @@ abstract class Skin extends ContextSource {
         */
        function addToSidebarPlain( &$bar, $text ) {
                $lines = explode( "\n", $text );
-               $wikiBar = array(); # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
 
                $heading = '';
 
@@ -1219,6 +1128,7 @@ abstract class Skin extends ContextSource {
                        if ( strpos( $line, '*' ) !== 0 ) {
                                continue;
                        }
+                       $line = rtrim( $line, "\r" ); // for Windows compat
 
                        if ( strpos( $line, '**' ) !== 0 ) {
                                $heading = trim( $line, '* ' );
@@ -1252,24 +1162,13 @@ abstract class Skin extends ContextSource {
 
                                        if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
                                                $href = $link;
-                                               //Parser::getExternalLinkAttribs won't work here because of the Namespace things
-                                               global $wgNoFollowLinks;
-                                               if ( $wgNoFollowLinks ) {
+                                               
+                                               // Parser::getExternalLinkAttribs won't work here because of the Namespace things
+                                               global $wgNoFollowLinks, $wgNoFollowDomainExceptions;
+                                               if ( $wgNoFollowLinks && !wfMatchesDomainList( $href, $wgNoFollowDomainExceptions ) ) {
                                                        $extraAttribs['rel'] = 'nofollow';
-
-                                                       global $wgNoFollowDomainExceptions;
-                                                       if ( $wgNoFollowDomainExceptions ) {
-                                                               $bits = wfParseUrl( $url );
-                                                               if ( is_array( $bits ) && isset( $bits['host'] ) ) {
-                                                                       foreach ( $wgNoFollowDomainExceptions as $domain ) {
-                                                                               if ( substr( $bits['host'], -strlen( $domain ) ) == $domain ) {
-                                                                                       unset( $extraAttribs['rel'] );
-                                                                                       break;
-                                                                               }
-                                                                       }
-                                                               }
-                                                       }
                                                }
+                                               
                                                global $wgExternalLinkTarget;
                                                if ( $wgExternalLinkTarget) {
                                                        $extraAttribs['target'] = $wgExternalLinkTarget;
@@ -1279,7 +1178,7 @@ abstract class Skin extends ContextSource {
 
                                                if ( $title ) {
                                                        $title = $title->fixSpecialName();
-                                                       $href = $title->getLocalURL();
+                                                       $href = $title->getLinkURL();
                                                } else {
                                                        $href = 'INVALID-TITLE';
                                                }
@@ -1291,25 +1190,12 @@ abstract class Skin extends ContextSource {
                                                'id' => 'n-' . Sanitizer::escapeId( strtr( $line[1], ' ', '-' ), 'noninitial' ),
                                                'active' => false
                                        ), $extraAttribs );
-                               } elseif ( ( substr( $line, 0, 2 ) == '{{' ) && ( substr( $line, -2 ) == '}}' ) ) {
-                                       global $wgParser;
-
-                                       $line = substr( $line, 2, strlen( $line ) - 4 );
-
-                                       $options = new ParserOptions();
-                                       $options->setEditSection( false );
-                                       $options->setInterfaceMessage( true );
-                                       $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $this->getTitle(), $options )->getText();
                                } else {
                                        continue;
                                }
                        }
                }
 
-               if ( count( $wikiBar ) > 0 ) {
-                       $bar = array_merge( $bar, $wikiBar );
-               }
-
                return $bar;
        }
 
@@ -1340,20 +1226,18 @@ abstract class Skin extends ContextSource {
                        $userTalkTitle = $userTitle->getTalkPage();
 
                        if ( !$userTalkTitle->equals( $out->getTitle() ) ) {
-                               $newMessagesLink = $this->link(
+                               $newMessagesLink = Linker::linkKnown(
                                        $userTalkTitle,
                                        wfMsgHtml( 'newmessageslink' ),
                                        array(),
-                                       array( 'redirect' => 'no' ),
-                                       array( 'known', 'noclasses' )
+                                       array( 'redirect' => 'no' )
                                );
 
-                               $newMessagesDiffLink = $this->link(
+                               $newMessagesDiffLink = Linker::linkKnown(
                                        $userTalkTitle,
                                        wfMsgHtml( 'newmessagesdifflink' ),
                                        array(),
-                                       array( 'diff' => 'cur' ),
-                                       array( 'known', 'noclasses' )
+                                       array( 'diff' => 'cur' )
                                );
 
                                $ntl = wfMsg(