Don't look for pipes in the root node.
[lhc/web/wiklou.git] / includes / Skin.php
index dc53517..15536c4 100644 (file)
@@ -27,6 +27,8 @@ class Skin extends Linker {
        protected $skinname = 'standard';
        // @todo Fixme: should be protected :-\
        var $mTitle = null;
+       protected $mRelevantTitle = null;
+       protected $mRelevantUser = null;
 
        /** Constructor, call parent constructor */
        function __construct() {
@@ -41,7 +43,7 @@ class Skin extends Linker {
                global $wgValidSkinNames;
                static $skinsInitialised = false;
 
-               if ( !$skinsInitialised ) {
+               if ( !$skinsInitialised || !count( $wgValidSkinNames ) ) {
                        # Get a list of available skins
                        # Build using the regular expression '^(.*).php$'
                        # Array keys are all lower case, array value keep the case used by filename
@@ -142,7 +144,7 @@ class Skin extends Linker {
 
                $skinNames = Skin::getSkinNames();
                $skinName = $skinNames[$key];
-               $className = 'Skin' . ucfirst( $key );
+               $className = "Skin{$skinName}";
 
                # Grab the skin class and initialise it.
                if ( !class_exists( $className ) ) {
@@ -192,7 +194,7 @@ class Skin extends Linker {
        }
 
        function initPage( OutputPage $out ) {
-               global $wgFavicon, $wgAppleTouchIcon;
+               global $wgFavicon, $wgAppleTouchIcon, $wgEnableAPI;
 
                wfProfileIn( __METHOD__ );
 
@@ -216,6 +218,18 @@ class Skin extends Linker {
                        'title' => wfMsgForContent( 'opensearch-desc' ),
                ) );
 
+               if ( $wgEnableAPI ) {
+                       # Real Simple Discovery link, provides auto-discovery information
+                       # for the MediaWiki API (and potentially additional custom API
+                       # support such as WordPress or Twitter-compatible APIs for a
+                       # blogging extension, etc)
+                       $out->addLink( array(
+                               'rel' => 'EditURI',
+                               'type' => 'application/rsd+xml',
+                               'href' => wfExpandUrl( wfAppendQuery( wfScript( 'api' ), array( 'action' => 'rsd' ) ) ),
+                       ) );
+               }
+
                $this->addMetadataLinks( $out );
 
                $this->mRevisionId = $out->mRevisionId;
@@ -265,7 +279,7 @@ class Skin extends Linker {
         */
        function addMetadataLinks( OutputPage $out ) {
                global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
-               global $wgDisableLangConversion, $wgDisableLangCanonical, $wgContLang;
+               global $wgDisableLangConversion, $wgCanonicalLanguageLinks, $wgContLang;
                global $wgRightsPage, $wgRightsUrl;
 
                if ( $out->isArticleRelated() ) {
@@ -287,7 +301,7 @@ class Skin extends Linker {
                        }
                }
 
-               if ( !$wgDisableLangConversion && !$wgDisableLangCanonical
+               if ( !$wgDisableLangConversion && $wgCanonicalLanguageLinks
                        && $wgContLang->hasVariants() ) {
 
                        $urlvar = $wgContLang->getURLVariant();
@@ -340,6 +354,15 @@ class Skin extends Linker {
                $this->usercss = false;
        }
 
+       /**
+        * Whether the revision displayed is the latest revision of the page
+        *
+        * @return Boolean
+        */
+       public function isRevisionCurrent() {
+               return $this->mRevisionId == 0 || $this->mRevisionId == $this->mTitle->getLatestRevID();
+       }
+
        /**
         * Set the title
         * @param $t Title object to use
@@ -353,6 +376,66 @@ class Skin extends Linker {
                return $this->mTitle;
        }
 
+       /**
+        * Set the "relevant" title
+        * @see self::getRelevantTitle()
+        * @param $t Title object to use
+        */
+       public function setRelevantTitle( $t ) {
+               $this->mRelevantTitle = $t;
+       }
+
+       /**
+        * Return the "relevant" title.
+        * A "relevant" title is not necessarily the actual title of the page.
+        * Special pages like Special:MovePage use set the page they are acting on
+        * as their "relevant" title, this allows the skin system to display things
+        * such as content tabs which belong to to that page instead of displaying
+        * a basic special page tab which has almost no meaning.
+        */
+       public function getRelevantTitle() {
+               if ( isset($this->mRelevantTitle) ) {
+                       return $this->mRelevantTitle;
+               }
+               return $this->mTitle;
+       }
+
+       /**
+        * Set the "relevant" user
+        * @see self::getRelevantUser()
+        * @param $u User object to use
+        */
+       public function setRelevantUser( $u ) {
+               $this->mRelevantUser = $u;
+       }
+
+       /**
+        * Return the "relevant" user.
+        * A "relevant" user is similar to a relevant title. Special pages like
+        * Special:Contributions mark the user which they are relevant to so that
+        * things like the toolbox can display the information they usually are only
+        * able to display on a user's userpage and talkpage.
+        */
+       public function getRelevantUser() {
+               if ( isset($this->mRelevantUser) ) {
+                       return $this->mRelevantUser;
+               }
+               $title = $this->getRelevantTitle();
+               if( $title->getNamespace() == NS_USER || $title->getNamespace() == NS_USER_TALK ) {
+                       $rootUser = strtok( $title->getText(), '/' );
+                       if ( User::isIP( $rootUser ) ) {
+                               $this->mRelevantUser = User::newFromName( $rootUser, false );
+                       } else {
+                               $user = User::newFromName( $rootUser );
+                               if ( $user->isLoggedIn() ) {
+                                       $this->mRelevantUser = $user;
+                               }
+                       }
+                       return $this->mRelevantUser;
+               }
+               return null;
+       }
+
        /**
         * Outputs the HTML generated by other functions.
         * @param $out Object: instance of OutputPage
@@ -370,7 +453,7 @@ class Skin extends Linker {
                $out->out( $out->headElement( $this ) );
 
                if ( $wgDebugComments ) {
-                       $out->out( "<!-- Wiki debugging output:\n" .
+                       $out->out( "<!-- Debug output:\n" .
                          $out->mDebugtext . "-->\n" );
                }
 
@@ -410,7 +493,7 @@ class Skin extends Linker {
         * You will only be adding bloat to the page and causing page caches to have to be purged on configuration changes.
         */
        static function makeGlobalVariablesScript( $skinName ) {
-               global $wgTitle, $wgUser, $wgRequest, $wgArticle, $wgOut, $wgRestrictionTypes, $wgUseAjax, $wgEnableMWSuggest;
+               global $wgTitle, $wgUser, $wgRequest, $wgOut, $wgUseAjax, $wgEnableMWSuggest;
                
                $ns = $wgTitle->getNamespace();
                $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
@@ -426,10 +509,11 @@ class Skin extends Linker {
                        'wgIsArticle' => $wgOut->isArticle(),
                        'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
                        'wgUserGroups' => $wgUser->getEffectiveGroups(),
-                       'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
+                       'wgCurRevisionId' => $wgTitle->getLatestRevID(),
                        'wgCategories' => $wgOut->getCategories(),
+                       'wgBreakFrames' => $wgOut->getFrameOptions() == 'DENY',
                );
-               foreach ( $wgRestrictionTypes as $type ) {
+               foreach ( $wgTitle->getRestrictionTypes() as $type ) {
                        $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
                }
                if ( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
@@ -519,17 +603,11 @@ class Skin extends Linker {
         */
        function setupUserCss( OutputPage $out ) {
                global $wgRequest;
-               global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs, $wgSquidMaxage;
+               global $wgUseSiteCss, $wgAllowUserCss, $wgAllowUserCssPrefs;
 
                wfProfileIn( __METHOD__ );
 
                $this->setupSkinUserCss( $out );
-
-               $siteargs = array(
-                       'action' => 'raw',
-                       'maxage' => $wgSquidMaxage,
-               );
-
                // Add any extension CSS
                foreach ( $out->getExtStyle() as $url ) {
                        $out->addStyle( $url );
@@ -1404,22 +1482,11 @@ class Skin extends Linker {
                global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
                global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
 
-               $oldid = $wgRequest->getVal( 'oldid' );
-               $diff = $wgRequest->getVal( 'diff' );
-
-               if ( !$wgOut->isArticle() ) {
-                       return '';
-               }
-
-               if ( !$wgArticle instanceof Article ) {
-                       return '';
-               }
-
-               if ( isset( $oldid ) || isset( $diff ) ) {
+               if ( !is_null( $wgRequest->getVal( 'oldid' ) ) || !is_null( $wgRequest->getVal( 'diff' ) ) ) {
                        return '';
                }
 
-               if ( 0 == $wgArticle->getID() ) {
+               if ( !$wgOut->isArticle() || !$this->mTitle->exists() ) {
                        return '';
                }
 
@@ -1461,13 +1528,12 @@ class Skin extends Linker {
        }
 
        function getCopyright( $type = 'detect' ) {
-               global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
+               global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
 
                if ( $type == 'detect' ) {
                        $diff = $wgRequest->getVal( 'diff' );
-                       $isCur = $wgArticle && $wgArticle->isCurrent();
 
-                       if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
+                       if ( is_null( $diff ) && !$this->isRevisionCurrent() && wfMsgForContent( 'history_copyright' ) !== '-' ) {
                                $type = 'history';
                        } else {
                                $type = 'normal';
@@ -1497,9 +1563,7 @@ class Skin extends Linker {
                // Allow for site and per-namespace customization of copyright notice.
                $forContent = true;
 
-               if ( isset( $wgArticle ) ) {
-                       wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
-               }
+               wfRunHooks( 'SkinCopyrightFooter', array( $this->mTitle, $type, &$msg, &$link, &$forContent ) );
 
                if ( $forContent ) {
                        $out .= wfMsgForContent( $msg, $link );
@@ -1544,16 +1608,16 @@ class Skin extends Linker {
                global $wgStylePath;
 
                $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
-               $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
-
-               return $img;
+               $text = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
+               wfRunHooks( 'SkinGetPoweredBy', array( &$text, $this ) );       
+               return $text;
        }
 
        function lastModified() {
                global $wgLang, $wgArticle;
 
-               if ( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
-                       $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
+               if ( !$this->isRevisionCurrent() ) {
+                       $timestamp = Revision::getTimestampFromId( $this->mTitle, $this->mRevisionId );
                } else {
                        $timestamp = $wgArticle->getTimestamp();
                }
@@ -1624,6 +1688,29 @@ class Skin extends Linker {
                return $s;
        }
 
+       /**
+        * Renders a $wgFooterIcons icon acording to the method's arguments
+        * @param $icon Array: The icon to build the html for, see $wgFooterIcons for the format of this array
+        * @param $withImage Boolean: Whether to use the icon's image or output a text-only footericon
+        */
+       function makeFooterIcon( $icon, $withImage = 'withImage' ) {
+               if ( is_string( $icon ) ) {
+                       $html = $icon;
+               } else { // Assuming array
+                       $url = $icon["url"];
+                       unset( $icon["url"] );
+                       if ( isset( $icon["src"] ) && $withImage === 'withImage' ) {
+                               $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
+                       } else {
+                               $html = htmlspecialchars( $icon["alt"] );
+                       }
+                       if ( $url ) {
+                               $html = Html::rawElement( 'a', array( "href" => $url ), $html );
+                       }
+               }
+               return $html;
+       }
+
        /**
         * Gets the link to the wiki's main page.
         * @return string
@@ -1640,7 +1727,7 @@ class Skin extends Linker {
                return $s;
        }
 
-       private function footerLink( $desc, $page ) {
+       public function footerLink( $desc, $page ) {
                // if the link description has been set to "-" in the default language,
                if ( wfMsgForContent( $desc )  == '-' ) {
                        // then it is disabled, for all languages.
@@ -1713,11 +1800,9 @@ class Skin extends Linker {
         * @private
         */
        function editUrlOptions() {
-               global $wgArticle;
-
                $options = array( 'action' => 'edit' );
 
-               if ( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
+               if ( !$this->isRevisionCurrent() ) {
                        $options['oldid'] = intval( $this->mRevisionId );
                }
 
@@ -2030,6 +2115,30 @@ class Skin extends Linker {
                }
        }
 
+       /**
+        * Return a fully resolved style path url to images or styles stored in the common folder.
+        * This method returns a url resolved using the configured skin style path
+        * and includes the style version inside of the url.
+        * @param $name String: The name or path of a skin resource file
+        * @return String The fully resolved style path url including styleversion
+        */
+       function getCommonStylePath( $name ) {
+               global $wgStylePath, $wgStyleVersion;
+               return "$wgStylePath/common/$name?$wgStyleVersion";
+       }
+
+       /**
+        * Return a fully resolved style path url to images or styles stored in the curent skins's folder.
+        * This method returns a url resolved using the configured skin style path
+        * and includes the style version inside of the url.
+        * @param $name String: The name or path of a skin resource file
+        * @return String The fully resolved style path url including styleversion
+        */
+       function getSkinStylePath( $name ) {
+               global $wgStylePath, $wgStyleVersion;
+               return "$wgStylePath/{$this->stylename}/$name?$wgStyleVersion";
+       }
+
        /* these are used extensively in SkinTemplate, but also some other places */
        static function makeMainPageUrl( $urlaction = '' ) {
                $title = Title::newMainPage();