Merge "Provide direction hinting in the personal toolbar"
[lhc/web/wiklou.git] / includes / SkinTemplate.php
index 6bd768b..b13d285 100644 (file)
@@ -130,39 +130,65 @@ class SkinTemplate extends Skin {
         */
        public function getLanguages() {
                global $wgHideInterlanguageLinks;
-               $out = $this->getOutput();
+               if ( $wgHideInterlanguageLinks ) {
+                       return array();
+               }
 
-               # Language links
-               $language_urls = array();
-
-               if ( !$wgHideInterlanguageLinks ) {
-                       foreach ( $out->getLanguageLinks() as $languageLinkText ) {
-                               $languageLinkParts = explode( ':', $languageLinkText, 2 );
-                               $class = 'interwiki-' . $languageLinkParts[0];
-                               unset( $languageLinkParts );
-                               $languageLinkTitle = Title::newFromText( $languageLinkText );
-                               if ( $languageLinkTitle ) {
-                                       $ilInterwikiCode = $languageLinkTitle->getInterwiki();
-                                       $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
-
-                                       if ( strval( $ilLangName ) === '' ) {
-                                               $ilLangName = $languageLinkText;
-                                       } else {
-                                               $ilLangName = $this->formatLanguageName( $ilLangName );
-                                       }
+               $userLang = $this->getLanguage();
+               $languageLinks = array();
 
-                                       $language_urls[] = array(
-                                               'href' => $languageLinkTitle->getFullURL(),
-                                               'text' => $ilLangName,
-                                               'title' => $languageLinkTitle->getText(),
-                                               'class' => $class,
-                                               'lang' => wfBCP47( $ilInterwikiCode ),
-                                               'hreflang' => wfBCP47( $ilInterwikiCode ),
-                                       );
+               foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
+                       $languageLinkParts = explode( ':', $languageLinkText, 2 );
+                       $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
+                       unset( $languageLinkParts );
+
+                       $languageLinkTitle = Title::newFromText( $languageLinkText );
+                       if ( $languageLinkTitle ) {
+                               $ilInterwikiCode = $languageLinkTitle->getInterwiki();
+                               $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
+
+                               if ( strval( $ilLangName ) === '' ) {
+                                       $ilLangName = $languageLinkText;
+                               } else {
+                                       $ilLangName = $this->formatLanguageName( $ilLangName );
+                               }
+
+                               // CLDR extension or similar is required to localize the language name;
+                               // otherwise we'll end up with the autonym again.
+                               $ilLangLocalName = Language::fetchLanguageName(
+                                       $ilInterwikiCode,
+                                       $userLang->getCode()
+                               );
+
+                               $languageLinkTitleText = $languageLinkTitle->getText();
+                               if ( $languageLinkTitleText === '' ) {
+                                       $ilTitle = wfMessage(
+                                               'interlanguage-link-title-langonly',
+                                               $ilLangLocalName
+                                       )->text();
+                               } else {
+                                       $ilTitle = wfMessage(
+                                               'interlanguage-link-title',
+                                               $languageLinkTitleText,
+                                               $ilLangLocalName
+                                       )->text();
                                }
+
+                               $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
+                               $languageLink = array(
+                                       'href' => $languageLinkTitle->getFullURL(),
+                                       'text' => $ilLangName,
+                                       'title' => $ilTitle,
+                                       'class' => $class,
+                                       'lang' => $ilInterwikiCodeBCP47,
+                                       'hreflang' => $ilInterwikiCodeBCP47,
+                               );
+                               wfRunHooks( 'SkinTemplateGetLanguageLink', array( &$languageLink, $languageLinkTitle, $this->getTitle() ) );
+                               $languageLinks[] = $languageLink;
                        }
                }
-               return $language_urls;
+
+               return $languageLinks;
        }
 
        protected function setupTemplateForOutput() {
@@ -212,15 +238,6 @@ class SkinTemplate extends Skin {
         * @param $out OutputPage
         */
        function outputPage( OutputPage $out = null ) {
-               global $wgContLang;
-               global $wgScript, $wgStylePath;
-               global $wgMimeType, $wgJsMimeType;
-               global $wgXhtmlNamespaces, $wgHtml5Version;
-               global $wgDisableCounters, $wgSitename, $wgLogo;
-               global $wgMaxCredits, $wgShowCreditsIfMax;
-               global $wgPageShowWatchingUsers;
-               global $wgArticlePath, $wgScriptPath, $wgServer;
-
                wfProfileIn( __METHOD__ );
                Profiler::instance()->setTemplated( true );
 
@@ -232,14 +249,44 @@ class SkinTemplate extends Skin {
                }
 
                $out = $this->getOutput();
-               $request = $this->getRequest();
-               $user = $this->getUser();
-               $title = $this->getTitle();
 
                wfProfileIn( __METHOD__ . '-init' );
                $this->initPage( $out );
                wfProfileOut( __METHOD__ . '-init' );
+               $tpl = $this->prepareQuickTemplate( $out );
+               // execute template
+               wfProfileIn( __METHOD__ . '-execute' );
+               $res = $tpl->execute();
+               wfProfileOut( __METHOD__ . '-execute' );
+
+               // result may be an error
+               $this->printOrError( $res );
+
+               if ( $oldContext ) {
+                       $this->setContext( $oldContext );
+               }
+
+               wfProfileOut( __METHOD__ );
+       }
+
+       /**
+        * initialize various variables and generate the template
+        *
+        * @since 1.23
+        * @return QuickTemplate the template to be executed by outputPage
+        */
+       protected function prepareQuickTemplate() {
+               global $wgContLang, $wgScript, $wgStylePath,
+                       $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
+                       $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
+                       $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
+                       $wgScriptPath, $wgServer;
 
+               wfProfileIn( __METHOD__ );
+
+               $title = $this->getTitle();
+               $request = $this->getRequest();
+               $out = $this->getOutput();
                $tpl = $this->setupTemplateForOutput();
 
                wfProfileIn( __METHOD__ . '-stuff-head' );
@@ -292,6 +339,7 @@ class SkinTemplate extends Skin {
                        $feeds = array();
                        foreach ( $out->getSyndicationLinks() as $format => $link ) {
                                $feeds[$format] = array(
+                                       // Messages: feed-atom, feed-rss
                                        'text' => $this->msg( "feed-$format" )->text(),
                                        'href' => $link
                                );
@@ -517,18 +565,8 @@ class SkinTemplate extends Skin {
                $tpl->set( 'dataAfterContent', $this->afterContentHook() );
                wfProfileOut( __METHOD__ . '-stuff5' );
 
-               // execute template
-               wfProfileIn( __METHOD__ . '-execute' );
-               $res = $tpl->execute();
-               wfProfileOut( __METHOD__ . '-execute' );
-
-               // result may be an error
-               $this->printOrError( $res );
-
-               if ( $oldContext ) {
-                       $this->setContext( $oldContext );
-               }
                wfProfileOut( __METHOD__ );
+               return $tpl;
        }
 
        /**
@@ -588,8 +626,6 @@ class SkinTemplate extends Skin {
         * @return array
         */
        protected function buildPersonalUrls() {
-               global $wgSecureLogin;
-
                $title = $this->getTitle();
                $request = $this->getRequest();
                $pageurl = $title->getLocalURL();
@@ -617,10 +653,6 @@ class SkinTemplate extends Skin {
                        }
                }
 
-               if ( $wgSecureLogin && $request->detectProtocol() === 'https' ) {
-                       $a['wpStickHTTPS'] = true;
-               }
-
                $returnto = wfArrayToCgi( $a );
                if ( $this->loggedin ) {
                        $personal_urls['userpage'] = array(
@@ -677,7 +709,7 @@ class SkinTemplate extends Skin {
                                'active' => $active
                        );
                        $personal_urls['logout'] = array(
-                               'text' => $this->msg( 'userlogout' )->text(),
+                               'text' => $this->msg( 'pt-userlogout' )->text(),
                                'href' => self::makeSpecialUrl( 'Userlogout',
                                        // userlogout link must always contain an & character, otherwise we might not be able
                                        // to detect a buggy precaching proxy (bug 17790)
@@ -689,24 +721,18 @@ class SkinTemplate extends Skin {
                        $useCombinedLoginLink = $this->useCombinedLoginLink();
                        $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
                                ? 'nav-login-createaccount'
-                               : 'login';
+                               : 'pt-login';
                        $is_signup = $request->getText( 'type' ) == 'signup';
 
-                       # anonlogin & login are the same
-                       $proto = $wgSecureLogin ? PROTO_HTTPS : null;
-
-                       $login_id = $this->showIPinHeader() ? 'anonlogin' : 'login';
                        $login_url = array(
                                'text' => $this->msg( $loginlink )->text(),
-                               'href' => self::makeSpecialUrl( 'Userlogin', $returnto, $proto ),
+                               'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
                                'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
-                               'class' => $wgSecureLogin ? 'link-https' : ''
                        );
                        $createaccount_url = array(
-                               'text' => $this->msg( 'createaccount' )->text(),
-                               'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup", $proto ),
+                               'text' => $this->msg( 'pt-createaccount' )->text(),
+                               'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
                                'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
-                               'class' => $wgSecureLogin ? 'link-https' : ''
                        );
 
                        if ( $this->showIPinHeader() ) {
@@ -731,10 +757,10 @@ class SkinTemplate extends Skin {
                                $personal_urls['createaccount'] = $createaccount_url;
                        }
 
-                       $personal_urls[$login_id] = $login_url;
+                       $personal_urls['login'] = $login_url;
                }
 
-               wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
+               wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
                wfProfileOut( __METHOD__ );
                return $personal_urls;
        }
@@ -1013,7 +1039,9 @@ class SkinTemplate extends Skin {
                                        }
                                }
 
-                               if ( $title->getNamespace() !== NS_MEDIAWIKI && $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() ) {
+                               if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
+                                       MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
+                               ) {
                                        $mode = $title->isProtected() ? 'unprotect' : 'protect';
                                        $content_navigation['actions'][$mode] = array(
                                                'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
@@ -1285,12 +1313,14 @@ class SkinTemplate extends Skin {
                                );
                        }
 
-                       $sur = new UserrightsPage;
-                       $sur->setContext( $this->getContext() );
-                       if ( $sur->userCanExecute( $this->getUser() ) ) {
-                               $nav_urls['userrights'] = array(
-                                       'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
-                               );
+                       if ( !$user->isAnon() ) {
+                               $sur = new UserrightsPage;
+                               $sur->setContext( $this->getContext() );
+                               if ( $sur->userCanExecute( $this->getUser() ) ) {
+                                       $nav_urls['userrights'] = array(
+                                               'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
+                                       );
+                               }
                        }
                }
 
@@ -1306,10 +1336,6 @@ class SkinTemplate extends Skin {
        function getNameSpaceKey() {
                return $this->getTitle()->getNamespaceKey();
        }
-
-       public function commonPrintStylesheet() {
-               return false;
-       }
 }
 
 /**
@@ -1378,15 +1404,6 @@ abstract class QuickTemplate {
                echo htmlspecialchars( $this->data[$str] );
        }
 
-       /**
-        * @private
-        * @deprecated since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead
-        */
-       function jstext( $str ) {
-               wfDeprecated( __METHOD__, '1.21' );
-               echo Xml::escapeJsString( $this->data[$str] );
-       }
-
        /**
         * @private
         */
@@ -1445,6 +1462,20 @@ abstract class QuickTemplate {
        public function getSkin() {
                return $this->data['skin'];
        }
+
+       /**
+        * Fetch the output of a QuickTemplate and return it
+        *
+        * @since 1.23
+        * @return String
+        */
+       public function getHTML() {
+               ob_start();
+               $this->execute();
+               $html = ob_get_contents();
+               ob_end_clean();
+               return $html;
+       }
 }
 
 /**
@@ -1724,6 +1755,10 @@ abstract class BaseTemplate extends QuickTemplate {
         * on the link) is present it will be used to generate a tooltip and
         * accesskey for the link.
         *
+        * The keys "context" and "primary" are ignored; these keys are used
+        * internally by skins and are not supposed to be included in the HTML
+        * output.
+        *
         * If you don't want an accesskey, set $item['tooltiponly'] = true;
         *
         * @param array $options can be used to affect the output of a link.
@@ -1764,7 +1799,7 @@ abstract class BaseTemplate extends QuickTemplate {
 
                if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
                        $attrs = $item;
-                       foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) {
+                       foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
                                unset( $attrs[$k] );
                        }
 
@@ -2001,9 +2036,10 @@ abstract class BaseTemplate extends QuickTemplate {
         * body and html tags.
         */
        function printTrail() { ?>
+<?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() ); ?>
 <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
 <?php $this->html( 'reporttime' ) ?>
-<?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() );
+<?php
        }
 
 }